0
0
Cypresstesting~10 mins

cy.wait() for explicit waiting in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses cy.wait() to pause the test for a fixed time before clicking a button and verifying the result. It checks that the button click updates the page text as expected.

Test Code - Cypress
Cypress
describe('Explicit wait with cy.wait()', () => {
  it('waits before clicking and verifies text update', () => {
    cy.visit('https://example.cypress.io/commands/waiting')
    cy.wait(2000) // wait 2 seconds explicitly
    cy.get('.wait-btn').click()
    cy.get('.wait-message').should('contain', 'Button clicked!')
  })
})
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.cypress.io/commands/waiting'Page loads with button labeled 'Wait Button' and empty message area-PASS
3Explicitly wait for 2000 milliseconds using cy.wait(2000)Page remains unchanged, test pauses for 2 seconds-PASS
4Find element with class '.wait-btn' and click itButton is found and clicked, triggering message update-PASS
5Find element with class '.wait-message' and check it contains text 'Button clicked!'Message area now shows 'Button clicked!'Verify text content includes 'Button clicked!'PASS
Failure Scenario
Failing Condition: The button with class '.wait-btn' is not found or the message text does not update as expected
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.wait(2000) do in this test?
APauses the test for 2 seconds before continuing
BWaits for an element to appear for 2 seconds
CRetries clicking the button for 2 seconds
DWaits for the page to load completely
Key Result
Use cy.wait() only for fixed delays when necessary, but prefer waiting for elements or events to avoid flaky tests.