webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.01k stars 2.5k forks source link

[🐛 Bug]: Mocha Step Definition Timeout #12102

Closed NIBOSAP closed 8 months ago

NIBOSAP commented 8 months ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.27.1

Node.js Version

18

Mode

WDIO Testrunner

Which capabilities are you using?

No response

What happened?

Local Timeout for step definitions doesn't work:

In the config:

framework: 'mocha',
mochaOpts: {
        ui: 'bdd',
        timeout: 60000
    },

If we want to set a specific timeout for a specific mocha step:

    it('Test timeout mocha', async () =>  {
        this.timeout(120000); // 2min
    });

The timeout for the step (it) is not set to 2min. And the mocha timeout appears at 1min:

 Error in "Test timeout mocha"
Error: Timeout
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7)

Seems to be the same that the one for cucumber: https://github.com/webdriverio/webdriverio/issues/11873

What is your expected behavior?

Timeout must be taken into account

How to reproduce the bug.

use repo - https://github.com/NIBOSAP/webdriverIO-with-mochaBDD

and run:

npm i
npx wdio wdio.local.conf.ts  --spec ./test/specs/timeout-test.spec.ts

Relevant log output

[chrome 120.0.6099.234 mac #0-0] Timeout
[chrome 120.0.6099.234 mac #0-0] Error: Timeout
[chrome 120.0.6099.234 mac #0-0]     at listOnTimeout (node:internal/timers:569:17)
[chrome 120.0.6099.234 mac #0-0]     at processTimers (node:internal/timers:512:7)


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### Is there an existing issue for this?

- [X] I have searched the existing issues
wdio-bot commented 8 months ago

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

jhorvat7 commented 8 months ago

I do not believe this is a bug and it is working as intended. It's just not possible to change the timeout within a lambda function. It is a simple fix though. Just convert your it block into a non arrow function. Your it block should look like this:

it('Test timeout mocha', async function () { this.timeout(120000); // 2min //this.timeout is not necessary if declaring //this.timeout in non-lambda describe block //You can immediately start using larger timeout });

I don't remember if it is required that you make your describe block have a non-lambda function with an increased timeout too. It may not be required, but here's what it would look like anyway if you want to be safe (I'm replying on a phone so excuse any odd formatting):

describe('My description', function (){ this.timeout(120000);

it('Test timeout mocha', async function () { this.timeout(120000); // 2min });

});

vinodreddy-bs commented 8 months ago

Not a Bug. Read this: https://mochajs.org/#arrow-functions. As mentioned by @jhorvat7 try that without lamdas/arrow

christian-bromann commented 8 months ago

@vinodreddy-bs good catch 👌

NIBOSAP commented 8 months ago

@jhorvat7 @vinodreddy-bs @christian-bromann Thanks a lot guys for your replies.

I made a mistake in my examples... I don't have arrow functions in my code but when I got the boiler webdriverIO-with-mochaBDD, I forgot to remove it. My bad...

For the issue, @jhorvat7, I tried this:

it('Test timeout mocha', async function () {
     this.timeout(120000); // 2min
});

without adding this.timeout(120000); in the describe, and the timeout is not taken in account.

And, when I tried what you supposed to do:

describe('My description', function (){
     this.timeout(120000);

     it('Test timeout mocha', async function () {
          this.timeout(120000); // 2min
     });
});

The timeout is set for all 'it' blocks. So it works also without the this.timeout(120000); in the it:

describe('My description', function (){
     this.timeout(120000);

     it('Test timeout mocha', async function () {

     });
});

I thought that we can set a specific timeout for a specific 'it' block, It's what I want to do. So, what to do you think? Should this be possible ? Many thanks.

NIBOSAP commented 8 months ago

I found another way to set the timeout for a specific 'it', and it works:

it('Test timeout mocha', async function () {

}).timeout(120000);

Thanks :)

talbss commented 5 months ago

@BorisOsipov @christian-bromann can you reopen the issue please.
I am facing exactly the same issue as described by @NIBOSAP in this post after upgrading from wdio 7 to wdio8. (Same code, per it timeouts ignored with wdio8). Thank you

wdio-bot commented 5 months ago

Thanks for raising this issue 🙏

Unfortunately we can't help you without a reproducible example in this matter. Please read our contributing guidelines on how to create a reproducible example. If you can't provide a reproducible example we will close this issue in 7 days.

If you have any questions please reach out to us on our Discord channel. We are happy to help you out there.

BorisOsipov commented 5 months ago

@talbss feel free to create a new issue with a reproducible example