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

fix: assertion failure in new Elem API leads to unhandledRejection. #4277

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

garg3133
Copy link
Member

Right now, if we create a test case using an async callback but do not use await anywhere inside the test case, failure of the newly introduced assertions in the new Element API leads to unhandledRejection:

it('asserts using newly introduced assertions', async function(browser) {
    browser.navigateTo('https://duckduckgo.com');

    browser.element('input[name=q]').assert.not.visible(); // it should fail normally but leads to unhandledRejection
    browser.element('input[name=q]').getText().assert.contains('Search');
});

With this PR, assertion failures will gracefully end the test instead of raising unhandledRejection which abruptly ends the test run.

Caveat

If we use then() with the assertion promises, assertion failure leads to unhandledRejection. But using then() inside an async function is not common, nor is using then() on any normal Nightwatch command or assertion.

it('asserts using newly introduced assertions', async function(browser) {
    browser.navigateTo('https://duckduckgo.com');

    // using `then()` on NW commands/assertions is not recommended
    browser.element('input[name=q]').assert.not.visible().then((res) => console.log(res));
    
    // use like below instead
    const res = await browser.element('input[name=q]').assert.not.visible();
    console.log(res);
});

Copy link

Status

  • ❌ No modified files found in the types directory.
    Please make sure to include types for any changes you have made. Thank you!.

@garg3133 garg3133 changed the title fix: assertion failure in new Elem API leading to unhandledRejection. fix: assertion failure in new Elem API leads to unhandledRejection. Oct 20, 2024
@garg3133 garg3133 merged commit a3f3181 into nightwatchjs:main Oct 21, 2024
15 of 17 checks passed
@garg3133 garg3133 deleted the fix-unhandled-on-new-assert branch October 21, 2024 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant