0
0
Cypresstesting~10 mins

Retry-ability of commands in Cypress - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Cypress
Cypress
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')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, browser ready-PASS
2Browser opens and navigates to 'https://example.cypress.io/commands/waiting'Page loads with delayed button not yet visible-PASS
3Cypress tries to find element with selector '#delayed-button' with 5 seconds timeoutButton not visible initially, appears after 3 secondsWaits and retries until '#delayed-button' is found and visiblePASS
4Cypress asserts '#delayed-button' is visibleButton is visible on the pageCheck that button is visiblePASS
5Cypress clicks the '#delayed-button'Button is clicked, changes state-PASS
6Cypress asserts '#delayed-button' has class 'clicked'Button has class 'clicked' after clickVerify button state changed after clickPASS
Failure Scenario
Failing Condition: The '#delayed-button' does not appear within 5 seconds timeout
Execution Trace Quiz - 3 Questions
Test your understanding
What does Cypress do when it cannot find the '#delayed-button' immediately?
AIt retries finding the element until timeout expires
BIt fails the test immediately
CIt skips the test step
DIt reloads the page automatically
Key Result
Cypress automatically retries commands and assertions until they pass or timeout, making tests more reliable for elements that appear or change state asynchronously.