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)
Links to this issue
Commits related to this issue
- Move server and routes before visiting urls More info: https://github.com/cypress-io/cypress/issues/3427#issuecomment-504938130 — committed to metabase/metabase by deleted user 4 years ago
- Fix "editor-sorting-columns" Cypress error (#13323) * Move server and routes before visiting urls More info: https://github.com/cypress-io/cypress/issues/3427#issuecomment-504938130 * Wait for tabl... — committed to metabase/metabase by nemanjaglumac 4 years ago
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();andcy.route(...);beforecy.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.cy.server()andcy.route()are defined BEFORE youcy.visit()or BEFORE you do the action that will cause the route to go out.FETCHresponse? We don’t fully support this yet. https://github.com/cypress-io/cypress/issues/95cy.route()if needed, it automatically only listens forGETrequests 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.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.
I tried this as well, test stability went up a little bit, but I still have failing tests.
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:
With the method:
Having the same problem here, using
cy.intercept(...).as('test')andcy.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.waitis 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.
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.
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:
request response status is 200 as expected
error:
i see a ton of recommendations to use
cy.server()thency.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:cy.wait()does not resolve when the XHR contains static resource-like text in the XHR’s query params or hash (like.js,.html,.css) https://github.com/cypress-io/cypress/issues/7280cy.wait()times out when waiting for multiple requests from the same URL (graphql-like requests) https://github.com/cypress-io/cypress/issues/5999General 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
cy.server()andcy.route()are defined BEFORE youcy.visit()or BEFORE you do the action that will cause the XHR request to go out.FETCHresponse? 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.0cy.route()if needed.cy.wait()automatically only listens forGETrequests by default.Cypress.minimatch()@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
fetchthis shoud work: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:
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 likeIts 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
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:

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…
I have the same problem :
cy.server() cy.route('http://192.168.0.209/saas/**').as('school') cy.wait('@school').then()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”);
`
@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?
@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
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 waiting9000msfor the 1st request to the route:saveTtg. No request ever occurred.Here is a snippet from my code:
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.waiton 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.waitwill 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
Routessection in the log, since it has a column listing the amount of calls for a given route. It’s justcy.waitnot picking up on it for some reason. Here an image of this:Here reproducible code as of
v4.12.1: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.waitto 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
@firstUrlis obviously for aPOSTrequest, while both@secondUrland@thirdUrlareGETrequests. The one url request which is flaky is the@thirdUrl, and I can comment the@secondUrlbefore 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.routeshowing 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:
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
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
GETrequest. The test looked something along the lines:This one always timeouted. The problem was that API request to
GET /listwas sent with query params, for example?userId=1&category=10. As soon as I changedroutedefinition as follows:cy.server().route('GET', '**/list?**').as('getList');<- do not overlook this part?**in urltimeouts vanished and everything worked like a charm. So the outcome is if you are listening to
GETrequest 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.
This POST request responses authtoken and redirectURL, which one I wanna use after in cy.visit.
But my test failed at step cy.wait
What is wrong?
Good day. Having same issue. As I have noticed it seem to be with
GETmethod requests. Could you please direct me if I’m doing it somehow wrongly?Screenshot:
Test:
@jennifer-shehane my colleagues are seeing this as well. any updates here?