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 three seconds:
await this.getPage('user').waitFor(3000);
Unfortunately, this kind of wait is 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.
What we can do instead is modify our production code to alert us when it is animating. We do this by adding an isAnimating class to the viewport div when an animation is running. We then use the Puppeteer waitForSelector function to...