cypress: cy.wait() always gives a timeout error: No request ever occurred.

Current behavior:

I am just following he tutorial at your site and there is a part when cy.wait('@alias') is shown.

On the video it worked fine, However I always getting an error

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

I have tried it both in my project and in your completed tutorial project The error is present in both cases.

Here is an image Request is going

When I don’t use cy.wait() it seems to work fine

Can you help me with this please?

Desired behavior:

cy.wait should for the request to resolve

Versions

“cypress”: “3.1.5”, Google Chrome Version 71.0.3578.98

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 34
  • Comments: 148 (18 by maintainers)

Commits related to this issue

Most upvoted comments

meeting this error, too… Is there any solution?

Unfortunately we have to close this issue as there is not enough information to reproduce the problem.

Please comment in this issue with a reproducible example and we will reopen the issue. 🙏

I had the same issue but solved it by moving cy.server(); and cy.route(...); before cy.visit().

Unfortunately we’ll have to close this issue if no reproducible example is provided. Can anyone provide a way to reproduce this?

@macarenagil No one ever produced a reproducible example that the Cypress team could run to recreate this, so this issue was closed.

Some advice if your cy.wait() is not resolving.

  • Make sure cy.server() and cy.route() are defined BEFORE you cy.visit() or BEFORE you do the action that will cause the route to go out.
  • Are you waiting for a FETCH response? We don’t fully support this yet. https://github.com/cypress-io/cypress/issues/95
  • Make sure to defined the method on the cy.route() if needed, it automatically only listens for GET requests by default.

I had a similar issue where XHR requests were never made. Solved this using this in my tests/cypress/support/index.js. Worked for me ever since.

// Hack to always bind cy.server() to bind to webAppWindow
Cypress.on('window:load', (window) => {
	// Get webApp iframe
	const docIframe = window.parent.document.getElementById("Your App: 'cypress'");
	const webAppWindow = docIframe.contentWindow;

	// Get current cypress server thats started
	const server = Cypress.state().server;
	if (server) {
		// bind server to our webApp window
		server.bindTo(webAppWindow);
	}
});

This is getting really frustrating for us. We do not receive this error every time and actually only when running the tests in docker. We use drone.io for our CI and the official cypress-docker-image (cypress/included:4.0.1). All our tests start with visiting the page and cy.wait()-ing for our translation file to be loaded. Locally the tests run fine, in the CI they fail randomly.

To solve this, I add cy.wait(500) after cy.visit() and before cy.wait(xhr..).

I tried this as well, test stability went up a little bit, but I still have failing tests.

Someone test it with Cypress 4.0.X?

Just upgraded yesterday. Does not make a difference.

I cannot understand how this attracts so little attention by the team. For us this currently makes cypress useless, as test-results are completely inconsistent.

Still happening on 6.4.0 and its apretty big issue. Requests are randomly not being intercepted. Ive tried with a full url, with **/path etc etc, no difference.

Please take a look

Good day. Wanted to ask if there is any status on this issue?

I just ran into this error, and this comment was the clue. I wasn’t specifying the request method POST. I was under the assumption it matched any method to the url. That was the core of my problem.

Without a method: image

With the method: image

Having the same problem here, using cy.intercept(...).as('test') and cy.wait('@test'), the wait sometimes fails with a timeout.

If it helps debugging, I can reproduce it reliably in Cypress Chrome browser window: Devtools -> Performance -> Gear Icon -> CPU: “6x slowdown”. Then reload the test and it fails every time.

So there seems to be a race condition, where on slow machines the request is already sent before the cy.wait is executed.

I’m also getting this. My use case seems basic? I have a button that submits a form, I want to wait for that submit request to finish before doing further actions.

cy.intercept({
      method: 'POST',
      url: '/user/login'
    }).as('login');
    cy.get('input[type="submit"]').click()
    cy.wait('@login')

Cypress understands the route, but the response is recorded before the wait is called, so it never catches it. This seems like a race condition to me.

image

i am not able to get a Code Sandbox using Cypress up and running (keep getting cy is not defined)

i am trying to simply spy on a request i am making manually from the spec file, but this example using the docs for Network Requests fails on my local machine inside a basic Angular app:

// test.spec.js

describe('basic test', () => {
  it('should hit the API', () => {
    const url = 'https://openlibrary.org/works/OL45883W.json';

    cy.intercept({
      method: 'GET',
      url,
    }).as('getBook');

    cy.request({
      method: 'GET',
      url,
    });

    cy.wait('@getBook').then((interception) => {
      console.log(interception);
    });
  });
});

request response status is 200 as expected

error:

Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: getBook. No request ever occurred.Learn more

i see a ton of recommendations to use cy.server() then cy.route() but i also see that these are both deprecated.

We recognize that this is very frustrating, especially since Cypress strongly advocates using cy.wait() for routes as a best practice. We very much want to fix this.

That being said, we regularly read the comments and we’ve re-reviewed all of the comments in this thread and there has not been a single reproducible example given. Without this, we have no path forward with identifying the cause of this issue and fixing the issue.

We use Cypress ourselves to test all of our products, every piece of the Test Runner, the Dashboard, and over 30 example repos. Since Cypress can be used to test everything on the internet, there are infinite variables that could contribute to a specific bug. We have not encountered this issue ourselves, so there is likely something outside of our usage that affects when this happens.

Please provide a reproducible example

Having a reproducible example is vital for us when narrowing down the cause of an issue among the infinite contributing variables available.

We really want to address this issue. To do that, we need a fully reproducible example provided that we can run on our machines.

If you have a reproducible example that you cannot share publicly, you’re welcome to email us at support@cypress.io to share privately.

Related Issues

There are a couple of other issues I’d like to note as reproducible bugs around cy.wait() never resolving. If you see your issue fits within one of these, please refer to the respective issue:

General tips for cy.wait()

There have been some cases mentioned in this thread where the issue was solvable by rewriting how the tests were written.

We definitely see room for improvement here in our documentation and our API in general. We understand this can be frustrating and we believe it’s our responsibility to help when a concept is commonly misunderstood in our product. We are working on improving the APIs around network requests overall here. https://github.com/cypress-io/cypress/pull/4176

  • Make sure cy.server() and cy.route() are defined BEFORE you cy.visit() or BEFORE you do the action that will cause the XHR request to go out.
  • Are you waiting for a FETCH response? We don’t fully support this yet https://github.com/cypress-io/cypress/issues/95 There are workarounds and an experimental fetch polyfill in v4.9.0
  • Make sure to define the method on the cy.route() if needed. cy.wait() automatically only listens for GET requests by default.
  • Double check the route’s URL glob, that it will match the request you are waiting for. We use minimatch under the hood so you can check using Cypress.minimatch()
  • If you have any custom overriding code for requests or mix async code in with Cypress commands, make sure there is not an async issue that could introduce variability in your timings when waiting for responses. https://github.com/cypress-io/cypress/issues/7207

@JessicaSachs just to reiterate point of @Saibamen but from a slightly different angle. This is a serious bug 😃

Right now, no one operating at this level(ie software architect) is going to reproduce issue. So, given current situation this will remain a bug. @JessicaSachs any idea how given the dynamic, we can get someone to spend time to reproduce bug?

^ in short the issue is that when stubbing a url like ‘v1/users**’ and that request happens two or more times in succession, and you wait for aforementioned url twice one after another, then it will skip the 2nd periodically causing the entire test to fail. The weird part about it, is that it’s sporadic. I was once doing this with 4 of them. Sometimes would be 2nd that would fail, sometimes the 3rd, sometimes the 4th, until I just created absolute urls for each without stubbing. I though for real should go to be now. It’s 1:50am in the JLM

if you are using fetch this shoud work:

// use `Cypress` instead of `cy` so this persists across all tests
Cypress.on("window:before:load", win => {
  win.fetch = null;
});

Link: https://github.com/cypress-io/cypress/issues/95#issuecomment-347607198

i have the same issue, i can’t believe how this issue still hasn’t got the attention it needs… locally it works perfectly fine, but in CI it fails randomly… any updates here??

Hello, I have the same issue and I solved by using full API URL example:

cy.server()
cy.route({
  method: 'GET',
  url: `https://myapi.com/user/profile` // or use env variable via `${Cypress.env('BASE_API')/user/profile}`
}).as('userProfile')

cy.visit(Cypress.env('HOST'))
cy.wait('@userProfile')

Hope this helps.

Meanwhile as I understand the issue still exists, wanted to share with a nice package which may be a workaround: cypress-wait-until

It’s weird but error happened with syntax like cy.route('POST', 'url') While in syntax like

cy.({
method: ....
})

Its gone.

Requests made from the spec file using cy.request are NOT intercepted by cy.route. Only the requests made by the application are intercepted

Sent from my iPhone

On Aug 6, 2020, at 17:19, Rene Roger notifications@github.com wrote:

Hello, I am also stuck with the same problem. I’ve read several posts about it and tried many different solutions, none worked.

What am I missing here? Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

LinkedIn post made here that expresses how I feel, and that hopes to bring more visibility to this issue: https://www.linkedin.com/posts/charliegreenman_cywait-always-gives-a-timeout-error-no-activity-6679349210942369792-Zxv5

thank you

I would love to give you a 100% reproductible error. But this happens to me only when I run all of the project tests. It happens on 2 tests over 103 now. It does not fail when it runs within the suite. Since I can’t give the 103 tests and access to our application, even if I could isolate a test, you would say that there is nothing wrong with it. Which is true, unless circumstances…

One thing to note is that it was happening to one other test. I refactored the code and the test for a feature. Since, the test succeed all the time. The xhr scheme is totally different and seem to be more compliant to what cypress is expecting. But still, I don’t understand in what way.

Hello,

I’m facing the same issue with latest Cypress version. Basically put, there seems to be an inconsistency with the XHR loading wait, in a sense that XHRs are loaded, afterwards the test waits for XHRs to load=> timeout. This does not happen all the time, but rather once every 3-4 cycles, case when waiting after XHRs are fired. Relevant screenshots: Screenshot_5 Screenshot_6

When I am running single spec file , then this works fine ( All cases passed which consists @wait). But when I run multiple specs file , then @wait starts failing for 2 test cases where wait is used…

CypressError: Timed out retrying: cy.wait() timed out waiting 30000ms for the 1st request to the route: ‘example’. No request ever occurred.

cy.route(
  "PUT",
  `/proxy/example`
).as("saveDrawer");
cy.get(selectors.saveDrawer).click();
cy.wait("@saveDrawer")
  .its("status")
  .should("eq", 200);

I have the same problem : cy.server() cy.route('http://192.168.0.209/saas/**').as('school') cy.wait('@school').then() image

The definitive solution. If this does not work, there may be an error in your GET service. ` cy.server(); cy.route({ URL: “URL…”, method: “GET” }).as(“tickets_count”);

  cy.visit("http://localhost:5000/dashboard");

  cy.wait('@tickets_count');

  cy.get('@tickets_count').then(function (xhr) {
    console.log("xhr: ", xhr);
  });

`

@jennifer-shehane is that it? I’m taking this to LinkedIn and I’m suggesting people not use Cypress. It’s a sham, everyone suggesting it and it doesn’t even work. So upset right now, especially with the burden being put on the community to produce examples. I can assure you, if I would have stuck with protractor I would be having a better time and getting these tests out quicker

@jennifer-shehane thank you for jotting this down, you obviously put in time and effort. Just curious, what incentive would I have to create a reproducible example?

@CharlieGreenman we have two upcoming releases that may address this problem but we need a reproducible example to be certain.

If you are 100% blocked on this issue, please create a reproducible example in a repo to show us what scenario is failing. With a reproduction, we can confidently triage and fix this issue.

@JessicaSachs trying to think through how I can do this. To reiterate point made on Twitter. Proprietary and internal apis, but I can potentially use open qsource apis to get this going. To be honest it’s probably going to take 1.5 hours of my time. I will not get paid for this work, so realistically, being that not 100% blocked, I am not going to work on it. If cypress would like to accommodate me for time spent recreating bug, charlie@razroo.com would be the right place to send something.

(Creating an extra 10 network requests that might break, due to somewhat fragile nature of write down complete, url, yes.) Oy! Software is rough sometimes

I was so upset this wasn’t solved yet, and unable to use while using globs that I sent a tweet over here: https://twitter.com/char_greenman/status/1273282685797126146?s=21

Should note, manpower isn’t the issue: https://www.crunchbase.com/organization/cypress-io#section-overview

^ this bug should be your number 1 priority

Hello

That not works for me And I confirm the server receive the request and send response

  it('clicks on "Recevoir mon devis"', () => {
      cy.server();
      cy.route('POST', `http://localhost:9030/api/public/website/checkout-quote`).as('order')
      cy.contains('Get my quote').click()
      cy.wait('@order').then((xhr) => {
          console.log(xhr)
      })
        .its('status')
        .should('eq', 200)
  })

Screenshot 2019-11-17 22:16:22

Hi, I’m facing the same issue using Cypress 6.4.0.

Trying to catch XHR Post request with the following error:

CypressError: Timed out retrying after 9000ms: cy.wait() timed out waiting 9000ms for the 1st request to the route: saveTtg. No request ever occurred.

Here is a snippet from my code:

      cy.intercept({ method: 'POST', url: 'https://services.myapi.com/core/v3/contents/FFfcokzPbnddil/targets' }).as('saveTtg');

      cy.get('input#ttgName').clear().type('ttg sample');
      cy.get('button.btn-round-check').as('btnGreenCheck').should('be.visible').should('not.be.disabled');
      // Button to click for post request to launch:
      cy.get('@btnGreenCheck').click();

      cy.wait('@saveTtg', { timeout: 9000 }).then((xhr) => {
        console.log(xhr);
        assert.equals(xhr.response.statusCode, 200);
      });

As you see I tried adding a timeout without success, also tried the url as: ‘**/core/v1/contents/FFfcokzPbnddil/targets’ but my app is not the same baseurl as api.

Any tip appreciated

I have managed to find out that cy.wait timed out when happends “(new url)” events. My project has logic that changes url (history replaceState) after click on a button. Also click triggers a POST request. If i comment replaceState logic - POST request succesfully captures. If not cypress logs (new url) and not captures that request

@jianjiming looks like you struggling the same “change location” issue

Got some time to investigate, at least a few hours.

I tried to upgrade to the 5.2.0 version. The problem still occurs. Reading the comment of @rezres I tried commenting the interceptors. No change at all.

It still happens “randomly” when running multiple tests sequentially. It does not happen if there is only one xhr sent and waited at a time. It can happen if there is multiple xhr but only one wait. It can happens when waiting multiple times for the same xhr ( cy.wait([q1,q2,q3]) ).

I can’t find anything to be sure to reproduce. I can’t find anything that the application is doing and is messing with cypress xhr listeners.

Not sure if the error I’m getting is the same as OP (in which case, let me know and I’ll create a separate issue), but the error message itself is the same, so they might be the same issue.

If I try to stub a request and give it a String response, any cy.wait on that route will simply time out. If the stubbed response happens to be an Object, or Array, as the API documents those are the other two possible types, cy.wait will pick up the request just fine.

To note, the request is being stubbed correctly, even when using a String. I can see this from the Routes section in the log, since it has a column listing the amount of calls for a given route. It’s just cy.wait not picking up on it for some reason. Here an image of this:

ad7c39fa-a617-4a52-bbc9-1ca3f357907d

Here reproducible code as of v4.12.1:

it('cy.wait times out when response is a simple string', () => {
  cy.visit('https://zooplus.de/shop/katzen/katzenfutter_trockenfutter/purizon');

  cy.server();

  cy.route({
    method: 'PATCH',
    url: '/checkout/api/cart-api/v1/cart/*/set-article-quantity-command',
    status: 403,
    response: 'just a string',
  }).as('addToCart');

  cy.get('a[data-zta^="addtocartbtn_"]').first().click();

  cy.wait('@addToCart', { timeout: 10000 }).then((xhr) => {
    const data = {
      status: xhr.status,
      body: xhr.response.body,
    };
    cy.log(JSON.stringify(data));
  });
});

I haven’t been able to test this yet (only tested with stubbed responses), but I believe any request, stubbed or not, that happens to return just a string (so not something that might be a JSON, like an array or object response), will cause cy.wait to time out.

Just got done dealing with the exact issues above. I solved it by following the guidance of cy.server() and cy.route() first, followed by cy.wait(). Also, the key fix which I only see in https://docs.cypress.io/api/commands/route.html#Examples but is completely missing from https://docs.cypress.io/guides/guides/network-requests.html#Waiting is the idea of url globs. I suspect many others were doing what I did by following the network-requests doc and listening to url: ‘/api/*’ or something like that. instead do url: ‘/api/**’. The double star made everything work perfectly. hope this helps somebody else.

@ArshadIram I’m not sure I get what you mean, but I’ll try to answer as detailed as I can. So @firstUrl is obviously for a POST request, while both @secondUrl and @thirdUrl are GET requests. The one url request which is flaky is the @thirdUrl, and I can comment the @secondUrl before that, but it doesn’t change the flakiness of @thirdUrl. I cannot comment the first one because this is the request that eventually leads to the other two requests.

Getting this issue randomly as well. In the recording I noticed that it immediately fails, even if it claims that it timed out after 5000ms 🤷 Note: I only get this in CI, can’t reproduce locally

I was also facing the error but I fixed it. by default cy.route showing Get method and if you have post method API and will not explicity metion post then you will get this error message.

Here is the syntax for post API routes:

cy.route('POST',"Your API post URL").as("alice")

Note: Make sure that route is work as a listener you must have to define it before performing the action and then you will use it as wait.

Much like others I’m getting nailed by this same issue where cy.wait(aliases) triggers a timeout by random. Hopefully we can land a fix here soon

Hello, I have the same issue and I solved by using full API URL example:

cy.server()
cy.route({
  method: 'GET',
  url: `https://myapi.com/user/profile` // or use env variable via `${Cypress.env('BASE_API')/user/profile}`
}).as('userProfile')

cy.visit(Cypress.env('HOST'))
cy.wait('@userProfile')

Hope this helps.

Same. Was getting the error while the request was being made. As soon as I used the full URL it worked…

After months I hoped it would be fixed. Why is this still open? :\

Maybe this one helps somebody else but I encountered similar issue when waiting for a GET request. The test looked something along the lines:

  it('should request list', () => {
    cy.server().route('GET', '**/list').as('getList');
    requestList(); // this one fires '/list' API request
    // wait for API request to finish
    cy.wait('@getList').its('status').should('be', 200);
  });

This one always timeouted. The problem was that API request to GET /list was sent with query params, for example ?userId=1&category=10. As soon as I changed route definition as follows:

cy.server().route('GET', '**/list?**').as('getList'); <- do not overlook this part ?** in url

timeouts vanished and everything worked like a charm. So the outcome is if you are listening to GET request with query params include the ?** part at the end of the route URL.

Hi! I’ve got the same issue with cy.wait(@alias). Tried a lot of ideas, but nothing.

  1. The main problem, fot GET request - it’s ok more or less. for POST - trouble 😦 2)I’ve got XHR responses : Screen Shot 2019-09-04 at 11 46 39
  2. in my test: Screen Shot 2019-09-04 at 11 56 35

This POST request responses authtoken and redirectURL, which one I wanna use after in cy.visit.

But my test failed at step cy.wait Screen Shot 2019-09-04 at 11 52 32

What is wrong?

Good day. Having same issue. As I have noticed it seem to be with GET method requests. Could you please direct me if I’m doing it somehow wrongly?

Screenshot: image

Test:

describe('Test wait issue', function() {

    const XHRTimeOut = 1000; //1 sec

    beforeEach(function () {
        cy.server({ urlMatchingOptions: { matchBase: false, dot: true } });
        cy.route({method: "GET", url: '**/complete/search**'}).as('apiCall');
    });

    afterEach(function () {});

    it('Wait issue test', function () {
        cy.visit('https://www.google.com/');
        cy.wait(Array(1).fill('@apiCall'), {timeout: XHRTimeOut});
    });

});

@jennifer-shehane my colleagues are seeing this as well. any updates here?