Reputation: 18023
In Cypress, I have multiple requests that will match my cy.route()
declaration. I want to make sure more than one request is made on the route. How do I tell Cypress to wait for multiple XHR requests to the same url?
Upvotes: 4
Views: 9051
Reputation: 23
This works for me
cy.wait("@Request1");
cy.wait("@Request2");
cy.wait(0);
cy.wait("@Request2");
Upvotes: 0
Reputation: 2873
Another alternative is to pass in an array of aliases.
cy.wait(["@graphql", "@graphql"]);
Upvotes: 7
Reputation: 18023
From the Cypress Docs:
You should set up an alias (using .as()) to a single cy.route() that matches all of the XHRs. You can then cy.wait() on it multiple times. Cypress keeps track of how many matching XHR requests there are.
cy.server()
cy.route('users').as('getUsers')
cy.wait('@getUsers') // Wait for first GET to /users/
cy.get('#list>li').should('have.length', 10)
cy.get('#load-more-btn').click()
cy.wait('@getUsers') // Wait for second GET to /users/
cy.get('#list>li').should('have.length', 20)
Upvotes: 4