What is the purpose of the automatic retry mechanism in Cypress?
It helps Cypress automatically retry commands and assertions until they pass or a timeout occurs, making tests more stable and reliable.
Click to reveal answer
beginner
Which Cypress commands benefit from automatic retries?
Commands like cy.get(), cy.contains(), and assertions such as should() are automatically retried until they pass or timeout.
Click to reveal answer
intermediate
How does Cypress decide when to stop retrying a command?
Cypress stops retrying when the command or assertion passes or when the default timeout (usually 4 seconds) is reached.
Click to reveal answer
intermediate
How can you customize the retry timeout in Cypress?
You can set a custom timeout by passing the { timeout: milliseconds } option to commands, for example: cy.get('.btn', { timeout: 10000 }) retries for 10 seconds.
Click to reveal answer
beginner
Why is automatic retry better than adding manual waits in tests?
Automatic retry waits only as long as needed for the condition to pass, making tests faster and less flaky compared to fixed manual waits.
Click to reveal answer
What happens if a Cypress command fails initially?
AThe test immediately fails without retrying.
BCypress retries the command until it passes or times out.
CCypress skips the command and continues.
DThe test pauses and waits for manual input.
✗ Incorrect
Cypress automatically retries commands and assertions until they pass or the timeout is reached.
Which of these commands does Cypress retry automatically?
Acy.task()
Bcy.log()
Ccy.exec()
Dcy.get()
✗ Incorrect
cy.get() is retried automatically; commands like cy.log() do not retry.
How can you increase the retry timeout for a specific command?
ABy adding <code>{ timeout: value }</code> option to the command
BBy changing the global Cypress config only
CBy adding <code>cy.wait()</code> before the command
DBy disabling retries in Cypress
✗ Incorrect
You can pass a timeout option directly to commands to customize retry duration.
What is the default timeout for retries in Cypress?
A4 seconds
B10 seconds
C1 second
DNo timeout, retries forever
✗ Incorrect
By default, Cypress retries commands for up to 4 seconds before failing.
Why should you avoid using fixed waits instead of relying on automatic retries?
AFixed waits are required for retries to work.
BFixed waits make tests faster.
CFixed waits slow down tests and can cause flakiness.
DAutomatic retries do not work with dynamic content.
✗ Incorrect
Fixed waits add unnecessary delay and can cause flaky tests; automatic retries wait only as long as needed.
Explain how Cypress automatic retry mechanism improves test reliability.
Think about how waiting for elements or conditions works in real life.
You got /4 concepts.
Describe how to customize retry timeout for a Cypress command and why you might do it.
Consider a slow website or network delay scenario.
You got /3 concepts.
Practice
(1/5)
1. What does Cypress's automatic retry mechanism do during test execution?
easy
A. It requires manual loops to retry commands.
B. It skips failed tests automatically without retrying.
C. It keeps trying commands and assertions until they pass or timeout.
D. It only retries tests when explicitly told by the user.
Solution
Step 1: Understand Cypress retry behavior
Cypress automatically retries commands and assertions until they pass or the timeout is reached.
Step 2: Compare options with this behavior
Only the option stating "It keeps trying commands and assertions until they pass or timeout." correctly describes this automatic retry mechanism without manual intervention.
Final Answer:
It keeps trying commands and assertions until they pass or timeout. -> Option C
Believing Cypress skips failed tests without retry
Assuming manual loops are needed for retries
2. Which of the following is the correct syntax to assert that an element with id submit-btn is visible, leveraging Cypress's automatic retry?
easy
A. cy.get('#submit-btn').assertVisible()
B. cy.get('#submit-btn').should('be.visible')
C. cy.find('#submit-btn').should('visible')
D. cy.getElement('#submit-btn').isVisible()
Solution
Step 1: Identify correct Cypress command and assertion
The correct command to select an element is cy.get() and the assertion to check visibility is should('be.visible').
Step 2: Validate syntax correctness
cy.get('#submit-btn').should('be.visible') uses the correct syntax and leverages automatic retry on the assertion. Other options use invalid commands or incorrect assertion syntax.
Final Answer:
cy.get('#submit-btn').should('be.visible') -> Option B
But the test fails because #result text updates slowly. Which fix uses Cypress's automatic retry correctly?
medium
A. Use cy.get('#result', { timeout: 7000 }).should('contain', 'Done') to increase timeout.
B. Change to cy.get('#result').should('contain', 'Done') as is (no change).
C. Replace should with then for immediate check.
D. Add cy.wait(5000) before the assertion.
Solution
Step 1: Identify problem with slow update
The element #result updates slowly, so default timeout may be too short.
Step 2: Use automatic retry with increased timeout
Use cy.get('#result', { timeout: 7000 }).should('contain', 'Done') to increase the timeout, letting Cypress retry the assertion longer until it passes.
Final Answer:
Use cy.get('#result', { timeout: 7000 }).should('contain', 'Done') -> Option A
Quick Check:
Increase timeout to let retry succeed [OK]
Hint: Increase timeout to extend retry duration [OK]
Common Mistakes:
Using fixed waits instead of timeout options
Not changing anything and expecting success
Replacing should with then, which disables retry
5. You want to test a button that becomes enabled only after an API call completes. The button has id submit-btn. Which Cypress code best uses automatic retry to wait for the button to be enabled before clicking it?
hard
A. cy.get('#submit-btn').should('be.enabled').click()
B. cy.get('#submit-btn').click()
C. cy.wait(3000); cy.get('#submit-btn').click()
D. cy.get('#submit-btn').then($btn => { if ($btn.is(':enabled')) { $btn.click() } })
Solution
Step 1: Understand button enabling timing
The button becomes enabled after an API call, so it may be disabled initially.
Step 2: Use automatic retry on enabled state
cy.get('#submit-btn').should('be.enabled').click() uses should('be.enabled') which retries until the button is enabled, then clicks it.
Final Answer:
cy.get('#submit-btn').should('be.enabled').click() -> Option A
Quick Check:
Use should('be.enabled') to wait before click [OK]
Hint: Chain should('be.enabled') before click to wait [OK]
Common Mistakes:
Clicking immediately without waiting
Using fixed wait instead of retry
Using then() which disables retry and may fail
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.