Cypress automatically tries commands again to help tests pass even if the page is slow or changes slowly. This makes tests less likely to fail by mistake.
Why Cypress auto-retries reduce flakiness
cy.get('selector').click()
Cypress automatically retries commands like get and click until they succeed or timeout.
You don't need to add extra waits or retries manually for most cases.
cy.get('#submit-button').click()
cy.get('.loading-spinner').should('not.exist')
cy.get('input[name="email"]').type('user@example.com')
This test visits a page where a button appears after 2 seconds. Cypress keeps trying to find and click the button until it appears, so the test passes without manual waits.
describe('Auto-retry example', () => { it('clicks a button that appears after delay', () => { cy.visit('https://example.cypress.io/delay') // The button appears after 2 seconds cy.get('#delayed-button').click() cy.get('#result').should('contain.text', 'Clicked!') }) })
Cypress retries commands up to the default timeout (usually 4 seconds).
This reduces flaky failures caused by slow loading or animations.
Common mistake: Adding manual waits instead of relying on auto-retries can slow tests unnecessarily.
Cypress auto-retries commands to wait for elements to be ready.
This makes tests more stable and less flaky.
You usually don't need extra waits or retries in your test code.
Practice
Solution
Step 1: Understand Cypress command retries
Cypress retries commands automatically to wait for elements to appear or become ready before continuing.Step 2: Connect retries to test stability
This retry behavior helps reduce flaky tests caused by timing issues or slow page loads.Final Answer:
To wait for elements to become ready and reduce test flakiness -> Option AQuick Check:
Auto-retries improve stability = B [OK]
- Thinking retries slow down tests intentionally
- Believing retries change test data
- Assuming retries skip tests
Solution
Step 1: Identify valid Cypress command syntax
The correct command to get an element and click it iscy.get('.btn').click().Step 2: Understand auto-retry usage
cy.get()automatically retries until the element appears, making tests less flaky.Final Answer:
cy.get('.btn').click() -> Option DQuick Check:
Correct command with auto-retry = A [OK]
- Using non-existent commands like cy.waitFor
- Confusing cy.find with cy.get
- Trying to click directly with cy.click('.btn')
cy.get('#submit').click()
cy.get('.result').should('contain', 'Success')What happens if the '.result' element appears after 2 seconds?
Solution
Step 1: Analyze Cypress auto-retry behavior on assertions
Cypress retriescy.get('.result')and the assertion until the element appears or timeout expires.Step 2: Understand timing and test outcome
If '.result' appears within the default timeout (usually 4 seconds), the test passes after retrying.Final Answer:
Cypress retries and waits up to default timeout, then passes if element appears -> Option BQuick Check:
Auto-retry waits for element = D [OK]
- Assuming immediate failure if element not found instantly
- Thinking test passes without checking element
- Expecting syntax errors from valid code
cy.get('.list-item').click()
cy.get('.detail').should('be.visible')But the test sometimes fails because '.detail' is not visible immediately. What is the best fix?
Solution
Step 1: Identify problem with visibility timing
The '.detail' element is not visible immediately, causing flaky failures.Step 2: Use timeout option to extend auto-retry wait
Adding{ timeout: 10000 }tocy.get()lets Cypress retry longer before failing.Final Answer:
Use cy.get('.detail', { timeout: 10000 }).should('be.visible') -> Option CQuick Check:
Extend timeout for retries = A [OK]
- Adding fixed waits which slow tests unnecessarily
- Ignoring retries and expecting instant visibility
- Using cy.find incorrectly
Solution
Step 1: Understand Cypress auto-retry for dynamic elements
Cypress automatically retriescy.get()and assertions until the button appears or timeout.Step 2: Avoid fixed waits or manual delays
Using fixed waits or manual delays slows tests and can cause flakiness if timing changes.Final Answer:
Use cy.get('button').should('be.visible') without extra waits -> Option AQuick Check:
Rely on auto-retry, avoid fixed waits = C [OK]
- Adding long fixed waits that slow tests
- Using setTimeout which is not Cypress-friendly
- Refreshing page manually instead of waiting
Ready to prove it?
Pass the test and this pattern moves unknown
