Reputation: 63
I'm wrote wait on 3 different requests on my automated test, but each time I run the test, the wait functions on one of the requests.
cy
.intercept('POST', '**/api/Availability')
.as('availabilecheck');
cy
.wait('@availabilecheck')
.its('response.statusCode')
.should('eq', 200)
////////////////////////////////////////
cy
.intercept('POST','**/api/Availability/GetPrice')
.as('getpricecheck');
cy
.wait('@getpricecheck')
.its('response.statusCode')
.should('eq', 200);
////////////////////////////
cy.intercept('POST','**/api/Member/Find')
.as('memberresponse')
cy.wait('@memberresponse')
I wrote the above code for 3 different requests but each time I run the test, one of the requests actually waits and the other 2 fails.
What should I do?
Upvotes: 6
Views: 7781
Reputation: 1370
The order of commands matters. In my case I had to move the cy.intercept()
command before the action that performed the request
//the intercept comes first
cy.intercept("POST", "**/api/user/login").as("loginResponse");
//this performs POST request in my case, comes second
cy.get('button[type="submit"]').should("not.be.disabled").click();
//thirdly comes the wait
cy.wait("@loginResponse").its("response.statusCode").should("eq", 200);
Upvotes: 2
Reputation: 1556
If the endpoints you are intercepting are not different, then Cypress will only take the first one and discard any subsequent ones. Make sure that the text that you are matching the url against is different for each request.
Upvotes: 0