cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.03k stars 3.19k forks source link

Specs are failing randomly when cy.visit() command timed out #2639

Closed vpetrache closed 6 years ago

vpetrache commented 6 years ago

Current behavior:

screen shot 2018-10-23 at 11 40 29 am

  Test
    1) "before each" hook for "Approve an instance, for AWS provider, with the default data"
  0 passing (1m)
  1 failing

  1) Test
       "before each" hook for "Test":
     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.

Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'Test...'
      at Object.cypressErr (http://localhost:60970/__cypress/runner/cypress_runner.js:67594:11)
      at Object.throwErr (http://localhost:60970/__cypress/runner/cypress_runner.js:67559:18)
      at Object.throwErrByPath (http://localhost:60970/__cypress/runner/cypress_runner.js:67586:17)
      at timedOutWaitingForPageLoad (http://localhost:60970/__cypress/runner/cypress_runner.js:57781:17)
      at http://localhost:60970/__cypress/runner/cypress_runner.js:58390:18
      at tryCatcher (http://localhost:60970/__cypress/runner/cypress_runner.js:6846:23)
      at http://localhost:60970/__cypress/runner/cypress_runner.js:2163:41
      at tryCatcher (http://localhost:60970/__cypress/runner/cypress_runner.js:6846:23)
      at Promise._settlePromiseFromHandler (http://localhost:60970/__cypress/runner/cypress_runner.js:4868:31)
      at Promise._settlePromise (http://localhost:60970/__cypress/runner/cypress_runner.js:4925:18)
      at Promise._settlePromise0 (http://localhost:60970/__cypress/runner/cypress_runner.js:4970:10)
      at Promise._settlePromises (http://localhost:60970/__cypress/runner/cypress_runner.js:5045:18)
      at Async._drainQueue (http://localhost:60970/__cypress/runner/cypress_runner.js:1778:16)
      at Async._drainQueues (http://localhost:60970/__cypress/runner/cypress_runner.js:1788:10)
      at Async.drainQueues (http://localhost:60970/__cypress/runner/cypress_runner.js:1662:14)

Desired behavior:

The test should not fail in cy.visit() command.

Steps to reproduce:

cy.clearCookie('react').clearCookie('angular');
cy.clearLocalAndSessionStorage();
cy.getURLByEnv().then(url => {
        cy.visit(url);
        cy.loginThroughRequest(Cypress.env('USERNAME'), Cypress.env('PASSWORD'));
        cy.reload();
    });

Sorry for not providing the app's url.

I get the same behavior if try to run the tests with cypress open or cypress run.

I don't know if it's a OS issue or its an issue with the steps I wrote or caching.

The problem occurs randomly, sometimes disconnected/connected the ethernet cable and the tests worked. Sometimes I retry running the tests and it works.

It's important to state that before running each spec I do clearCache and localStorage as it caused problems in the past.

Versions

Cypress: 3.1.0 NodeJS: 8.12.0 OS: MacOS Mojave 10.14

Any solution is welcomed. Thanks in advance!

vpetrache commented 6 years ago

This is the local Storage when the visit command fails.

screen shot 2018-10-23 at 2 14 25 pm

jennifer-shehane commented 6 years ago

@vpetrache It appears that your application is not firing it's load event within 60 seconds.

Have you tried increasing the timeout to allow more time for your page to load? cy.visit('url', { timeout: 80000 })

Can you verify that your app is firing the load event and Cypress is incorrectly logging this error anyway?

pazjing commented 6 years ago

I encountered a similar issue very often. even the same test. sometimes it just fails. I wonder if anyway that we can debug or capture more log for troubleshooting.

   CypressError: Timed out after waiting '50000ms' for your remote page to load.

Your page did not fire its 'load' event within '50000ms'.

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.

Because this error occurred during a 'before all' hook we are skipping the remaining tests in the current suite: 'Account Setup'
EdwinMeijne commented 6 years ago

I also encountered this issue. We are running our app in a docker container on the bitbucket pipelines, and then run cypress tests which randomly fail (we reran it a few times, and each time other tasks fail). After bumping the value to 3 minutes it seems not to happen anymore.

vpetrache commented 6 years ago

@EdwinMeijne @jennifer-shehane Increasing the load timeout to 120000 fixed the issue. Thanks for the solution.

EdwinMeijne commented 6 years ago

I have to come back from my previous statement; I just had failing tests again. I will bump now to 5 minutes to see if that resolves it as we add more tests (we are mainly writing tests currently)

jfo84 commented 6 years ago

@EdwinMeijne We're having the same issue. Identical setup

ghost commented 5 years ago

We're also experiencing the same issue, with a React SPA, even though the page is visibly done loading in the screenshot taken by Cypress. This only happens in CI, and also only randomly.

jennifer-shehane commented 5 years ago

We'll need a reproducible example to reopen this issue. Can anyone provide a way to reproduce this?

jfo84 commented 5 years ago

After tuning the timeouts to 30000 we haven't run into this issue in CI. Sometimes on very busy machines. If people still need help with the bitbucket setup, etc. feel free to ask

chantlong commented 5 years ago

Everything works perfectly locally, but when ran on Bitbucket Pipelines, it flakes out consistently. Adding cy.visit('url', { timeout: 30000 }) solved it. Thanks! Something about Docker makes it need more time.

rodrigovolkmer commented 5 years ago

I wonder if there is a way to retry the commands once or twice before failing? that way we wound't need to bump the timeout too high because if the page randomly got stuck on loading, it doesn't matter how long the wait it, because it just makes the whole testing suite to be very slow.

jennifer-shehane commented 5 years ago

@rodrigovolkmer There is an issue open regarding retrying tests / commands here: https://github.com/cypress-io/cypress/issues/1313 with some current workarounds to implement this.

canderson22 commented 5 years ago

How can we just try a retry, if cy.visit() fails once?

jennifer-shehane commented 5 years ago

@canderson22 See this thread: https://github.com/cypress-io/cypress/issues/1313 Also this plugin: https://github.com/Bkucera/cypress-plugin-retries

ranjanngc commented 4 years ago

I am still getting this issue

 before(()=>{
        cy.visit((URL,  {timeout: 80000 }); //Color Screen
        cy.login();
    });

url is redirection, meaning its callas login.aspx but get back default.aspx. Server redirects it to different page.

 "before all" hook for "Test numeric field":
     CypressError: Timed out after waiting `80000ms` for your remote page to load.

Your page did not fire its `load` event within `80000ms`.

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.

Because this error occurred during a `before all` hook we are skipping the remaining tests in the current suite: `Test screen feature II`
      at timedOutWaitingForPageLoad (URL__cypress/runner/cypress_runner.js:144463:13)
      at (URL/__cypress/runner/cypress_runner.js:145424:16
      at tryCatcher ((URL/__cypress/runner/cypress_runner.js:10384:23)
      at(URL/__cypress/runner/cypress_runner.js:5506:41
      at tryCatcher ((URL/__cypress/runner/cypress_runner.js:10384:23)
      at Promise._settlePromiseFromHandler ((URL/__cypress/runner/cypress_runner.js:8319:31)
      at Promise._settlePromise ((URL/__cypress/runner/cypress_runner.js:8376:18)
      at Promise._settlePromise0 ((URL/__cypress/runner/cypress_runner.js:8421:10)
      at Promise._settlePromises ((URL/__cypress/runner/cypress_runner.js:8497:18)
      at _drainQueueStep ((URL/__cypress/runner/cypress_runner.js:5091:12)
      at _drainQueue ((URL/__cypress/runner/cypress_runner.js:5084:9)
      at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues ((URL/__cypress/runner/cypress_runner.js:5100:5)
      at Async.drainQueues ((URL/__cypress/runner/cypress_runner.js:4970:14)
  From Your Spec Code:
      at Context.eval ((URL/__cypress/tests?p=cypress\integration\screen-feature-2.rkumar.spec.js:18:8)
danielmhair commented 4 years ago

I had this same error, and realized I hadn't updated Cypress for a VERY LONG time. haha. I was at version 3.8.2. I updated to 4.8.0 and it worked perfect.

nishant994 commented 4 years ago

I am facing this issue because domain changes on my app in between. Any solution?

AILazerka commented 2 years ago

I'm facing this issue with Cypress 9.5.0.

There are no domain switching in between or anything like that. It is very random. I was able to see it on the videos from the pipeline: Page just loads almost instantly but cy.visit is still waiting. As a temporary workaround - I'm enabling the retries for now.

Would be nice to get it sorted.

estet commented 2 years ago

Having the same issue in Cypress 9.4.1. The bug has to be reopened @jennifer-shehane

Julyanajs commented 2 years ago

@jennifer-shehane having the same issue in Cypress 9.5.4, even trying to use the "retries" plugin, my problem was not solved. =(

Julyanajs commented 2 years ago

Having the same issue in Cypress 9.4.1. The bug has to be reopened @jennifer-shehane

Did you find any solution for this error?

finnef commented 2 years ago

I have the same problem running my tests. It mostly occurs after a few longer tests have been run (in Gitlab CI). At some point cy.visit() will return a 500 error.

zsaidov commented 1 year ago

Having the same issue in Cypress 12.9.0.

nagash77 commented 1 year ago

@zsaidov please open a new issue with a reproducible example and the Cypress team will be happy to investigate.