Introducing Test Retries in Cypress 5.0

August 19, 2020

By The Cypress Team

We are excited to announce that as of Cypress 5.0, Cypress will include native support for test retries! 🎉

What are test retries?

Similar to how Cypress will retry assertions when they fail, test retries is a new feature where Cypress will automatically retry a failed test prior to marking it as failed.

Why is this important?

In the course of an end-to-end (E2E) test run, it is fairly common for tests to fail intermittently due to integration dependencies temporarily going offline, random network failures, race conditions, etc.. And just like how you would expect a user to refresh their browser if they got a 404 error, it seems like a waste to fail an entire test run due to a random outage.

How do I get started?

In Cypress 5.0*, test retries are disabled by default; but it is easy to enable it!

With the new Test Retries feature, you also configure the number of retries in your cypress.json config file with the new retries property.

The simplest way to configure it is to pass a number which will define the number of retries for both cypress run and cypress open mode. For example, you can disable test retries globally by defining the retries property with 0 in your cypress.json configuration file.

{
  "retries": 0
}

However, in the event you need to define different retry attempts for the different modes of Cypress, you can pass retries an object with the following options:

  • runMode - allows you to define the number of test retries when running cypress run
  • openMode - allows you to define the number of test retries when running cypress open
{
  "retries": {
    // Configure retries for `cypress run` 
    // Default is 0
    "runMode": 1,
    // Configure retries for `cypress open`
    // Default is 0
    "openMode": 3
  }
}

*If you are running an older version of Cypress, be sure to check out our migration guide for how to upgrade to Cypress 5.0!

Will retried tests be counted as more than one test recording in my billing?

Nope! 🙂 Tests recorded during cypress run with the --record flag will be counted the same with or without test retries. As a result, test retries will not count as extra test recordings in your billing.

You can always see how many tests you’ve recorded from your organization’s Billing & Usage page within the Dashboard.

Next Steps

To learn more about test retries, be sure to check out our official Test Retries Guide.

Happy testing!