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

Run is stoped after a fail/error in any before() method #4284

Closed
olkaz opened this issue Oct 25, 2024 · 3 comments
Closed

Run is stoped after a fail/error in any before() method #4284

olkaz opened this issue Oct 25, 2024 · 3 comments

Comments

@olkaz
Copy link

olkaz commented Oct 25, 2024

Description of the bug/issue

When run get a NightwatchAssertError (or any other fail/error) in before() method the all run a stopped. No report is created.

I'm expecting that only failed test will be skipped, not an entire suite.

Steps to reproduce

Clone an example project
Run npm install
run >> npx nightwatch ./test/mobile-app-tests/ --env app.android.real --reporter=html --open

Sample test

Check an example project

Command to run

npx nightwatch ./test/mobile-app-tests/ --env app.android.real --reporter=html --open

Verbose Output

No response

Nightwatch Configuration

Check an example project

Nightwatch.js Version

3.8.0

Node Version

No response

Browser

No response

Operating System

No response

Additional Information

Example test > https://github.com/pretorian121/test-proj

Problem in a discord chat > https://discord.com/channels/618399631038218240/935468415731253258/1298987835650605206

@garg3133
Copy link
Member

@garg3133
Copy link
Member

@olkaz Sorry for getting here late, but this issue is happening because you're using the done() call in the before() hook. Since you're already writing your tests using async/await syntax, done() is not required.

If you instead write your before hook as below, the tests will work fine.

    before(async function (app: NightwatchAPI) {
        await app.waitForElementPresent({locateStrategy: 'id', selector: 'org.wikipedia:id/fragment_onboarding_skip_button2'})
            .click('id', 'org.wikipedia:id/fragment_onboarding_skip_button2');
    });

The issue happening in your case is that the before hook gets temporarily stuck after the NightwatchAssertError because the first statement in before hook keeps on awaiting a result from the click() command but because the earlier waitForElementPresent command failed, the click command is never run. So, because the await in the first statement is never resolve, the following done() is also never called and so the before hook gets stuck.

Now, normally the hook would be stuck for 20 secs after which the asyncHookTimeout would come into play and the before hook would timeout, and so the rest of the tests would continue. But because you've set the asyncHookTimeout to 170000, the before hook remains stuck for 170 secs in your case, after which the tests continue normally.

But all in all, this issue is easily resolvable by removing the use of done in the hook.

Another alternative to resolve this is to use await with just the waitForElementPresent command and write browser.click() command as a separate statement instead of chaining them together.

@garg3133
Copy link
Member

garg3133 commented Jan 10, 2025

Closing this issue. Feel free to reopen in case this is still not resolved on your end.

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

No branches or pull requests

2 participants