0
0
Cypresstesting~10 mins

Command timeout vs assertion timeout in Cypress - Test Execution Compared

Choose your learning style9 modes available
Test Overview

This test demonstrates the difference between command timeout and assertion timeout in Cypress. It verifies that a button becomes visible within the command timeout and that its text matches the expected value within the assertion timeout.

Test Code - Cypress
Cypress
describe('Command timeout vs assertion timeout demo', () => {
  it('waits for button visibility and text assertion with different timeouts', () => {
    cy.visit('https://example.cypress.io/commands/waiting')

    // Command timeout: wait up to 5 seconds for button to be visible
    cy.get('.wait-btn', { timeout: 5000 }).should('be.visible')

    // Assertion timeout: retry assertion for up to 7 seconds
    cy.get('.wait-btn').should('have.text', 'Button appears after 3 seconds', { timeout: 7000 })
  })
})
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsCypress test runner initialized-PASS
2Browser opens and navigates to 'https://example.cypress.io/commands/waiting'Page loads with waiting buttons section-PASS
3Find element with selector '.wait-btn' with command timeout 5000msButton not visible initially, appears after 3 secondsCheck element is visiblePASS
4Assert that element '.wait-btn' has text 'Button appears after 3 seconds' with assertion timeout 7000msButton text updates after it appearsVerify button text matches expected stringPASS
5Test ends successfullyAll assertions passed-PASS
Failure Scenario
Failing Condition: Button does not become visible within 5 seconds or text does not match within 7 seconds
Execution Trace Quiz - 3 Questions
Test your understanding
What does the command timeout control in this Cypress test?
AHow long Cypress waits for the assertion to pass
BHow long Cypress waits to find the element before failing
CHow long the test runner waits before starting
DHow long the browser stays open after the test
Key Result
Use command timeout to control how long Cypress waits to find elements, and assertion timeout to control how long it retries assertions. Setting appropriate timeouts helps tests be reliable and fast.