Skip to content

Commit

Permalink
Fix #3181waitForElementNotPresent inside section for the section…
Browse files Browse the repository at this point in the history
… element to be gone
  • Loading branch information
harshit-bs committed Feb 2, 2023
1 parent 0214404 commit d710d76
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/element/locate/recursive-lookup.js
Expand Up @@ -50,7 +50,8 @@ class RecursiveLookupBase extends EventEmitter {
element,
transportAction: this.transportAction,
commandName: this.commandName,
returnSingleElement: this.shouldReturnSingleElement(returnSingleElement)
returnSingleElement: this.shouldReturnSingleElement(returnSingleElement),
cacheElementId: false
})
.then(result => {
this.recursiveElementLookup({
Expand Down
25 changes: 25 additions & 0 deletions test/extra/pageobjects/pages/waitForElementNotPresentPageObj.js
@@ -0,0 +1,25 @@
module.exports = {
commands: [{
waitForElementNotPresentDemo(cb) {
this.click('@button')
const dialog = this.section.dialog;
dialog.selectValueDemo(cb)
}
}],
elements: {
button: '#weblogin'
},
sections: {
dialog: {
selector: '#weblogin',
elements: {
select: '#badElement'
},
commands: [{
selectValueDemo(cb) {
this.waitForElementNotPresent('@select', cb);
}
}]
}
}
};
24 changes: 24 additions & 0 deletions test/lib/nocks.js
Expand Up @@ -179,6 +179,30 @@ module.exports = {
return this;
},

childElementsNotFound(selector='#badElement') {
nock('http://localhost:10195')
.post('/wd/hub/session/1352110219202/element/0/elements', {'using': 'css selector', 'value': selector})
.reply(200, {
status: 0,
state: 'success',
value: []
});

return this;
},

childElementsFound(selector='#weblogin') {
nock('http://localhost:10195')
.post('/wd/hub/session/1352110219202/element/0/elements', {'using': 'css selector', 'value': selector})
.reply(200, {
status: 0,
state: 'success',
value: [{'element-6066-11e4-a52e-4f735466cecf': '0'}]
})

return this;
},

elementFoundXpath() {
nock('http://localhost:10195')
.post('/wd/hub/session/1352110219202/elements', {'using': 'xpath', 'value': '//weblogin'})
Expand Down
33 changes: 33 additions & 0 deletions test/src/core/testPageObjectWaitForElementNotPresent.js
@@ -0,0 +1,33 @@
const assert = require('assert');
const path = require('path');
const Nocks = require('../../lib/nocks.js');
const Nightwatch = require('../../lib/nightwatch.js');

describe('test PageObject WaitForElementNotPresent', function () {
beforeEach(function (done) {
Nocks.enable().cleanAll().createSession();
Nightwatch.init({
page_objects_path: path.join(__dirname, '../../extra/pageobjects/pages')
}, function () {
done();
});
this.client = Nightwatch.client();
});

afterEach(function () {
Nocks.deleteSession().disable();
});

it('WaitForElementNotPresent with section', function(done) {
Nocks.elementFound().click().elementFound().childElementsFound('#badElement').elementFound().childElementsNotFound()

const page = this.client.api.page.waitForElementNotPresentPageObj();

page.waitForElementNotPresentDemo(function(result) {
assert.equal(result.status, 0);
done();
})

this.client.start()
});
});

0 comments on commit d710d76

Please sign in to comment.