Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cy.route: wait on alias does not contain all requests #3516

Closed
Konstruktour opened this issue Feb 18, 2019 · 4 comments
Closed

cy.route: wait on alias does not contain all requests #3516

Konstruktour opened this issue Feb 18, 2019 · 4 comments

Comments

@Konstruktour
Copy link

Konstruktour commented Feb 18, 2019

Current behavior:

In the following code example an "listener" is added to the api/test route and after a duration of 5 seconds it waits until the route has been called. During the 5 seconds multiple (non-deterministic) calls to the route are triggered, but the alias @getTest only contains the xhr of the first request.

cy.visit('/');
cy.server();
cy.route('GET', 'api/test').as('getTest');
cy.wait(5000);
cy.wait('@getTest')
    .then((xhr) => {
        console.log(xhr);
     });

Desired behavior:

Expected behaviour would be that the alias @getTest contains an array of the fired requests.
Either I did not find any solution for that or it is not (yet) implemented?

Versions

Cypress 3.1.5

@jennifer-shehane
Copy link
Member

A single cy.wait() will only wait for a single response. To wait for multiple requests, you would need to define multiple cy.wait() commands.

In order to access all responses of a single alias, you can use the undocumented .all property. For example:

cy.wait('@getTest.all')
  .should("have.length", 2)
  .then((xhrs) => {
    console.log(xhrs);
});

@nvkhanh08t4
Copy link

A single cy.wait() will only wait for a single response. To wait for multiple requests, you would need to define multiple cy.wait() commands.

In order to access all responses of a single alias, you can use the undocumented .all property. For example:

cy.wait('@getTest.all')
  .should("have.length", 2)
  .then((xhrs) => {
    console.log(xhrs);
});

Hi @jennifer-shehane Can you give full example for this?

@jennifer-shehane
Copy link
Member

@nvkhanh08t4 Please check the docs.

@cypress-io cypress-io locked and limited conversation to collaborators Dec 24, 2019
@jennifer-shehane
Copy link
Member

Docs for the usage of .all syntax can be found here. It’s not officially documented because the API may change in the future. cypress-io/cypress-documentation#1573

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants