How to make testcase stable in cypress with retry.

In most automation frameworks, During testing, the application test might fail sometimes due to environmental issues or due to some slowness, and we might retry running it again, just to make sure the failure is real, and not an accidental fluke. Let’s discuss how to make test case stable in cypress with retry with its built-in features.

Cypress offers an option to re-execute a test case that is failing due to environmental issues and the flakiness of the test case.

We can implement retry capability in cypress by adding the following code snippet in the cypress.json file.


Find below the description for the above statement

runMode: allows you to define the number of test retries when running cypress run (Headless mode)

openMode: allows you to define the number of test retries when running cypress open

Retry functionality operates as

  1. A test runs for the first time. If the test passes, Cypress will move forward with remaining tests.
  2. Incase if test fails, Cypress will indicate that the first attempt got failed and will attempt to run the test a second time.
  3. If the test passes after the second attempt, Cypress will continue with remaining tests.
  4. If the test fails a second time, Cypress will mark the test as failed and then move on to run remaining tests.

Let’s run a test case by intentionally failing the test case by changing the list size to 1 in application with the original list size being 1.

cypress with retry

The above snippet shows that in open mode, the test case was attempted 2 times since the test case was failing.

In Run mode, the same logic is visible which is shown in the below snapshot.

cypress with retry

Leave a Reply