Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to reload the first test case if it fails in cypress

Every feature test case starts with landing page testing in cypress.

We are witnessing failures here because of network connectivity issues.

it('should load home page', () => {
    cy.waitUntil(() =>
      cy.contains('Home', { timeout: 500000 }).should('exist')
    );
  });

So, is there a way to reload this test case if it fails once or twice and avoid recursion?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I suspect retries will work here, if so how can we configure it?

>Solution :

You can use Test Retries. You can add it to Test Suite Level, Test Case level or globally as well. The test will be re-triggered in case of failures.

runMode works for headless. openMode for test runner. You can add both of them followed by how many times you want to retry them. So 2 means, once after the test failed, the test will be re-executed 2 times until the test passes, So if the test passes in the first re-execution, the second re-execution will not happen.

it(
  'should load home page',
  {
    retries: {
      runMode: 2,
      openMode: 1,
    },
  },
  () => {
    cy.waitUntil(() => cy.contains('Home', {timeout: 500000}).should('exist'))
  }
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading