Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.wait('@getUsers') do in this test?
cy.wait() with an alias in Cypress tests?cy.wait() with aliascy.wait() command pauses the test until the network request with the given alias completes.cy.intercept() is used to spy or stub requests, and .as() assigns an alias.cy.intercept('/api/data').as('getData'), which is the correct syntax.cy.intercept('GET', '/users').as('getUsers')
cy.visit('/users')
cy.wait('@getUsers').then(({ response }) => {
console.log(response.status)
})cy.intercept() spies on the GET request to '/users' and aliases it as 'getUsers'.cy.wait('@getUsers') waits for the request to finish, then logs the response.status. A successful GET usually returns 200.cy.intercept('POST', '/login').as('loginRequest')
cy.get('button#submit').click()
cy.wait('loginRequest')cy.wait() command requires the alias to be prefixed with '@' to identify the request alias.cy.wait('loginRequest') missing the '@', which causes Cypress to not recognize the alias.cy.intercept() and alias before triggering the request by clicking the button.cy.wait('@submitRequest') after clicking to pause until the POST completes, then check page content.Pass the test and this pattern moves unknown