From 1a8b44fb97ea65d1d46aacfb02910eab082cb74c Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Sat, 1 Jun 2024 21:32:53 +0530 Subject: [PATCH 01/10] add isPresent command --- lib/api/web-element/commands/isPresent.js | 31 +++++++++++++++++++ lib/api/web-element/scoped-element.js | 3 +- lib/core/asynctree.js | 7 +++++ lib/core/treenode.js | 10 ++++-- .../selenium-webdriver/method-mappings.js | 15 +++++++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 lib/api/web-element/commands/isPresent.js diff --git a/lib/api/web-element/commands/isPresent.js b/lib/api/web-element/commands/isPresent.js new file mode 100644 index 0000000000..c1a823cf49 --- /dev/null +++ b/lib/api/web-element/commands/isPresent.js @@ -0,0 +1,31 @@ +/** + * Checks if an element is present in the DOM. + * + * This command is useful for verifying the presence of elements that may not be visible or interactable. + * For more information on working with DOM elements in Nightwatch, refer to the Finding Elements guide page. + * + * @example + * describe('isPresent Demo', function() { + * it('test isPresent', function(browser) { + * browser.element('#search') + * .isPresent() + * .assert.equals(true); + * }); + * + * it('test async isPresent', async function(browser) { + * const result = await browser.element('#search').isPresent(); + * browser.assert.equal(result, true); + * }); + * }); + * + * @since 3.5.0 + * @method isPresent + * @memberof ScopedWebElement + * @instance + * @syntax browser.element(selector).isPresent() + * @returns {ScopedValue} A boolean value indicating if the element is present in the DOM. + */ + +module.exports.command = function () { + return this.runQueuedCommandScoped('isElementPresent'); +}; diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 341778bec7..45cc608216 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -164,6 +164,7 @@ class ScopedWebElement { } const parentElement = args[0]; + const suppressNotFoundErrorsFromArgs = args[1] ?? suppressNotFoundErrors; try { if (condition.usingRecursion) { @@ -172,7 +173,7 @@ class ScopedWebElement { return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval}); } catch (error) { - if (suppressNotFoundErrors) { + if (suppressNotFoundErrorsFromArgs) { return null; } diff --git a/lib/core/asynctree.js b/lib/core/asynctree.js index 926a45a17f..e89c873c31 100644 --- a/lib/core/asynctree.js +++ b/lib/core/asynctree.js @@ -133,6 +133,13 @@ class AsyncTree extends EventEmitter{ this.emit('asynctree:command:start', {node}); + const nextSibbling = node.nextSibbling; + + if (node.name === 'find' && nextSibbling.name === 'isElementPresent') { + // In case of isPresent command, we want to supress the Timeout error. + node.__args.push(true); + } + const result = await node.run(); const {parent} = this.currentNode; diff --git a/lib/core/treenode.js b/lib/core/treenode.js index 9996d1f180..56ecb971f4 100644 --- a/lib/core/treenode.js +++ b/lib/core/treenode.js @@ -27,6 +27,12 @@ class TreeNode { return this.options && this.options.isTraceable; } + get nextSibbling() { + const currentNodeIndex = this.parent.childNodes.indexOf(this); + + return this.parent.childNodes[currentNodeIndex + 1]; + } + get fullName() { if (!this.namespace || !Utils.isString(this.namespace)) { return this.name; @@ -121,8 +127,8 @@ class TreeNode { err.abortOnFailure = err.abortOnFailure || err.abortOnFailure === undefined; } - let errorName = err.name !== 'Error' ? `[${err.name}] ` : ''; - let originalError = `${errorName}${err.message}`; + const errorName = err.name !== 'Error' ? `[${err.name}] ` : ''; + const originalError = `${errorName}${err.message}`; if (this.stackTrace && Utils.shouldReplaceStack(err)) { err.stack = this.stackTrace; diff --git a/lib/transport/selenium-webdriver/method-mappings.js b/lib/transport/selenium-webdriver/method-mappings.js index 0f10c8f72e..6719d80b74 100644 --- a/lib/transport/selenium-webdriver/method-mappings.js +++ b/lib/transport/selenium-webdriver/method-mappings.js @@ -1,4 +1,5 @@ const {WebElement, WebDriver, Origin, By, until, Condition, Key} = require('selenium-webdriver'); +const {ShadowRoot} = require('selenium-webdriver/lib/webdriver'); const {Locator} = require('../../element'); const NightwatchLocator = require('../../element/locator-factory.js'); const {isString} = require('../../utils'); @@ -583,6 +584,20 @@ module.exports = class MethodMappings { return value; }, + async isElementPresent(webElement) { + try { + // New element apis contains only webElement argument + const element = await webElement; + + return element instanceof WebElement || element instanceof ShadowRoot; + } catch (error) { + if (error.name === 'NoSuchElementError') { + return false; // Element does not exist + } + throw error; // Re-throw other errors for further handling + } + }, + async clearElementValue(webElementOrId) { const element = this.getWebElement(webElementOrId); await element.clear(); From b0aacb85981ae3207c1c639c8a08fe35295b2e3f Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Wed, 5 Jun 2024 15:14:19 +0530 Subject: [PATCH 02/10] add missing outofbounds check --- lib/core/asynctree.js | 2 +- lib/core/treenode.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/asynctree.js b/lib/core/asynctree.js index e89c873c31..6f3206e294 100644 --- a/lib/core/asynctree.js +++ b/lib/core/asynctree.js @@ -135,7 +135,7 @@ class AsyncTree extends EventEmitter{ const nextSibbling = node.nextSibbling; - if (node.name === 'find' && nextSibbling.name === 'isElementPresent') { + if (node.name === 'find' && nextSibbling && nextSibbling.name === 'isElementPresent') { // In case of isPresent command, we want to supress the Timeout error. node.__args.push(true); } diff --git a/lib/core/treenode.js b/lib/core/treenode.js index 56ecb971f4..50a68cc496 100644 --- a/lib/core/treenode.js +++ b/lib/core/treenode.js @@ -29,6 +29,9 @@ class TreeNode { get nextSibbling() { const currentNodeIndex = this.parent.childNodes.indexOf(this); + if (currentNodeIndex + 1 >= this.parent.childNodes.length){ + return null; + } return this.parent.childNodes[currentNodeIndex + 1]; } From 4e44f67b5aa6a70077a0408f87a94e29f2bfbf81 Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Wed, 5 Jun 2024 20:49:52 +0530 Subject: [PATCH 03/10] add isPresent test --- .../api/commands/web-element/testIsPresent.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/src/api/commands/web-element/testIsPresent.js diff --git a/test/src/api/commands/web-element/testIsPresent.js b/test/src/api/commands/web-element/testIsPresent.js new file mode 100644 index 0000000000..d885a8ca86 --- /dev/null +++ b/test/src/api/commands/web-element/testIsPresent.js @@ -0,0 +1,45 @@ +const assert = require('assert'); +const {WebElement} = require('selenium-webdriver'); +const MockServer = require('../../../../lib/mockserver.js'); +const CommandGlobals = require('../../../../lib/globals/commands-w3c.js'); +const common = require('../../../../common.js'); +const Element = common.require('element/index.js'); + +describe('element().isPresent() command', function() { + before(function (done) { + CommandGlobals.beforeEach.call(this, done); + }); + + after(function (done) { + CommandGlobals.afterEach.call(this, done); + }); + + it('test .element().isPresent() present', async function() { + const resultPromise = this.client.api.element('#signupSection').isPresent(); + assert.strictEqual(resultPromise instanceof Element, false); + assert.strictEqual(typeof resultPromise.find, 'undefined'); + + assert.strictEqual(resultPromise instanceof Promise, false); + assert.strictEqual(typeof resultPromise.then, 'function'); + + const result = await resultPromise; + assert.strictEqual(result instanceof WebElement, false); + assert.strictEqual(result, true); + + }); + + it('test .element().isPresent() not present', async function() { + const resultPromise = this.client.api.element('#wrong').isPresent(); + assert.strictEqual(resultPromise instanceof Element, false); + assert.strictEqual(typeof resultPromise.find, 'undefined'); + + assert.strictEqual(resultPromise instanceof Promise, false); + assert.strictEqual(typeof resultPromise.then, 'function'); + + const result = await resultPromise; + assert.strictEqual(result instanceof WebElement, false); + assert.strictEqual(result, false); + + }); + +}); \ No newline at end of file From 3c8bd22d1c1d172a80632d907be4a11bd833686a Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Wed, 5 Jun 2024 20:59:24 +0530 Subject: [PATCH 04/10] added more test cases --- .../api/commands/web-element/testIsPresent.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/src/api/commands/web-element/testIsPresent.js b/test/src/api/commands/web-element/testIsPresent.js index d885a8ca86..208e3e71d7 100644 --- a/test/src/api/commands/web-element/testIsPresent.js +++ b/test/src/api/commands/web-element/testIsPresent.js @@ -42,4 +42,30 @@ describe('element().isPresent() command', function() { }); + it('test .element().find().isPresent() present', async function() { + const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').isPresent(); + assert.strictEqual(resultPromise instanceof Element, false); + assert.strictEqual(typeof resultPromise.find, 'undefined'); + + assert.strictEqual(resultPromise instanceof Promise, false); + assert.strictEqual(typeof resultPromise.then, 'function'); + + const result = await resultPromise; + assert.strictEqual(result instanceof WebElement, false); + assert.strictEqual(result, true); + }); + + it('test .element().find().isPresent() not present', async function() { + const resultPromise = this.client.api.element('#signupSection').find('#wrong').isPresent(); + assert.strictEqual(resultPromise instanceof Element, false); + assert.strictEqual(typeof resultPromise.find, 'undefined'); + + assert.strictEqual(resultPromise instanceof Promise, false); + assert.strictEqual(typeof resultPromise.then, 'function'); + + const result = await resultPromise; + assert.strictEqual(result instanceof WebElement, false); + assert.strictEqual(result, false); + }); + }); \ No newline at end of file From b89c32f905ba2e75ebe26178440ddc8a022030fe Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Fri, 7 Jun 2024 15:42:18 +0530 Subject: [PATCH 05/10] moved error suppression logic from tree to scoped-element --- lib/api/web-element/commands/isPresent.js | 2 +- lib/api/web-element/scoped-element.js | 11 +++++++++-- lib/core/asynctree.js | 7 ------- lib/core/treenode.js | 9 --------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/api/web-element/commands/isPresent.js b/lib/api/web-element/commands/isPresent.js index c1a823cf49..55ee16d66d 100644 --- a/lib/api/web-element/commands/isPresent.js +++ b/lib/api/web-element/commands/isPresent.js @@ -27,5 +27,5 @@ */ module.exports.command = function () { - return this.runQueuedCommandScoped('isElementPresent'); + return this.runQueuedCommandScoped('isElementPresent', {suppressNotFoundErrors: true}); }; diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 45cc608216..64130c1ea4 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -70,6 +70,10 @@ class ScopedWebElement { return true; } + get suppressNotFoundErrors() { + return this._suppressNotFoundErrors; + } + constructor(selector = 'html', parentElement, nightwatchInstance) { this.nightwatchInstance = nightwatchInstance; this.parentScopedElement = parentElement; @@ -164,7 +168,6 @@ class ScopedWebElement { } const parentElement = args[0]; - const suppressNotFoundErrorsFromArgs = args[1] ?? suppressNotFoundErrors; try { if (condition.usingRecursion) { @@ -173,7 +176,7 @@ class ScopedWebElement { return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval}); } catch (error) { - if (suppressNotFoundErrorsFromArgs) { + if (this.suppressNotFoundErrors ?? suppressNotFoundErrors) { return null; } @@ -287,6 +290,10 @@ class ScopedWebElement { }); }; + if (args[0]?.suppressNotFoundErrors) { + this._suppressNotFoundErrors = true; + } + const node = this.queueAction({name: commandName, createAction}); return node; diff --git a/lib/core/asynctree.js b/lib/core/asynctree.js index 6f3206e294..926a45a17f 100644 --- a/lib/core/asynctree.js +++ b/lib/core/asynctree.js @@ -133,13 +133,6 @@ class AsyncTree extends EventEmitter{ this.emit('asynctree:command:start', {node}); - const nextSibbling = node.nextSibbling; - - if (node.name === 'find' && nextSibbling && nextSibbling.name === 'isElementPresent') { - // In case of isPresent command, we want to supress the Timeout error. - node.__args.push(true); - } - const result = await node.run(); const {parent} = this.currentNode; diff --git a/lib/core/treenode.js b/lib/core/treenode.js index 50a68cc496..1bfa4ae365 100644 --- a/lib/core/treenode.js +++ b/lib/core/treenode.js @@ -27,15 +27,6 @@ class TreeNode { return this.options && this.options.isTraceable; } - get nextSibbling() { - const currentNodeIndex = this.parent.childNodes.indexOf(this); - if (currentNodeIndex + 1 >= this.parent.childNodes.length){ - return null; - } - - return this.parent.childNodes[currentNodeIndex + 1]; - } - get fullName() { if (!this.namespace || !Utils.isString(this.namespace)) { return this.name; From 9a838ad2561bba56e0eb008bca2e223c1b910a62 Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Tue, 16 Jul 2024 23:26:42 +0530 Subject: [PATCH 06/10] fixes --- lib/api/web-element/scoped-element.js | 14 +++++++++----- .../selenium-webdriver/method-mappings.js | 12 ++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 64130c1ea4..a155e1d8e0 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -169,6 +169,10 @@ class ScopedWebElement { const parentElement = args[0]; + if (suppressNotFoundErrors) { + this.suppressNotFoundErrors = true; + } + try { if (condition.usingRecursion) { return await this.findElementUsingRecursion({parentElement, recursiveElement: condition, timeout, retryInterval}); @@ -176,7 +180,7 @@ class ScopedWebElement { return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval}); } catch (error) { - if (this.suppressNotFoundErrors ?? suppressNotFoundErrors) { + if (this.suppressNotFoundErrors) { return null; } @@ -277,6 +281,10 @@ class ScopedWebElement { } createNode(commandName, args) { + if (args[0]?.suppressNotFoundErrors) { + this._suppressNotFoundErrors = true; + } + const createAction = (actions, webElement) => function () { if (isFunction(commandName)) { return commandName(webElement, ...args).then((result) => { @@ -290,10 +298,6 @@ class ScopedWebElement { }); }; - if (args[0]?.suppressNotFoundErrors) { - this._suppressNotFoundErrors = true; - } - const node = this.queueAction({name: commandName, createAction}); return node; diff --git a/lib/transport/selenium-webdriver/method-mappings.js b/lib/transport/selenium-webdriver/method-mappings.js index 6719d80b74..f0a32136bd 100644 --- a/lib/transport/selenium-webdriver/method-mappings.js +++ b/lib/transport/selenium-webdriver/method-mappings.js @@ -585,17 +585,9 @@ module.exports = class MethodMappings { }, async isElementPresent(webElement) { - try { - // New element apis contains only webElement argument - const element = await webElement; + const element = await webElement; - return element instanceof WebElement || element instanceof ShadowRoot; - } catch (error) { - if (error.name === 'NoSuchElementError') { - return false; // Element does not exist - } - throw error; // Re-throw other errors for further handling - } + return element instanceof WebElement || element instanceof ShadowRoot; }, async clearElementValue(webElementOrId) { From 289dcf9e973f396fbdb64822ccaf284d1c10cb3a Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Wed, 7 Aug 2024 00:32:44 +0530 Subject: [PATCH 07/10] add another test case --- .../isPresent/isPresentElementNotPresent.js | 6 ++++ .../api/commands/web-element/testIsPresent.js | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/sampletests/isPresent/isPresentElementNotPresent.js diff --git a/test/sampletests/isPresent/isPresentElementNotPresent.js b/test/sampletests/isPresent/isPresentElementNotPresent.js new file mode 100644 index 0000000000..146dcdab49 --- /dev/null +++ b/test/sampletests/isPresent/isPresentElementNotPresent.js @@ -0,0 +1,6 @@ +describe('test', function () { + test('test setPassword', async (browser) => { + browser + .element('#wrong').isPresent().assert.equals(false); + }); +}); diff --git a/test/src/api/commands/web-element/testIsPresent.js b/test/src/api/commands/web-element/testIsPresent.js index 208e3e71d7..7ff25492b0 100644 --- a/test/src/api/commands/web-element/testIsPresent.js +++ b/test/src/api/commands/web-element/testIsPresent.js @@ -1,13 +1,18 @@ const assert = require('assert'); const {WebElement} = require('selenium-webdriver'); +const path = require('path'); const MockServer = require('../../../../lib/mockserver.js'); const CommandGlobals = require('../../../../lib/globals/commands-w3c.js'); const common = require('../../../../common.js'); const Element = common.require('element/index.js'); +const Utils = common.require('./utils'); +const NightwatchClient = common.require('index.js'); +const {settings} = common; describe('element().isPresent() command', function() { before(function (done) { CommandGlobals.beforeEach.call(this, done); + }); after(function (done) { @@ -68,4 +73,35 @@ describe('element().isPresent() command', function() { assert.strictEqual(result, false); }); + it('test .element().find().isPresent() suppressNotFoundErrors should not throw NoSuchElementError', async function() { + + MockServer.addMock({ + url: '/session/13521-10219-202/elements', + method: 'POST', + postdata: JSON.stringify({using: 'css selector', value: '#wrong'}), + response: JSON.stringify({ + value: [] + }) + }); + + const globals = { + reporter(results) { + if (Object.prototype.hasOwnProperty.call(results, 'lastError')) { + assert.notStrictEqual(results.lastError.name, 'NoSuchElementError'); + } + }, + waitForConditionTimeout: 100 + }; + const testsPath = [ + path.join(__dirname, '../../../../sampletests/isPresent/isPresentElementNotPresent.js') + ]; + + await NightwatchClient.runTests(testsPath, settings({ + globals, + output_folder: 'output', + selenium_host: null + })); + + }); + }); \ No newline at end of file From 66faef36e18f9c548ab72d283fb7d11e2f29ed1d Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Mon, 12 Aug 2024 18:19:51 +0530 Subject: [PATCH 08/10] test fix --- lib/api/web-element/scoped-element.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index a155e1d8e0..d801763fc5 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -170,7 +170,7 @@ class ScopedWebElement { const parentElement = args[0]; if (suppressNotFoundErrors) { - this.suppressNotFoundErrors = true; + this._suppressNotFoundErrors = true; } try { @@ -180,7 +180,7 @@ class ScopedWebElement { return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval}); } catch (error) { - if (this.suppressNotFoundErrors) { + if (this._suppressNotFoundErrors) { return null; } From 6595b0f47340b931a47a810488ebf2d712397df6 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Mon, 12 Aug 2024 23:59:11 +0530 Subject: [PATCH 09/10] Few refactors. --- lib/api/web-element/commands/isPresent.js | 3 ++- lib/api/web-element/scoped-element.js | 14 +++++++------- .../selenium-webdriver/method-mappings.js | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/api/web-element/commands/isPresent.js b/lib/api/web-element/commands/isPresent.js index 55ee16d66d..3a588ee633 100644 --- a/lib/api/web-element/commands/isPresent.js +++ b/lib/api/web-element/commands/isPresent.js @@ -2,6 +2,7 @@ * Checks if an element is present in the DOM. * * This command is useful for verifying the presence of elements that may not be visible or interactable. + * * For more information on working with DOM elements in Nightwatch, refer to the Finding Elements guide page. * * @example @@ -18,7 +19,7 @@ * }); * }); * - * @since 3.5.0 + * @since 3.7.1 * @method isPresent * @memberof ScopedWebElement * @instance diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index d801763fc5..35209164a9 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -161,7 +161,7 @@ class ScopedWebElement { return webElements[index]; } - async findElementAction({parentElement, condition, index, timeout, retryInterval, abortOnFailure, suppressNotFoundErrors}) { + async findElementAction({parentElement, condition, index, timeout, retryInterval, abortOnFailure}) { const createAction = () => async ({args}) => { if ((args[0] instanceof Promise) && !args[0]['@nightwatch_element']) { args[0] = await args[0]; @@ -169,10 +169,6 @@ class ScopedWebElement { const parentElement = args[0]; - if (suppressNotFoundErrors) { - this._suppressNotFoundErrors = true; - } - try { if (condition.usingRecursion) { return await this.findElementUsingRecursion({parentElement, recursiveElement: condition, timeout, retryInterval}); @@ -180,7 +176,7 @@ class ScopedWebElement { return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval}); } catch (error) { - if (this._suppressNotFoundErrors) { + if (this.suppressNotFoundErrors) { return null; } @@ -249,8 +245,12 @@ class ScopedWebElement { return resolve(condition); } + if (suppressNotFoundErrors) { + this._suppressNotFoundErrors = true; + } + const webElement = await this.findElementAction({ - parentElement, condition, index, timeout, retryInterval, abortOnFailure, suppressNotFoundErrors + parentElement, condition, index, timeout, retryInterval, abortOnFailure }); resolve(webElement); diff --git a/lib/transport/selenium-webdriver/method-mappings.js b/lib/transport/selenium-webdriver/method-mappings.js index f0a32136bd..b492f1f23e 100644 --- a/lib/transport/selenium-webdriver/method-mappings.js +++ b/lib/transport/selenium-webdriver/method-mappings.js @@ -585,6 +585,7 @@ module.exports = class MethodMappings { }, async isElementPresent(webElement) { + // webElement would be a Promise in case of new Element API. const element = await webElement; return element instanceof WebElement || element instanceof ShadowRoot; From 7022912d6c01a41c9aedea7b9817209a78c9d0fd Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Tue, 13 Aug 2024 01:29:40 +0530 Subject: [PATCH 10/10] Few minor changes in tests. --- ...sentElementNotPresent.js => elementNotPresent.js} | 2 +- test/src/api/commands/web-element/testIsPresent.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) rename test/sampletests/isPresent/{isPresentElementNotPresent.js => elementNotPresent.js} (70%) diff --git a/test/sampletests/isPresent/isPresentElementNotPresent.js b/test/sampletests/isPresent/elementNotPresent.js similarity index 70% rename from test/sampletests/isPresent/isPresentElementNotPresent.js rename to test/sampletests/isPresent/elementNotPresent.js index 146dcdab49..68e8310f25 100644 --- a/test/sampletests/isPresent/isPresentElementNotPresent.js +++ b/test/sampletests/isPresent/elementNotPresent.js @@ -1,5 +1,5 @@ describe('test', function () { - test('test setPassword', async (browser) => { + test('test isPresent', async (browser) => { browser .element('#wrong').isPresent().assert.equals(false); }); diff --git a/test/src/api/commands/web-element/testIsPresent.js b/test/src/api/commands/web-element/testIsPresent.js index 7ff25492b0..b9a18ae0b2 100644 --- a/test/src/api/commands/web-element/testIsPresent.js +++ b/test/src/api/commands/web-element/testIsPresent.js @@ -73,8 +73,7 @@ describe('element().isPresent() command', function() { assert.strictEqual(result, false); }); - it('test .element().find().isPresent() suppressNotFoundErrors should not throw NoSuchElementError', async function() { - + it('test .element().isPresent() suppresses NoSuchElementError', async function() { MockServer.addMock({ url: '/session/13521-10219-202/elements', method: 'POST', @@ -84,8 +83,11 @@ describe('element().isPresent() command', function() { }) }); + let globalReporterCalled = false; + const globals = { reporter(results) { + globalReporterCalled = true; if (Object.prototype.hasOwnProperty.call(results, 'lastError')) { assert.notStrictEqual(results.lastError.name, 'NoSuchElementError'); } @@ -93,7 +95,7 @@ describe('element().isPresent() command', function() { waitForConditionTimeout: 100 }; const testsPath = [ - path.join(__dirname, '../../../../sampletests/isPresent/isPresentElementNotPresent.js') + path.join(__dirname, '../../../../sampletests/isPresent/elementNotPresent.js') ]; await NightwatchClient.runTests(testsPath, settings({ @@ -102,6 +104,6 @@ describe('element().isPresent() command', function() { selenium_host: null })); + assert.strictEqual(globalReporterCalled, true); }); - -}); \ No newline at end of file +});