Test Retries | Bondar Academy
Course: Cypress UI Testing with JavaScript
Module: Advanced Features
Instructor: Artem Bondar
Lesson Summary
In this lesson, we discuss test retries in Cypress, addressing the issue of flaky UI tests . Flaky tests can pass or fail unpredictably, making debugging challenging. This can lead to inaccurate reporting, where tests that should pass fail intermittently. Understanding Flaky Tests Flaky tests may fail due to: State of the application at the time of the test Environmental factors affecting the test execution Implementing Test Retries To manage flaky tests, Cypress allows you to configure a retries feature . This feature automatically retries failed tests to determine if the failure is due to flakiness or an actual bug. Configuration Steps retries: { runMode: 1, openMode: 0 } In this configuration: runMode : Number of retries in headless mode (e.g., CI/CD pipeline). openMode : Number of retries when running tests in the Cypress GUI. Why Separate Configurations? Separating configurations is beneficial because: Open Mode : Used for developing tests where retries may not be desired. Run Mode : Typically more flaky due to slower execution in CI/CD environments. Advanced Retry Configuration You can also set specific retry attempts for individual tests: it('test name', { retries: 2 }, () => { ... }); This allows for more flexibility in handling particularly flaky tests. In summary, configuring test retries is a simple yet effective way to enhance the stability of your Cypress tests and manage flakiness efficiently.