wait | Cypress Documentation (2025)

Wait for a number of milliseconds or wait for an aliased resource to resolvebefore moving on to the next command.

Syntax

cy.wait(time)
cy.wait(alias)
cy.wait(aliases)
cy.wait(time, options)
cy.wait(alias, options)
cy.wait(aliases, options)

Usage

Correct Usage

cy.wait(500)
cy.wait('@getProfile')

Arguments

time (Number)

The amount of time to wait in milliseconds.

alias (String)

An aliased route as defined using the .as() command andreferenced with the @ character and the name of the alias.

info

Core Concept

You can read more about aliasing routes in our Core Concept Guide.

aliases (Array)

An array of aliased routes as defined using the .as()command and referenced with the @ character and the name of the alias.

options (Object)

Pass in an options object to change the default behavior of cy.wait().

OptionDefaultDescription
logtrueDisplays the command in the Command log
timeoutrequestTimeout, responseTimeoutTime to wait for cy.wait() to resolve before timing out
requestTimeoutrequestTimeoutOverrides the global requestTimeout for this request. Defaults to timeout.
responseTimeoutresponseTimeoutOverrides the global responseTimeout for this request. Defaults to timeout.

Yields

When given a time argument:

  • cy.wait() yields the same subject it was given.
  • It is unsafeto chain further commands that rely on the subject after .wait().

When given an alias argument:

  • cy.wait() 'yields an object containing the HTTP request and responseproperties of the request.

Examples

Time

Wait for an arbitrary period of milliseconds:

cy.wait(2000) // wait for 2 seconds

caution

Anti-Pattern

You almost never need to wait for an arbitrary period of time. There arealways better ways to express this in Cypress.

Read aboutbest practices here.

Additionally, it is often much easier to use cy.debug()or cy.pause() when debugging your test code.

Alias

For a detailed explanation of aliasing,read more about waiting on routes here.

Wait for a specific request to respond

  • End-to-End Test
  • Component Test
// Wait for the alias 'getAccount' to respond
// without changing or stubbing its response
cy.intercept('/accounts/*').as('getAccount')
cy.visit('/accounts/123')
cy.wait('@getAccount').then((interception) => {
// we can now access the low level interception
// that contains the request body,
// response body, status, etc
})

Wait automatically increments responses

Each time we use cy.wait() for an alias, Cypress waits for the next nthmatching request.

// stub an empty response to requests for books
cy.intercept('GET', '/books', []).as('getBooks')
cy.get('#search').type('Peter Pan')

// wait for the first response to finish
cy.wait('@getBooks')

// the results should be empty because we
// responded with an empty array first
cy.get('#book-results').should('be.empty')

// now the request (aliased again as `getBooks`) will return one book
cy.intercept('GET', '/books', [{ name: 'Peter Pan' }]).as('getBooks')

cy.get('#search').type('Peter Pan')

// when we wait for 'getBooks' again, Cypress will
// automatically know to wait for the 2nd response
cy.wait('@getBooks')

// we responded with one book the second time
cy.get('#book-results').should('have.length', 1)

Aliases

You can pass an array of aliases that will be waited on before resolving.

When passing an array of aliases to cy.wait(), Cypress will wait for allrequests to complete within the given requestTimeout and responseTimeout.

  • End-to-End Test
  • Component Test
cy.intercept('/users/*').as('getUsers')
cy.intercept('/activities/*').as('getActivities')
cy.intercept('/comments/*').as('getComments')
cy.visit('/dashboard')

cy.wait(['@getUsers', '@getActivities', '@getComments']).then(
(interceptions) => {
// interceptions will now be an array of matching requests
// interceptions[0] <-- getUsers
// interceptions[1] <-- getActivities
// interceptions[2] <-- getComments
}
)

Using .spread() to spread the array into multiple arguments.

cy.intercept('/users/*').as('getUsers')
cy.intercept('/activities/*').as('getActivities')
cy.intercept('/comments/*').as('getComments')
cy.wait(['@getUsers', '@getActivities', '@getComments']).spread(
(getUsers, getActivities, getComments) => {
// each interception is now an individual argument
}
)

Notes

Nesting

Cypress automatically waits for the network call to complete before proceedingto the next command.

// Anti-pattern: placing Cypress commands inside .then callbacks
cy.wait('@alias')
.then(() => {
cy.get(...)
})

// Recommended practice: write Cypress commands serially
cy.wait('@alias')
cy.get(...)

// Example: assert status from cy.intercept() before proceeding
cy.wait('@alias').its('response.statusCode').should('eq', 200)
cy.get(...)

ReadGuide: Introduction to Cypress

Timeouts

requestTimeout and responseTimeout

When used with an alias, cy.wait() goes through two separate "waiting"periods.

The first period waits for a matching request to leave the browser. Thisduration is configured by therequestTimeout option - which hasa default of 5000 ms.

This means that when you begin waiting for an aliased request, Cypress will waitup to 5 seconds for a matching request to be created. If no matching request isfound, you will get an error message that looks like this:

wait | Cypress Documentation (1)

Once Cypress detects that a matching request has begun its request, it thenswitches over to the 2nd waiting period. This duration is configured by theresponseTimeout option - whichhas a default of 30000 ms.

This means Cypress will now wait up to 30 seconds for the external server torespond to this request. If no response is detected, you will get an errormessage that looks like this:

wait | Cypress Documentation (2)

This gives you the best of both worlds - a fast error feedback loop whenrequests never go out and a much longer duration for the actual externalresponse.

Using an Array of Aliases

When passing an array of aliases to cy.wait(), Cypress will wait for allrequests to complete within the given requestTimeout and responseTimeout.

Rules

Requirements

  • When passed a time argument cy.wait() can be chained off of cy or offanother command.
  • When passed an alias argument cy.wait() requires being chained off ofcy.

Assertions

  • cy.wait() will only run assertions you have chained once, and will notretry.

Timeouts

  • cy.wait() can time out waiting for the request to go out.
  • cy.wait() can time out waiting for the response to return.

Command Log

Wait for the PUT to users to resolve.

cy.intercept('PUT', /users/, {}).as('userPut')
cy.get('form').submit()
cy.wait('@userPut').its('request.url').should('include', 'users')

The cy.wait() will display in the Command Log as:

wait | Cypress Documentation (3)

When clicking on wait within the command log, the console outputs thefollowing:

wait | Cypress Documentation (4)

History

VersionChanges
3.1.3Added requestTimeout and responseTimeout option
< 0.3.3cy.wait() command added

See also

  • .as()
  • cy.intercept()
  • .spread()
wait | Cypress Documentation (2025)

FAQs

What to use instead of cy wait? ›

Instead of relying on cy. wait(TIME) , it's better to use cy. get() with assertions that automatically retry until the presence of specific DOM elements signals the page has loaded. These assertions can be chained to keep retrying until certain conditions are met.

How to avoid waits in Cypress? ›

The best way to handle these waits is to wait on aliases. Anything that can be aliased can be waited upon, like elements, intercepts, requests, etc. Let's take a look at an example of what this looks like in practice. describe("User Sign-up and Login", () => { beforeEach(() => { cy.

How long should Cypress wait? ›

By default, Cypress waits for up to 30 seconds for a response.

How to wait for response in Cypress? ›

You can pass an array of aliases that will be waited on before resolving. ​ When passing an array of aliases to cy. wait() , Cypress will wait for all requests to complete within the given requestTimeout and responseTimeout .

What can I use instead of wait? ›

Synonyms and examples
  • wait for. We're waiting for the bus.
  • await. formal. ...
  • stay. Stay there until I get back.
  • remain. formal. ...
  • hang on. Hang on, I'll be ready in a minute.
  • hang around. informal. ...
  • loiter. A bunch of men were loitering outside the pub.
  • line up. People were lining up for tickets.
Aug 14, 2024

What is the alternative to implicit wait? ›

Use explicit wait instead of implicit wait: Implicit waits can cause our tests to take longer than necessary to fail if the element cannot be located. Explicit and fluent waits are better because they allow us to wait for a specific condition to occur before proceeding further.

How do I make Cypress tests faster? ›

Tips To Improve Cypress Testing
  1. Set a baseUrl: ...
  2. Use aliases in cy. ...
  3. Avoid visiting external sites while test execution. ...
  4. Avoid coupling of tests. ...
  5. Using hooks the right way. ...
  6. Incorporate Cypress into your Continuous Integration and cloud testing plan.
May 3, 2023

How to implement dynamic wait in Cypress? ›

Conditional Timeout Handling:

By utilizing timeout options in these different ways, we can effectively handle dynamic waits in Cypress tests, ensuring reliability and efficiency in our test automation process. If the element loads before the specified timeout time in Cypress, the test execution will proceed normally.

What is the default wait in Cypress? ›

Request timeout : Default Request Timeout is 5000 ms . This means that cypress by default will wait for 5000ms for a matching request to leave the browser . If no matching request is found , cypress will throw an error. Response timeout : This is the second wait period which is 30 secs by default.

How to wait until a page loads in Cypress? ›

Since cy. wait() will wait for not only the request to happen, but also the response, it can be a reliable way of making sure that your page is properly loaded. Another way of waiting for multiple requests is to use cy. get('@alias.

How to click and wait in Cypress? ›

The cy. wait() method is a command in Cypress that tells the test runner to pause and wait for a specified amount of time or until a specific condition is met. It is useful for simulating certain actions that take time to complete, such as API requests, loading data, or animations.

What does a cy wrap do? ›

cy. wrap() , when its argument is a promise, will automatically wait until the promise resolves. If the promise is rejected, cy. wrap() will fail the test.

What is stubbing in Cypress? ›

In Cypress , stubbing can be accomplished using the cy. stub() method, which creates a stubbed version of a function or method. With stubs, we can define the desired behavior, return values, or even trigger specific actions when the stubbed function is called.

What is the default wait in Cy? ›

(By default, Cypress waits 4 seconds to retrieve and verify items.)

What is the wait event in Cypress? ›

The cy. wait() method is a command in Cypress that tells the test runner to pause and wait for a specified amount of time or until a specific condition is met. It is useful for simulating certain actions that take time to complete, such as API requests, loading data, or animations.

What is explicit wait in Cypress? ›

An explicit wait, on the other hand, is a way to pause the test and wait for a specific condition to be met before moving on to the next action. You can use the cy. wait() command with a condition argument to create an explicit wait. For example, you can use cy.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Arielle Torp

Last Updated:

Views: 5947

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.