Search code examples
automated-testsmocha.jscypressui-automationretry-logic

Cypress Retries: How to get the retry attempt count in the test


How do we capture the retry count in the it() block?

My scenario is:

  • Upon first time login, the user has to change password to get to homescreen and do some checks

  • If the check/test fails, the it() block will be retried, but this time the user doesn't have to change password, because its not the first time login anymore. The password change already happened in the first attempt.

  • This time (second retry attempt onwards..), user only logs in and performs the same checks from first step

I want to put a condition in my it() block that,

if (retry = '1st attempt')
  changePasswordUponLogin()
else
  onlyLogin()

So how do I get the above retry value in the test?


Solution

  • Please take a look at Can I access the current attempt counter from the test?

    const attempt = cy.state('runnable')._currentRetry