cypress: Problem with multiple requests and route / wait
Current behavior:
I am using the alias of cy.route() and on the page there are 2 requests for the same alias. For some reason when I use the following code, it uses the data from the first request, not the second.
Desired behavior:
I would like it to use the data of the last request and not the first one.
Steps to reproduce: (app code and test code)
it("testara a selecao de precos", () => {
let priceValue: any = 1000000;
let maxValue: any = 1500000;
cy.route('POST','/v1/realestate/properties/search?token=altopedroso')
.as('postProperties')
cy.get(`input[ng-model="vm.filters['price_gte']"]`).type(priceValue)
cy.get(`input[ng-model="vm.filters['price_lte']"]`).click();
cy.wait("@postProperties")
.then((xhr) => {
let request: any = xhr.request.body;
let response: any = xhr.response.body;
response = response.body;
testClass.propTests(response.results, request.filters, response.count);
});
cy.get(`input[ng-model="vm.filters['price_lte']"]`).type(maxValue);
cy.get(`input[ng-model="vm.filters['price_gte']"]`).click();
cy.wait("@postProperties")
.then((xhr) => {
let request: any = xhr.request.body;
let response: any = xhr.response.body;
response = response.body;
console.log('response', response)
console.log('request', request)
});
});
Versions
Cypress: 3.1.4 Chrome: 71
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 19
- Comments: 20 (2 by maintainers)
I found a solution where in you create multiple aliases for the same route
eg - cy.route(‘GET’, ‘/request’).as(‘req1’) cy.wait(‘@req1) cy.route(‘GET’, ‘/request’).as(‘req2’) cy.wait(’@req1) cy.route(‘GET’, ‘/request’).as(‘req3’) cy.wait('@req1)
On Wed, Nov 13, 2019 at 7:12 PM Daniel notifications@github.com wrote:
any chance on update here? I’m approaching the same issue in which it’s impossible to rename alias, all post are running at the same time so for
*2it fails.This works for me
I ran into a similar situation today, but all I did was…
This is the closest doc I could find about it https://docs.cypress.io/api/commands/wait.html#Nesting
I guess, in the original issue description, I would make this line return a promise.
Above doesn’t seem to work for glob routes:
This is a pretty nasty bug.
The workaround is to redefine the same route with a different alias and use that new alias for each new
wait:Note that this is different from @prashantabellad’s example above which uses the same alias for all the waits.