Avoiding timeouts in test code
In this section, we’ll improve the speed at which our Cucumber tests run by replacing waitForTimeout
calls with waitForSelector
calls.
Many of our step definitions contain waits that pause our test script interaction with the browser while we wait for the animations to finish. Here’s an example from our tests, which waits for a period of 3 seconds:
await this.getPage("user").waitForTimeout(3000);
Not only will this timeout slow down the test suite, but this kind of wait is also brittle as there are likely to be occasions when the timeout is slightly too short and the animation hasn’t finished. In this case, the test will intermittently fail. Conversely, the wait period is actually quite long. As more tests are added, the timeouts add up and the test runs suddenly take forever to run.
Avoiding timeouts
Regardless of the type of automated test, it is a good idea to avoid timeouts in your test code. Timeouts...