Test Overview
This test demonstrates how Cypress automatically retries commands until the element appears or the assertion passes. It verifies that a button becomes visible after a delay and can be clicked successfully.
This test demonstrates how Cypress automatically retries commands until the element appears or the assertion passes. It verifies that a button becomes visible after a delay and can be clicked successfully.
describe('Retry-ability of commands', () => { it('should wait for the button to appear and click it', () => { cy.visit('https://example.cypress.io/commands/waiting') // The button appears after 3 seconds cy.get('#delayed-button', { timeout: 5000 }) .should('be.visible') .click() cy.get('#delayed-button').should('have.class', 'clicked') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, browser ready | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io/commands/waiting' | Page loads with delayed button not yet visible | — | PASS |
| 3 | Cypress tries to find element with selector '#delayed-button' with 5 seconds timeout | Button not visible initially, appears after 3 seconds | Waits and retries until '#delayed-button' is found and visible | PASS |
| 4 | Cypress asserts '#delayed-button' is visible | Button is visible on the page | Check that button is visible | PASS |
| 5 | Cypress clicks the '#delayed-button' | Button is clicked, changes state | — | PASS |
| 6 | Cypress asserts '#delayed-button' has class 'clicked' | Button has class 'clicked' after click | Verify button state changed after click | PASS |
get combined with should assertions that retry until condition is true.get with should('be.visible') which retries until the button is visible before clicking.cy.get('#status').should('contain', 'Success')
cy.get('#submit').click()status initially does not contain 'Success' but updates after 2 seconds?should('contain', 'Success') assertion retries until the text appears or timeout.cy.get('.loading').should('not.exist')
cy.get('.content').click().content is not clickable yet. What is the likely cause?should('not.exist') retries until the loading element disappears, so this part works correctly.get command retries until the element exists but does not wait for it to be clickable or visible before clicking.should('not.exist') on spinner retries until spinner is gone, ensuring loading finished.should('be.visible') retries until button is visible and ready for click, avoiding flaky clicks.Pass the test and this pattern moves unknown