Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/3540 undhandled promises for wait commands #3570

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/core/asynctree.js
Expand Up @@ -87,20 +87,20 @@ class AsyncTree extends EventEmitter{
return parentNode.childNodes.filter(item => item !== node && !item.done).length > 0;
}

shouldRejectNodePromise(err) {
if ((err.isExpect|| this.currentNode.namespace === 'assert') && this.currentNode.isES6Async) {
shouldRejectNodePromise(err, node = this.currentNode) {
if ((err.isExpect|| node.namespace === 'assert') && this.currentNode.isES6Async) {
return true;
}

if (this.cucumberRunner) {
return err.waitFor;
}

return this.currentNode.rejectPromise || err.rejectPromise;
return node.rejectPromise || err.rejectPromise;
}

shouldRejectParentNodePromise(err) {
const {parent} = this.currentNode;
shouldRejectParentNodePromise(err, node = this.currentNode) {
const {parent} = node;
if (!parent || this.mochaRunner) {
return false;
}
Expand Down Expand Up @@ -129,18 +129,18 @@ class AsyncTree extends EventEmitter{
err.stack = err.stack.split('\n').slice(1).join('\n');
}

if (this.shouldRejectNodePromise(err)) {
this.currentNode.reject(err);
if (this.shouldRejectNodePromise(err, node)) {
node.reject(err);
} else {
this.currentNode.resolve(err);
node.resolve(err);
}

if (this.shouldRejectParentNodePromise(err)) {
if (this.shouldRejectParentNodePromise(err, node)) {
parent.reject(err);
}
} else {
node.resolveValue = result;
this.resolveNode(this.currentNode, result);
this.resolveNode(node, result);
Comment on lines +132 to +143
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this.currentNode which might have changed during execution (When there are events like abortOnFailure currentNode is shifted to rootNode), I've changed it node which is stored in the context while executing this function.

}

Logger.log(` ${Logger.colors.green('→')} Completed command: ${Logger.colors.light_green(node.fullName)}` +
Expand All @@ -157,7 +157,7 @@ class AsyncTree extends EventEmitter{
return err;
}

if (Debuggability.stepOverAndPause && node.parent.isRootNode && this.currentNode.fullName !== 'pause') {
if (Debuggability.stepOverAndPause && node.parent.isRootNode && node.fullName !== 'pause') {
this.currentNode.context.api.pause();
// Whether to stop after performing next step will be decided
// in the next "paused" prompt.
Expand Down
@@ -0,0 +1,12 @@
const {Given, Then} = require('@cucumber/cucumber');

Given('I navigate to localhost', function() {

return browser.url('http://localhost');
});

Then('I check if badElement is present', async function() {

await browser.customWaitForPresent('#badElement');
await browser.click('#webdriver');
});
5 changes: 5 additions & 0 deletions test/extra/commands/customWaitForPresent.js
@@ -0,0 +1,5 @@
module.exports = class CustomWaitForPresent {
async command(selector) {
await this.api.waitForElementPresent(selector);
}
};
4 changes: 3 additions & 1 deletion test/extra/cucumber-config.js
Expand Up @@ -11,8 +11,10 @@ module.exports = {

webdriver: {
start_process: false
},
},

custom_commands_path: [path.join(__dirname, './commands')],

globals: {
test_calls: 0,
waitForConditionTimeout: 20,
Expand Down
2 changes: 1 addition & 1 deletion test/src/apidemos/expect-global/testExpect.js
Expand Up @@ -48,7 +48,7 @@ describe('expect(element.<command>) - passed', function() {
const testsPath = path.join(__dirname, '../../../apidemos/expect-global/expect.js');

Mocks.elementNotSelected();
Mocks.elementProperty('0', 'className', {value: ['div-container']});
Mocks.elementProperty('0', 'className', {value: ['container']});
Copy link
Member Author

@gravityvi gravityvi Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is fixing a test which not reported earlier. The Nightwatch-test running inside this test has two expect out of which one should fail but without this change there would be two failures.
Nightwatch-Test: https://github.com/nightwatchjs/nightwatch/tree/main/test/apidemos/expect-global/expect.js


const globals = {
waitForConditionPollInterval: 50,
Expand Down
14 changes: 14 additions & 0 deletions test/src/runner/cucumber-integration/testCucumberSampleTests.js
Expand Up @@ -54,4 +54,18 @@ describe('Cucumber integration', function() {
});
});


it('testCucumberSampleTests - use custom commands failure', function() {
const source = [path.join(__dirname, '../../../cucumber-integration-tests/sample_cucumber_tests/customCommands/testCucumberWithCustomWait.js')];

return runTests({
source,
tags: ['@fail'],
verbose: false,
config: path.join(__dirname, '../../../extra/cucumber-config.js')
}, {})
.then(failures => {
assert.strictEqual(failures, true, 'Cucumber has test failures. Run with verbose to investigate.');
});
});
});