Cypress · Browser testing end to end
How does Cypress retry-ability work?
Short answer
Only the last command in a chain and its assertions are retried. Cypress re-runs that command and query until the assertions pass or the timeout expires; earlier commands in the chain are not re-executed.
Retry-ability is Cypress's answer to asynchronous UI. When a chain ends in an assertion, Cypress reruns the query that produced the subject and checks the assertion again. It keeps doing that until the assertion passes or the command times out. This is why a test can assert on a value that appears a moment later without a sleep.
cy.get("[data-cy=status]")
.should("have.text", "Ready");Only the last command retries
This is the detail most people miss. If a chain is cy.get, find, first, should, the retry applies to the tail of the chain, not to every step independently. Cypress restarts the query from the last command that can be retried, which is typically the query immediately before the assertion. A stale subject earlier in the chain is not magically refreshed.
cy.get("[data-cy=row]")
.find("[data-cy=status]")
.should("have.text", "Paid");- Retry applies to queries and assertions at the end of the chain
- A .then callback is not retried as a whole
- Network-dependent changes need an intercept or a fresh query, not a longer sleep
- Timeouts bound the retry loop; a longer timeout is not a fix for a real race
- Actions such as click are not retried blindly, so assert the resulting state
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Which command in a chain is retried?
- 2Does a .then callback retry?
- 3How do you make a network-driven assertion reliable?
- 4Why is increasing the timeout not a real fix?
Say it in the interview
Retry-ability means Cypress reruns the last query and its assertions until they pass or time out. Earlier commands are not re-executed, and a then callback is not retried as a unit. So I put the volatile part of the assertion at the end of the chain and start from a selector that can be re-evaluated. For network-driven UI I intercept the request and wait for its alias rather than extending a timeout.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Cypress mock interview and get scored feedback on depth, clarity and confidence.