From 6b64e8798a0a3277b35b7b9a345ac3888f06e23d Mon Sep 17 00:00:00 2001 From: Ravi Sawlani Date: Thu, 12 Oct 2023 18:01:27 +0530 Subject: [PATCH] fix abortOnAssertionFailure issue with waitFor commands --- lib/core/asynctree.js | 4 -- lib/testsuite/index.js | 5 ++- .../waitFor-commands/waitForElementTest.js | 9 ++++ .../waitFor-commands/testWaitForCommands.js | 43 +++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 test/apidemos/waitFor-commands/waitForElementTest.js create mode 100644 test/src/apidemos/waitFor-commands/testWaitForCommands.js diff --git a/lib/core/asynctree.js b/lib/core/asynctree.js index 72152e56b9..6b5c99d7ec 100644 --- a/lib/core/asynctree.js +++ b/lib/core/asynctree.js @@ -47,10 +47,6 @@ class AsyncTree extends EventEmitter{ if (childNode) { const result = await this.runChildNode(childNode); - if (result instanceof Error && result.namespace === 'verify') { - return null; - } - return result; } diff --git a/lib/testsuite/index.js b/lib/testsuite/index.js index b20e88b422..739df2ebb7 100644 --- a/lib/testsuite/index.js +++ b/lib/testsuite/index.js @@ -13,7 +13,7 @@ const SuiteRetries = require('./retries.js'); const NightwatchClient = require('../core/client.js'); const Concurrency = require('../runner/concurrency'); const ElementGlobal = require('../api/_loaders/element-global.js'); -const {Logger, Screenshots, Snapshots, alwaysDisplayError, isString, isFunction, SafeJSON} = require('../utils'); +const {Logger, Screenshots, Snapshots, alwaysDisplayError, isString, isFunction, SafeJSON, isDefined} = require('../utils'); const NightwatchInspectorServer = require('./nightwatch-inspector'); const {DEFAULT_RUNNER_EVENTS, NightwatchEventHub} = require('../runner/eventHub'); const {GlobalHook, TestSuiteHook} = DEFAULT_RUNNER_EVENTS; @@ -863,7 +863,8 @@ class TestSuite { return this.retryCurrentTestCase(); } - if ((possibleError instanceof Error) && this.shouldSkipTestsOnFail()) { + const abortOnFailure = isDefined(possibleError.abortOnFailure) ? possibleError.abortOnFailure : true; + if ((possibleError instanceof Error && abortOnFailure) && this.shouldSkipTestsOnFail()) { throw possibleError; } diff --git a/test/apidemos/waitFor-commands/waitForElementTest.js b/test/apidemos/waitFor-commands/waitForElementTest.js new file mode 100644 index 0000000000..739d2324a1 --- /dev/null +++ b/test/apidemos/waitFor-commands/waitForElementTest.js @@ -0,0 +1,9 @@ +describe('test wait for element commands', function() { + it('waitForElementVisible command - failure', function() { + browser.waitForElementVisible('#weblogin', 100, 90, false); + }); + + it('waitForElementNotVisible command - failure', function() { + browser.waitForElementNotVisible('#badElement', 100, 90, false); + }); +}); \ No newline at end of file diff --git a/test/src/apidemos/waitFor-commands/testWaitForCommands.js b/test/src/apidemos/waitFor-commands/testWaitForCommands.js new file mode 100644 index 0000000000..2185012b07 --- /dev/null +++ b/test/src/apidemos/waitFor-commands/testWaitForCommands.js @@ -0,0 +1,43 @@ +const path = require('path'); +const assert = require('assert'); +const MockServer = require('../../../lib/mockserver.js'); +const Mocks = require('../../../lib/command-mocks.js'); +const common = require('../../../common.js'); +const {settings} = common; +const NightwatchClient = common.require('index.js'); + +describe('waitFor commands tests', function() { + beforeEach(function(done) { + this.server = MockServer.init(); + this.server.on('listening', () => { + done(); + }); + }); + + afterEach(function(done) { + this.server.close(function() { + done(); + }); + }); + + it('run waitFor api demo tests ', function() { + const testsPath = path.join(__dirname, '../../../apidemos/waitFor-commands/waitForElementTest.js'); + + Mocks.visible('0', false); + + const globals = { + waitForConditionPollInterval: 50, + + reporter(results) { + assert.ok(results.lastError, 'should return NightwatchAssertError'); + assert.strictEqual(results.skipped, 0, 'should not skip any tests'); + } + }; + + return NightwatchClient.runTests(testsPath, settings({ + output: false, + globals + })); + }); + +}); \ No newline at end of file