Cypress: CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'aliasName'. No request ever occurred.

Created on 9 Jul 2019  路  1Comment  路  Source: cypress-io/cypress

Current behavior:

I currently have a scenairo whereby we run tests in CI mode and they fail intermittently.

I have tried to workout why but have run out of ideas for a solution

Key scenairo observations:

  1. We are hitting the same endpoint synchronously in our code
  2. These are mocked with different response types.
  3. Using wait does not work. Have removed them from the code below
  4. Even if we add some actions before the cy.wait() we still have an issue

Code below: (I have renamed endpoints)(

it("should display error if user not allowed", () => {
      cy.server();
      cy.route(
        "POST",
        "https://**/allowUser",
        "fixture:allowUser.json"
      );
      cy.visit(url);

      cy.get("#field1").type("suspended1");

      cy.get("#submit-button").click();

      cy.server({ status: 401 });
      cy.route("POST", "https://**/allowUser", "fixture:notAllowed.json").as(
        "notAllowed"
      );

      cy.get(".notAllowed").contains(
        "Not Allowed."
      );
    });

Desired behavior:

I expects tests to run and pass

Steps to reproduce: (app code and test code)

  1. Have the same endpoint which is hit one after another based on the response of the first

Versions

Cypress: 3.3.2
Headless using chrome

>All comments

If clicking the submit button is what is causing the POST XHR, then you want to define the route BEFORE you click the button like below.

      cy.server({ status: 401 });
      cy.route("POST", "https://**/allowUser", "fixture:notAllowed.json").as(
        "notAllowed"
      );
      cy.get("#submit-button").click();

Calling cy.route() is essentially setting up a listener for XHR's - so that when it finds a matching route, it will have access to it. See this comment

Was this page helpful?
0 / 5 - 0 ratings