cypress: Page occasionally does not load from cy.visit()
Current behavior:
99+% of the time this is not an issue, but once in a while the cy.visit() at the beginning of a test will not load the page, no matter how long of a timeout I set, no XHR requests are sent, nothing is loaded in the page. This is only ever seen in cypress tests and has never been seen manually by our testers so I am sure it is a bug with Cypress.
CypressError: Timed out after waiting ‘60000ms’ for your remote page to load.
Your page did not fire its ‘load’ event within ‘60000ms’.
You can try increasing the ‘pageLoadTimeout’ value in ‘cypress.json’ to wait longer.
Browsers will not fire the ‘load’ event until all stylesheets and scripts are done downloading.
When this ‘load’ event occurs, Cypress will continue running commands.
Desired behavior:
Always load the page.
Steps to reproduce: (app code and test code)
I realize I am not providing a reproducible example, but it is not triggered by any specific test and is not reliably reproducible. I have seen in other tickets that members of the cypress team have asked for additional logging to be turned on. I would like to turn on additional logging that may help diagnose this and provide you the logs next time this happens.
Versions
Cypress 3.1.3
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 42
- Comments: 85 (24 by maintainers)
We also have this issue. Is there any update yet?
I having issue with cy.visit() as well but only with Electron browser… 100% of the time What are the steps of my application
At the step 3 users page is never opened.
A small spinner in the URL field is always loading and error of Cypress Timeout 😦

UPDATE: The issue was because of the error with ‘beforeUnload’ event. This error was in the console. Chrome ignores is, but Electron not. Found a workaround with this code added to support/index.ts
Cypress.on('window:load', function(window) { const original = window.addEventListener; window.addEventListener = function() { if (arguments && arguments[0] === 'beforeunload') { return; } return original.apply(this, arguments); }; });Known
beforeloadissueWe have found a situation where a Page load may time out if there is an event listener on
beforeloadon the application under test when running in Electron. This would prevent the page from navigating and timeout on the Page Load.This error looks slightly different from a cy.visit() error timeout and will display the text below.
When this happens:
This situation could happen if you have code similar to any of the code examples below:
Workaround:
There are 2 possible workarounds.
--chromeflag duringcypress runor choosing Chrome duringcypress open.OR
support/index.jsfile. This will prevent the prompts from occurring - and not hang Electron.Everyone
Please try the workaround code above. If this solves your issue, refer to https://github.com/cypress-io/cypress/issues/2118 if this is your issue for official updates. This seems to be the issue for @mariusbutuc, @mattcrooks specifically.
We have had to give up on cypress due to this issue causing our team to loose trust in our tests.
Fingers crossed it can be fixed. This is a game stopper unfortunately for now.
Upgrading from Cypress
3.1.5to3.3.1, I’m having this issue only on CI for some reason.And in 100% of the cases, no way to make it work on CI, but all fine locally 🤷♂️
This is happening 100% of the time on a particular page for us. This only seems to happen when when the page requests confirmation to navigate away. There is an error in the console:
Blocked attempt to show a 'beforeunload' confirmation panel for a frame that never had a user gesture since its loadHoping this helps with the diagnosis
This only happens in Electron not Chrome.
We’ve blacklisted the hosts linked in #1608 and are still seeing this issue
So for me, it seems that this was an issue with loading resources on the page. I am testing a react application, and the first request to the page will compile the JS bundle. The first request was always taking much longer than the initial timeout since it is a large application. Subsequent attempts succeed (on the same machine) because the initial request already started the build process.
It seems like it might be helpful for the error message to indicate that there were still some resources loading if the visit doesn’t succeed because of resources (and maybe what the resources were). My page itself was loading from the server, but the load event was what wasn’t triggering. I realize that the error message indicates that for the most part, but more details would probably help.
@jennifer-shehane :
seeing this too on
The spec passes when run using
cypress openbut fails when running in circle (underlying command is./node_modules/.bin/cypress run --reporter junit --reporter-options 'mochaFile=results/junit.xml' --spec <path-to-our.spec.js>)The test does has a
beforeEachwhich executes a Command to make an API request. In the.thenof that command, we run another to login as a user. We do both of these in most test with no problem.The test then does the following:
Could it have something to do with
cy.window? or withwindow.localStorage.getItem?Also to note, the app page shows a confirm alert when exiting (the
cy.visitwould trigger that). Cypress seems to automatically accept alerts (https://docs.cypress.io/api/events/catalog-of-events.html#Window-Alert) and i’m seeing this when running the test withopenbut maybe this doesn’t work well when running withrun. In which case, this could be related to https://github.com/cypress-io/cypress/issues/2118.I’m able to repro this so let me know what info you need
We seem to experience same issue.
See https://travis-ci.org/orwell1984/explorer/builds/516284960 for CI run and https://github.com/orwell1984/explorer/blob/master/cypress/integration/clades_info.spec.js for code.
@jennifer-shehane How is this awaiting information when you have shown reproductions in cypress’ own repos? https://github.com/cypress-io/cypress/issues/2938#issuecomment-448135595 As a paying subscriber is it possible to get any extra help in fixing this issue? I’m making a feature to investigate and fix this in cypress, but its pretty difficult… It would probably already had a resolution if someone had added exposed logging that could tell us what the problem is, because then we could run it on our builds, see the error and know what needed fixing.
Same thing here, on circleCI, even after upgrading to 3.1.5 that supposed to fix an onLoad bug.
I’ve ended up solving our problems by retrying : https://github.com/cypress-io/cypress/issues/1313#issuecomment-409342834
I too have been seeing this issue for several months. I tend to get anywhere between 1 to 3 test failures in every other run or so due to timeout, regardless of how high I configure it.
We have retries running but it’s causing the team to loose confidence in the stability of the tests.
I’m running 400+ tests hourly as well as chained to deployments and every time it breaks the build a little part of me dies.
Thanks I have deleted the history and update again.
I also want to make sure everyone visiting this issue is aware of a known issue when calling cy.visit() to a url that you are currently navigated to - https://github.com/cypress-io/cypress/issues/1311
It exhibits the exact same error of timing out waiting for the ‘load’ event - so ensure this is not the case for you - you likely would not be intentionally visiting the same url twice, but your application may be rerouting and end up visiting the exact url you are already on.
I’ve tried:
Is there some way to catch the visit failure and try visiting again?