Skip to content

Commit

Permalink
fix abortOnAssertionFailure issue with waitFor commands
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityvi committed Oct 12, 2023
1 parent f6ed245 commit 6b64e87
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
4 changes: 0 additions & 4 deletions lib/core/asynctree.js
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/testsuite/index.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions 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);
});
});
43 changes: 43 additions & 0 deletions 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
}));
});

});

0 comments on commit 6b64e87

Please sign in to comment.