Open reallymello opened 7 months ago
This is actually a known issue where the test run ends abruptly on unhandledRejection
or uncaughtError
and I had started working on it but then had to re-prioritize stuff. I'll try to take this up on priority again.
But for your particular examples, it will be handled correctly by Nightwatch if you move the await
from inside to outside the parenthesis:
const billingCard = locateWith(By.css(`body`));
const headerElement = await browser.element.find(billingCard).findElement(
By.css('[this="doesntExist"]')
);
Explanation for above: When you do browser.element.find()
, it returns a Nightwatch wrapper around the actual result, that contains the various API methods provided by Nightwatch (like chained .find()
commands, .getText()
, etc). But when you await
this statement, it would resolve to the actual result (a WebElement instance here).
Now, if you do .findElement()
on the WebElement
instance directly (which you are doing in the example provided), it would directly go to Selenium and any errors won't be handled by Nightwatch (though we should add something to handle it in future), so you get the unhandledRejection
error.
But if you call the findElement()
on the Nightwatch wrapper directly, then the .findElement()
command would go through the Nightwatch implementation, where everything is handled. This .findElement()
will also in turn return the Nightwatch wrapper around the actual result, so to get the actual final result you can use await
over the entire statement.
Description of the bug/issue
I have an async page object command that returns an object containing Definition(s). Those definitions are found by chaining using syntax like
If billingCard is present in the DOM, but the selector in the chained findElement does not, when I run the test I get an unhandledRejection and Nightwatch exits unexpectedly without finishing out the test and closing the browser.
Steps to reproduce
npx nightwatch nightwatch\test\google.ts
Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
3.6.0
Node Version
21.6.2
Browser
Chrome 123
Operating System
Windows 11
Additional Information
nightwatchUnhandled.zip