Cypress "cy.visit() failed trying to load" - Fix Page Load Errors
cy.visit() loaded the URL but the response was not a success: a 4xx/5xx status, a refused connection, or a redirect Cypress could not follow. By default Cypress fails the test on any non-2xx/3xx response.
What this error means
A test fails at cy.visit(...) with "cy.visit() failed trying to load: <url>", reporting the status code or connection error it received. The browser opened but the page did not load successfully.
cy.visit() failed trying to load:
http://localhost:3000/dashboard
The response we received from your web server was:
> 500: Internal Server ErrorCommon causes
App returned an error status
The page itself responded 4xx/5xx (a backend not seeded, a missing env var, an unhandled route). Cypress treats any non-2xx/3xx as a failed visit.
Connection refused or DNS failure
Nothing is listening at the URL, or the host is unresolvable in the CI network (e.g. a service name that only exists in another container).
How to fix it
Fix the underlying response
- Open the reported status - a 500 means the app errored; check its logs and seed/env.
- A connection refused means the server is not up at that URL - start it and wait.
- Confirm the route exists and returns HTML, not a redirect loop.
Allow a non-2xx status only when intended
If you are deliberately asserting an error page, opt out of the default status check.
cy.visit('/missing', { failOnStatusCode: false });
cy.contains('404');How to prevent it
- Seed the backend and set required env before E2E runs.
- Gate the run on a healthcheck of the exact route you visit.
- Keep service hostnames/ports consistent between app and Cypress config.