0
0
Cypresstesting~5 mins

Waiting for requests (cy.wait with alias) in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does cy.wait('@alias') do in Cypress?
It waits for a network request that was aliased earlier to complete before continuing the test. This helps ensure the app has received the response before assertions run.
Click to reveal answer
beginner
How do you create an alias for a network request in Cypress?
Use cy.intercept() with .as('aliasName'). For example: cy.intercept('GET', '/api/data').as('getData').
Click to reveal answer
intermediate
Why is using cy.wait() with aliases better than using fixed cy.wait() times?
Because it waits exactly for the network request to finish, making tests faster and more reliable than waiting a fixed time which might be too short or too long.
Click to reveal answer
intermediate
What happens if the aliased request does not complete within the default timeout when using cy.wait('@alias')?
The test will fail with a timeout error, indicating the request did not finish in time. You can adjust the timeout if needed.
Click to reveal answer
intermediate
Can you wait for multiple requests using cy.wait() with aliases?
Yes, you can pass an array of aliases like cy.wait(['@req1', '@req2']) to wait for all specified requests to complete.
Click to reveal answer
What is the correct way to alias a GET request to '/users' in Cypress?
Acy.wait('GET', '/users').as('getUsers')
Bcy.route('GET', '/users').alias('getUsers')
Ccy.intercept('GET', '/users').as('getUsers')
Dcy.get('/users').as('getUsers')
What does cy.wait('@getUsers') do?
AWaits for the aliased network request 'getUsers' to finish
BWaits for 5 seconds
CStarts the network request 'getUsers'
DCancels the network request 'getUsers'
If a request takes longer than the default timeout, what happens when using cy.wait('@alias')?
ARequest is retried automatically
BTest continues immediately
CTest pauses indefinitely
DTest fails with a timeout error
How can you wait for multiple requests at once in Cypress?
Acy.wait(['@req1', '@req2'])
Bcy.wait('@req1 && @req2')
Ccy.wait('@req1').wait('@req2')
Dcy.wait('@req1 || @req2')
Why is using cy.wait() with aliases preferred over fixed time waits?
AIt waits longer than fixed times
BIt waits exactly for the request, making tests faster and more reliable
CIt skips the request
DIt makes tests slower
Explain how to use cy.intercept() and cy.wait() together to wait for a network request in Cypress.
Think about how to catch and wait for a request before checking results.
You got /3 concepts.
    Describe why waiting for network requests with aliases improves test reliability compared to fixed time waits.
    Consider what happens if the app is slow or fast.
    You got /3 concepts.