Skip to content

Commit

Permalink
Fix nightwatchjs#3181 Added a fix to wait waitForElementNotPresent
Browse files Browse the repository at this point in the history
…inside section for the section element to be gone
  • Loading branch information
harshit-bs committed Jan 23, 2023
1 parent cefae71 commit 7564e4c
Show file tree
Hide file tree
Showing 4 changed files with 85 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;
},

childElementNotFound(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;
},

childElementFound(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: [{'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
34 changes: 34 additions & 0 deletions test/src/core/testPageObjectWaitForElementNotPresent.js
@@ -0,0 +1,34 @@
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().childElementFound().elementFound().childElementNotFound()

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

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

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

0 comments on commit 7564e4c

Please sign in to comment.