Challenge - 5 Problems
Cypress Wait Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Cypress test snippet?
Consider the following Cypress test code. What will be the value of
response.status after the cy.wait('@getUser') command resolves?Cypress
cy.intercept('GET', '/api/user').as('getUser'); cy.visit('/profile'); cy.wait('@getUser').then(({ response }) => { const status = response.status; cy.wrap(status).as('statusCode'); }); cy.get('@statusCode').then(statusCode => { console.log(statusCode); });
Attempts:
2 left
💡 Hint
The intercept simulates a successful GET request to '/api/user'.
✗ Incorrect
The intercept command sets up a stub for the GET request to '/api/user' which by default returns a 200 status. The cy.wait('@getUser') waits for this request and the response status is 200.
❓ assertion
intermediate2:00remaining
Which assertion correctly waits for and verifies the response body property?
You want to wait for the API call aliased as '@fetchData' and assert that the response body has a property
success set to true. Which option correctly does this?Attempts:
2 left
💡 Hint
Use
cy.wait with its to access nested properties.✗ Incorrect
Option C correctly waits for the alias and accesses the nested property using
its, then asserts it equals true. Option C is invalid because should does not work directly on the alias object like that. Option C uses cy.get which is for DOM elements, not aliases. Option C correctly accesses response.body by destructuring the argument.🔧 Debug
advanced2:00remaining
Why does this test fail to wait for the request?
This Cypress test fails intermittently because
cy.wait('@postData') times out. What is the most likely reason?Cypress
cy.intercept('POST', '/api/data').as('postData'); cy.visit('/form'); cy.get('button[type=submit]').click(); cy.wait('@postData');
Attempts:
2 left
💡 Hint
Check if the user action triggers the network request.
✗ Incorrect
If the button click does not trigger the POST request, cy.wait('@postData') will time out waiting for a request that never happens. The intercept and alias are correctly set up before the visit, and cy.wait works with POST requests. The alias spelling is correct.
🧠 Conceptual
advanced2:00remaining
What is the main benefit of using
cy.wait with an alias in Cypress tests?Why do testers use
cy.wait('@alias') instead of arbitrary cy.wait(time) delays?Attempts:
2 left
💡 Hint
Think about waiting for real events vs fixed delays.
✗ Incorrect
Using cy.wait with an alias waits for the actual network request to complete, avoiding flaky tests caused by guessing wait times. Fixed delays can be too short or too long, making tests unreliable or slow. Cypress does not retry requests automatically with cy.wait, nor does it disable other requests.
❓ framework
expert3:00remaining
In a complex test suite, how can you wait for multiple requests with different aliases before proceeding?
You have three API calls aliased as '@getUser', '@getPosts', and '@getComments'. You want to wait for all three to finish before continuing the test. Which code snippet correctly waits for all three requests?
Attempts:
2 left
💡 Hint
Check Cypress docs for waiting on multiple aliases at once.
✗ Incorrect
Option A uses an array of aliases in cy.wait, which waits for all listed requests to complete before continuing. Option A waits sequentially but is less efficient and can cause timing issues. Option A is invalid because cy.wait returns Cypress chainables, not promises usable with Promise.all. Option A is invalid syntax.