From d710d768db8cedc7e321e08fc91b8bbe71454912 Mon Sep 17 00:00:00 2001 From: Harshit Agrawal <94462364+harshit-bs@users.noreply.github.com> Date: Thu, 2 Feb 2023 14:54:57 +0530 Subject: [PATCH] =?UTF-8?q?Fix=20#3181=20=E2=80=93=20`waitForElementNotPre?= =?UTF-8?q?sent`=20inside=20section=20for=20the=20section=20element=20to?= =?UTF-8?q?=20be=20gone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/element/locate/recursive-lookup.js | 3 +- .../pages/waitForElementNotPresentPageObj.js | 25 ++++++++++++++ test/lib/nocks.js | 24 ++++++++++++++ .../testPageObjectWaitForElementNotPresent.js | 33 +++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 test/extra/pageobjects/pages/waitForElementNotPresentPageObj.js create mode 100644 test/src/core/testPageObjectWaitForElementNotPresent.js diff --git a/lib/element/locate/recursive-lookup.js b/lib/element/locate/recursive-lookup.js index 928cca5539..65710e9fca 100644 --- a/lib/element/locate/recursive-lookup.js +++ b/lib/element/locate/recursive-lookup.js @@ -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({ diff --git a/test/extra/pageobjects/pages/waitForElementNotPresentPageObj.js b/test/extra/pageobjects/pages/waitForElementNotPresentPageObj.js new file mode 100644 index 0000000000..70fae6fcd0 --- /dev/null +++ b/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); + } + }] + } + } +}; diff --git a/test/lib/nocks.js b/test/lib/nocks.js index 434aa9acbe..f841d488a8 100644 --- a/test/lib/nocks.js +++ b/test/lib/nocks.js @@ -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'}) diff --git a/test/src/core/testPageObjectWaitForElementNotPresent.js b/test/src/core/testPageObjectWaitForElementNotPresent.js new file mode 100644 index 0000000000..40351e1c04 --- /dev/null +++ b/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() + }); +});