cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.07k stars 3.19k forks source link

.wait() behaving inconsistently - does not always see that XHR calls completed #7447

Closed kyrstenkelly closed 4 years ago

kyrstenkelly commented 4 years ago

Current behavior:

When I am running my tests, about half the time Cypress does not see that the XHR requests I have told it to wait for have completed successfully. I can rerun the test many times and it works only about half the time.

Here is a screenshot of the test timing out because No response ever occurred, even though you can see in the Cypress logs that more than 4 graphl XHR calls successfully returned w/ a 200:

Screen Shot 2020-05-21 at 5 06 59 PM

And I then re-ran the test, and got this.....same XHR calls, all successful, but this time the wait finished properly:

Screen Shot 2020-05-21 at 5 08 09 PM

Desired behavior:

Consistent test behavior. It seems like maybe cy.wait(...) is not seeing that the XHR requests finish if they happen too fast?

Test code to reproduce

This can easily be reproduced if you don't mind creating a Udacity account.

  1. See my test code here: https://github.com/kyrstenkelly/cypress-test-tiny
  2. Create a Udacity account (it's free!)
  3. Find your _jwt cookie, and paste that into the test where cypress sets a cookie
  4. Run the tests repeatedly. Sometimes they pass, sometimes they don't.

Here is an overview of the code.

I have read through so many issues and as far as I can tell, from a code perspective I am doing things correctly. I am starting the server & setting up routes before using cypress.visit(). If I am setting this up incorrectly, please let me know.

describe('Our website', () => {
  beforeEach(() => {
    cy.setCookie('_jwt', '< add your JWT here >');

    cy.server();
    cy.route({
      url: '**/graphql',
      method: 'POST' 
    }).as('apiRoute');
  });

  it(`Has no accessibility violations`, () => {
    cy.visit('https://classroom.udacity.com/me');

    // Also try waiting for the requests one at a time - but neither seems to work
    // cy.wait('@apiRoute');
    // cy.wait('@apiRoute');
    // cy.wait('@apiRoute');
    // cy.wait('@apiRoute');
    cy.wait(['@apiRoute', '@apiRoute', '@apiRoute', '@apiRoute']);

    expect(true);
  });
});

Versions

Cypress: 4.6.0 System: mac OS 10.14 Browser: Electron 80 (when headless) or Chrome 83 in the GUI

jennifer-shehane commented 4 years ago

This is something we've seen with GraphQL requests before unfortunately. Duplicate of #5999

evba1 commented 4 years ago

I have the same issue with xhr requests