cy.wait() non-deterministically times out when waiting for mocked responses: No response ever occurred.
See original GitHub issueCurrent behavior:
Sometimes, cy.wait()
times out when waiting for some nth response of a mocked out endpoint, even though the Cypress UI shows that the request was stubbed out.
Desired behavior:
The documentation for cy.wait()
says:
Each time we use
cy.wait()
for an alias, Cypress waits for the next nth matching request.
It seems that this behavior should be deterministic and the nth call to cy.wait()
should find the nth response of a mocked endpoint if n responses have been successfully stubbed out.
Steps to reproduce:
- Mock out an API response, and simulate n calls using that endpoint
- Queue n
cy.wait()
calls (either by manually callingcy.wait()
n times, orcy.wait([alias, alias, ..., alias])
- This test should always pass, but sometimes the test will fail due a timeout while waiting for one of the responses
Versions
3.0.2, Mac OSX El Capitan, Chrome 67
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:12 (5 by maintainers)
Top Results From Across the Web
wait - Cypress Documentation
Wait automatically increments responses. Each time we use cy.wait() for an alias, Cypress waits for the next nth matching request. // stub an...
Read more >Cypress intercept - No request ever occurred - Stack Overflow
I am trying to validate this with cypress but it throws ' Timed out retrying after 30000ms: cy.wait() timed out waiting 30000ms for...
Read more >Waiting in Cypress and how to avoid it - Filip Hric
wait() command in Cypress and halt the test for a couple of seconds. If this applies to you as well, then you know...
Read more >How to wait for a request to finish before moving on with Cypress
ERROR: Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: file. No request ever occurred....
Read more >Pragmatic Unit Testing
system's idea of “current time” to cause events to happen that you'd have to wait around for ... calls your own getTime() and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am currently experiencing a similar issue. Random tests across our test suite fail on a cy.wait, but it only happens in our CI environment, not when running things locally. I can run the same test suite three times, and of the three two fail and one passes; of the two failing, they each fail in different test suites, but both from waiting on cy.wait commands that never returned.
My current theory is that some responses are so fast that cypress doesn’t have time to hook in. The main difference from our CI environment to our local development is that the CI environment is entirely inside docker. API server, DB, static server that serves the client, and cypress. The docker network connections may be so fast on some responses that it is missed by Cypress.
That is my going theory, at least. I don’t have time to do a minimal reproduction, but I will try to make some time in the next few days. I think setting it all up inside docker-compose should make for a reproducible demonstration of the bug.
There is a difference between manually calling
cy.wait()
n times and usingcy.wait([alias, alias, ..., alias])
Each
cy.wait()
command has a defaultrequestTimeout
of5000 ms
and a defaultresponseTimeout
of30000
. This means:Scenario 1
Scenario 2
I find the behavior in Scenario 2 to be incredibly confusing - as I myself had many response timeouts seemingly for no reason until I discovered this was the case. I’ve since changed nearly all of my
cy.wait()
to be chained, like in Scenario 1, rendering the Scenario 2 usage pretty much useless.Proposal
In order to fix this behavior, I would ideally want the timeouts to apply to each defined alias within the array individually.
@lawsumisu Please let me know if this is not the case and there is also a non-deterministic timeout when serially defining the
cy.wait()
.