cypress-io / cypress

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

pageLoadTimeout not working correctly #2549

Closed michaelcarteryork closed 5 years ago

michaelcarteryork commented 6 years ago

Current behavior:

Hi, I have come across a bug when running batch tests. The timer logs the time for all tests and doesn't reset in between. When an page is requested and doesn't load quickly the pageLoadTimeout value in cypress.json is checked against this composite time causing this and all subsequent tests to fail. The timer should surely be reset to zero at the start of each individual page load not the composite value for all tests.

Steps to reproduce:

Run a sequence of tests with a purposefully loading page load fail. Note that the timeout for the pageLoadTimeout uses the composite time for all tests not the time for the individual page request

Versions

Not sure of version of Cypress, Chrome (latest)

jennifer-shehane commented 6 years ago

Could you include some of the test code you are running? How are you using the pageLoadTimeout in your tests?

michaelcarteryork commented 6 years ago

Thank you for getting back to me so quickly Jennifer. I'll attach a pdf which explains the issue further: Cypress timeout issue.pdf

michaelcarteryork commented 6 years ago

do you have everthing you need @jennifer-shehane ? Many thanks

jennifer-shehane commented 6 years ago

cypress timeout issue

@michaelcarteryork I do understand the behavior you are describing. Is there any way you could provide a repo or set a tests where we could reproduce this behavior?

jennifer-shehane commented 5 years ago

Unfortunately we'll have to close this issue if no reproducible example is provided. Can you provide a way to reproduce this?

ChrisLahaye commented 5 years ago

I would like to confirm that I am encountering the same bug. @michaelcarteryork did you manage to fix or work around this?

michaelcarteryork commented 5 years ago

Hi Jennifer, Chris, apologies I'm not able to provide reproducble example (our code is local and behind many barriers). Hopefully Chris can provide an example? @ChrisLahaye @jennifer-shehane

ChrisLahaye commented 5 years ago

Test: https://gist.github.com/ChrisLahaye/c2e1fe5e11a6dd00161145b9de597919 Support file: https://gist.github.com/ChrisLahaye/7053cb1da0f6548fa91c81beb05258dd Suppor file sub: https://gist.github.com/ChrisLahaye/036d2de6b6c86817f38393f3713178ee

Config:

{
  "fixturesFolder": "spec/cypress/fixtures",
  "integrationFolder": "spec/cypress/integration",
  "pluginsFile": "spec/cypress/plugins/index.js",
  "supportFile": "spec/cypress/support/index.js",
  "viewportWidth": 1200,
  "viewportHeight": 1200,
  "defaultCommandTimeout": 15000,
  "requestTimeout": 15000,
  "video": false,
  "pageLoadTimeout": 300000
}

Note that the pageLoadTimeout is set extremely high as the timeout doesn't reset in between tests

jennifer-shehane commented 5 years ago

Hey @ChrisLahaye I won't be able to run these tests without the baseUrl provided. Also, is there any way that you could narrow down the issue? This is quite a lot of cypress commands for a reproducible example.

ChrisLahaye commented 5 years ago

@jennifer-shehane I am really sorry but I can't give you access to the application or more code than I did.

xviuda-rhm commented 5 years ago

@jennifer-shehane This also occurs in my project. What kind of info do you need to help you find this problem.

jennifer-shehane commented 5 years ago

@xviuda-rhm We need the reproducible code to run locally that shows this bug behavior - test code + app code.

xviuda-rhm commented 5 years ago

So i found out what triggered this issue on our side. When the app moves from page to page its load external javascript components. Because its our test env the developers created a XXX parameter in front of our hotjar.js. So the app is looking for xxxtestxxxhotjar.js. This gives a cannot find 404 in the console, but this also hinders cypress with the unload event.

So for me i fixed it by searching the event that triggers finding for the hotjar and stub it with cy.stub.

If i dont do it i need the pageLoadTimeout fix because there is still something wrong with the internal cypress timing.

@jennifer-shehane I'm sorry that i cannot give you access to our appcode. But i hope this explains a bit what happens. So in short: PageLoad>JS Error>Pageload event not fired(Says Cypress) > In the browser you see the new page > Cypress checks pageLoadTimeout and fails.

jennifer-shehane commented 5 years ago

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. 🙏

schwen commented 4 years ago

same problem

a global

 afterEach(function () {
    const testFailed = this.currentTest.err;
    if (testFailed) {
      cy.window().should("exist")
    }
  })

fixed it for me