Open memihai opened 1 year ago
@memihai Check this issue, I think there might be an overlap, as it's the same kind of error.
@asos-saveriocutrupi I hit that error too but that one hangs the process indefinitely. I never logged it as I didn't know how to reproduce it.
There are 2 differences between that and the current issue: 1) The problem I am seeing is not related to custom commands as expect statements still fail if they are in a Page Object and the selector doesn't match an element. 2) The Node process exists abruptly (without stack trace obviously) I have no idea what blows up and I could find no workaround to this other than moving assertions into the step definitions, which is not an option for me.
But thanks for pointing that issue out! Good to know about it as I can now avoid it 👍 .
I played around with this today and realised that if I define the command like this
commands: [
{
async waitForAnElementToBeVisible() {
//this.expect.element('@randomXpath').to.be.visible;
await this.customWait(xpath.randomXpath('Random string'));
}
}
],
So it returns a promise then I use it like so in the step definition:
Given(/^I open the Rijksmuseum page$/, async function() {
await browser.navigateTo('https://www.rijksmuseum.nl/en');
await browser.page.RijksmuseumHomepage().waitForAnElementToBeVisible();
});
Then the tests behave as expected. After the first test failed the second one is run and the result is 2 out of 2 failures.
There is a simpler test case for this issue in https://discord.com/channels/618399631038218240/1072553726193184788/threads/1083290462011523142
describe('Ecosia', function() {
// test() and specify() is also available
it('demo test', function(browser) {
browser
.url('https://www.ecosia.org/%27)
.setValue('input[type=search]', 'nightwatch')
.click('button[type=submit]')
// .assert.containsText('.mainline-results', 'Nightwatch.js')
browser.waitForElementNotPresent('#dialog', 50000)
.end();
});
});
Updating priority. Hopefully we can get to this soon!
I can also reproduce this issue and it is one of the blockers for upgrading to v2.
The problem described here is still an issue in Nightwatch 3.0.1, I just tested it today. @ituradastra FYI.
@gravityvi, @AutomatedTester Do you have any updates on this? We want to resume our efforts to migrate to NW3 now and this is a blocker for us.
@memihai I don't think it's a bug while using cucumber the nightwatch commands should return a promise or a value in the example shown above the page command isn't returning a promise.
To fix the test just return the result from customWait. Let me know if I missed something here.
Actual Example:
waitForAnElementToBeVisible() {
//this.expect.element('@randomXpath').to.be.visible;
this.customWait(xpath.randomXpath('Random string'));
return this;
}
Fixed command:
waitForAnElementToBeVisible() {
return this.customWait(xpath.randomXpath('Random string'));
}
@gravityvi yes your solution works for that example but what if I want to click the element after waiting for it to be visible
waitForAnElementToBeVisible() {
this.customWait(xpath.randomXpath('Random string'));
return this.click(xpath.randomXpath('Random string');
}
This will fail the same way I had pointed out in the issue.
Another thing I tried is to return the result from the command which should be a promise
// customCommands/customWait
module.exports = class customWait {
command(selector , typeOfSelector='xpath') {
return browser.waitForElementVisible('xpath', selector)
}
}
and then chain the wait and click:
waitForAnElementToBeVisible() {
return this.customWait(xpath.randomXpath('Random string')).click(xpath.randomXpath('Random string'));
}
This will fail the same way I had pointed out in the issue.
I would expect both scenariops to work or at least the last one. Am I wrong in my assumptions?
Description of the bug/issue
When the runner is Cucumber if an assertion fails in a Page Object the process exists abruptly with no stack trace.
Steps to reproduce
Actual: Node process exists with exit code 0 after the NightwatchAssertError is thrown.
Expected: Test is failed and next test is run.
Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
2.6.11
Node Version
17.8.0
Browser
Chrome 109.0.5414.119
Operating System
No response
Additional Information
This reproduces with custom commands and expect statemetns like this.expect.element('@randomslector').to.be.visible;