Open humphreyn opened 1 year ago
This could be a duplicate of #2510
Hi @AutomatedTester I am not sure. Existing API commands do stop the tests from continuing, but when you create a custom command that follows the documentation it does not.
@swrdfish , is there any timeline as to when this will be fixed as we cannot migrate from version 1.* until this is resolved
@humphreyn this is a complex bug, we are looking into it but cannot promise on a timeline yet.
@humphreyn Is it happening with the default test format or is it only when using the Cucumber runner?
@beatfactor , I will set up a test can get back to you as we currently only use the Cucumber runner.
@beatfactor, using the NW runner doesn't stop execution. To the default NW project installed with "npm init nightwatch" I added the below as follows:
//nightwatch/page-objects/google/search.js
const searchCommands = {
dismissModal(){
this.waitForElementVisible('@button', 5000)
.click('@button');
this.api.myCustomCommand();
return this; // for command-chaining
},
submit() {
this.waitForElementVisible('@submitButton', 1000)
.click('@submitButton');
this.pause(1000);
return this; // for command-chaining
}
};
module.exports = {
url: 'https://google.no',
commands: [
searchCommands
],
elements: {
searchBar: {
selector: 'textarea#APjFqb'
},
submitButton: {
selector: 'input.gNO89b'
},
button: {
selector:'button#W0wltc'
}
}
};
//nightwatch/examples/with-page-objects/google.js
describe('google search with consent form - page objects', function() {
const homePage = browser.page.google.search(); // first page-object
before(async () => {
homePage.navigate();
});
after(async (browser) => browser.quit());
it('should find nightwatch.js in results', function(browser) {
homePage.dismissModal();
homePage.setValue('@searchBar', 'Nightwatch.js');
homePage.submit();
const resultsPage = browser.page.google.searchResults(); // second page-object
resultsPage.expect.element('@results').to.be.present;
resultsPage.expect.element('@results').text.to.contain('Nightwatch.js');
resultsPage.expect.section('@menu').to.be.visible;
const menuSection = resultsPage.section.menu;
menuSection.expect.element('@all').to.be.visible;
});
});
//nightwatch/custom-commands/myCustomCommand.js
module.exports = class MyCustomCommand {
command(callback) {
if (typeof callback === "function") {
callback.call(this.api);
}
const result = {
"status": -1,
"value": false,
"error": new Error("Promise Class Command 'myCustomCommand' returns promise.reject")
}
return Promise.reject(result);
}
};
//output after running: npx nightwatch ./nightwatch/examples/with-page-objects/google.js
google search with consent form - page objects] Test Suite
───────────────────────────────────────────────────────────────────────────────
ℹ Connected to ChromeDriver on port 9515 (2418ms).
Using: chrome (113.0.5672.126) on MAC OS X.
ℹ Loaded url https://google.no in 1219ms
Running should find nightwatch.js in results:
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔ Element <button#W0wltc> was visible after 50 milliseconds.
Error
Promise Class Command 'myCustomCommand' returns promise.reject
✔ Element <input.gNO89b> was visible after 131 milliseconds.
✔ Expected element @results <#rso> to be present (66ms)
✔ Expected element @results <#rso> text to contain: "Nightwatch.js" (138ms)
✔ Expected element @menu <#hdtb-msb> to be visible (43ms)
✔ Expected element <Section [name=menu],Element [name=@all[0]]> to be visible (152ms)
FAILED: 1 errors and 6 passed (2.199s)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
️TEST FAILURE (7.331s):
- 1 error during execution;
- 0 assertions failed; 6 passed
✖ 1) with-page-objects/google
– should find nightwatch.js in results (2.199s)
- OTHER ERRORS:
Error
Error
Promise Class Command 'myCustomCommand' returns promise.reject
FYI @humphreyn
@humphreyn If you are migrating a framework you might also be interested in this issue. This one is my blocker and you might hit it. I am also migrating a ~2000 test framework from 1.*.
While working on the migration I had also hit the issue you had logged here so thank you for logging it.
Description of the bug/issue
When I call my custom command that returns a promise.reject Then I expected the scenario.result.status to equal "FAILED" in the cucumber AfterStep And I expect any following cucumber steps to be skipped But instead the AfterStep scenario.result.status equals "PASSED" And any following cucumber steps are executed
Steps to reproduce
Any custom command that returns a promise.reject causes this error The attached script uses a custom command that always returns a promise reject We have 1.x custom commands that wait for a condition and return a promise.reject if that condition is not met within the timeout period Version 2.x does not seem to handle custom commands promise.rejects at all
Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
2.6.21
Node Version
16.18.0
Browser
chrome 113.0.5672.127
Operating System
No response
Additional Information
No response