0
0
Cypresstesting~20 mins

Waiting for requests (cy.wait with alias) in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cypress Wait Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
});
A200
Bundefined
C404
D500
Attempts:
2 left
💡 Hint
The intercept simulates a successful GET request to '/api/user'.
assertion
intermediate
2: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?
Acy.get('@fetchData').should('have.property', 'response.body.success', true);
Bcy.wait('@fetchData').should('have.property', 'success', true);
Ccy.wait('@fetchData').its('response.body.success').should('eq', true);
Dcy.wait('@fetchData').then(({ response }) => expect(response.body.success).to.be.true);
Attempts:
2 left
💡 Hint
Use cy.wait with its to access nested properties.
🔧 Debug
advanced
2: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');
AThe POST request happens before the intercept is set up.
BThe button click does not trigger the POST request.
CThe alias '@postData' is misspelled in cy.wait.
Dcy.wait cannot be used with POST requests.
Attempts:
2 left
💡 Hint
Check if the user action triggers the network request.
🧠 Conceptual
advanced
2: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?
AIt retries the request automatically if it fails.
BIt pauses the test for a fixed time to avoid race conditions.
CIt disables all other network requests during the wait.
DIt waits exactly for the network request to finish, making tests more reliable and faster.
Attempts:
2 left
💡 Hint
Think about waiting for real events vs fixed delays.
framework
expert
3: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?
Acy.wait(['@getUser', '@getPosts', '@getComments']);
Bcy.wait('@getUser'); cy.wait('@getPosts'); cy.wait('@getComments');
CPromise.all([cy.wait('@getUser'), cy.wait('@getPosts'), cy.wait('@getComments')]);
Dcy.wait('@getUser && @getPosts && @getComments');
Attempts:
2 left
💡 Hint
Check Cypress docs for waiting on multiple aliases at once.