Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for two parallel XHR requests in Cypress

Tags:

cypress

I know that it is possible to wait for multiple XHR requests on the same url as shown here. However, I would like to wait for two requests running in parallel.

cy.wait('@users')
cy.wait('@users')

When I add two waits as shown above, the second one sometimes timeouts when they finish very closely together, as it basically misses the XHR.

CypressError: Timed out retrying: cy.wait() timed out waiting 30000ms for the 1st response to the route: 'users'. No response ever occurred.

I do not like the introduction of flakiness. Is there a better way to write this that I am missing?

like image 949
Peter Pavlík Avatar asked Aug 15 '18 11:08

Peter Pavlík


1 Answers

You can wait for an array of aliases, I haven't tried it with multiple calls to the same route, but I think it should do the trick.

cy.wait(['@users', '@users'])
like image 68
Brendan Avatar answered Sep 24 '22 06:09

Brendan