Open MurzNN opened 1 month ago
The interesting thing is that if I do this inside the Nightwath test directly - it works well! The issue appears only if I put it into the Nightwatch command and call it from the sync function.
Example of the working tests without the custom function:
module.exports = {
'Test thFindNested in async mode': async (browser) => {
await browser.url('http://google.com');
const el1 = await browser.findElement('body');
const el1Id = el1.getId();
console.log('el1Id', el1Id);
const els2 = await browser.elementIdElements(el1Id, 'css selector', 'div')
const el2 = els2[0];
console.log('el2', el2);
const el2Id = Object.values(el2)[0];
console.log('el2Id', el2Id);
const els3 = await browser.elementIdElements(el2Id, 'css selector', 'div')
console.log('els3', els3);
const el3 = els3[0];
console.log('el3', el3);
const el3Id = Object.values(el3)[0];
console.log('el3Id', el3Id);
},
'Test thFindNested in sync mode': (browser) => {
browser
.url('http://google.com')
.findElement('body', (result) => {
const el1 = result.value;
const el1Id = el1.getId();
console.log('el1Id', el1Id);
browser.elementIdElements(el1Id, 'css selector', 'div', function (result) {
const els2 = result.value;
const el2 = els2[0];
console.log('el2', el2);
const el2Id = Object.values(el2)[0];
console.log('el2Id', el2Id);
browser.elementIdElements(el2Id, 'css selector', 'div', function (result) {
const els3 = result.value;
console.log('els3', els3);
const el3 = els3[0];
console.log('el3', el3);
const el3Id = Object.values(el3)[0];
console.log('el3Id', el3Id);
});
});
})
.end();
},
};
Description of the bug/issue
When I call the
this.api.elementIdElements()
in a custom command, called from thesync
function, on the second call it returns theNightwatchAPI
object instead of the actual result.So, the first call of
result = this.api.elementIdElements()
returns the array of elements, but when doing the same call a second time - it suddenly returns theNigthwatchAPI
object instead!If I do the same from the
async
function - all work well.See the test code below on how to reproduce.
Steps to reproduce
this.api.elementIdElements()
multiple times.NigthwatchAPI
object instead of the expected result.Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
3.8.0
Node Version
18.20.4
Browser
Chrome 101.0.4951.41
Operating System
Ubuntu Linux, the test run in the docker container
Additional Information
No response