We use cy.wait() to pause the test for a set time or until something finishes. This helps make sure the app is ready before the next step.
0
0
cy.wait() for explicit waiting in Cypress
Introduction
Waiting for a page or element to load before clicking it.
Pausing to let an animation or transition finish.
Waiting for a server response after a button click.
Delaying test steps to avoid race conditions.
Pausing to debug or observe test behavior.
Syntax
Cypress
cy.wait(timeInMilliseconds) cy.wait(alias)
You can wait for a fixed time by giving milliseconds, like cy.wait(2000) waits 2 seconds.
You can also wait for a network request by using an alias, like cy.wait('@getUsers').
Examples
Waits for 3 seconds before moving on.
Cypress
cy.wait(3000)Waits until the GET /users request finishes.
Cypress
cy.intercept('GET', '/users').as('getUsers') cy.wait('@getUsers')
Sample Program
This test opens a page, waits 2 seconds, then clicks a link and checks the URL changed.
Cypress
describe('Example of cy.wait()', () => { it('waits for 2 seconds before clicking', () => { cy.visit('https://example.cypress.io') cy.wait(2000) // wait 2 seconds cy.get('a[href="/commands/actions"]').click() cy.url().should('include', '/commands/actions') }) })
OutputSuccess
Important Notes
Use fixed waits (cy.wait(2000)) sparingly because they slow tests.
Prefer waiting for network calls or elements to appear for faster, reliable tests.
Always give meaningful aliases when waiting for requests to keep tests clear.
Summary
cy.wait() pauses tests for a set time or until a request finishes.
Use it to avoid running steps too early and causing errors.
Prefer waiting for events or requests over fixed time waits for better tests.