-
Notifications
You must be signed in to change notification settings - Fork 1.4k
unhandledRejection, crashes Nightwatch when using nth when upstream element is not found #4390
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
Comments
The issue was caused by an incorrect ID. The #main ID does not exist on Google's page, so the test was unable to locate the correct element, leading to errors. I tested a different case instead, as the Google test was causing more issues on my setup.
|
Sorry if I wasn't clear, yes, I purposefully designed the test to look for elements that don't exist because the issue I am reporting needs for that sort of failure to occur...e.g. the test was purposefully designed with that mistake/error to replicate the issue. The issue is, instead of Nightwatch reporting the missing element and logging a test failure it seems to crash out early and leave the browser and session closed which causes issues for the test suite run--especially in BrowserStack which encounters an eventual test timeout vs reporting back with a pass or fail. Organically, what happened in our real scenario was a test using a similar scenario was working fine for some time, but the page changed in a later build, causing the element to not be present and it started throwing this unhandled exception vs logging a normal test failure. I need someone from the dev team to look into what its happening and see why Nightwatch isn't handling it properly. |
I found the main issue in To fix this, I updated the code to properly mark the test as failed, clean up, and exit safely:
I hope this would help in bug fixing. |
Description of the bug/issue
When I use the
.nth(n)
method to select the nth item from the result of findElements and findElements returned no found elements then I expect my test to report a normal test failure, fail my test, run teardowns gracefully, and safely exit the Nightwatch process, but instead it throwsand the Nightwatch process short circuits/crashes without closing the browser or session (the browser remains open)
Steps to reproduce
Write an async test case that chains .findElements and .nth where the element selector in findElements yields no matches and execute the test. See the sample test below.
Sample test
Command to run
npx nightwatch nightwatch\nthTest.ts
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
3.12.0
Node Version
22.13.1
Browser
Chrome 134
Operating System
Windows 11
Additional Information
nth-issue.zip
The text was updated successfully, but these errors were encountered: