Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page occasionally does not load from cy.visit() #2938

Closed
drewbrend opened this issue Dec 12, 2018 · 85 comments
Closed

Page occasionally does not load from cy.visit() #2938

drewbrend opened this issue Dec 12, 2018 · 85 comments

Comments

@drewbrend
Copy link

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

@jennifer-shehane
Copy link
Member

Does this happen during cypress open, cypress run, or both?

@lukeapage
Copy link
Contributor

lukeapage commented Dec 13, 2018

We also have the same problem - I've been spending alot of time investigating this - I wrote up my findings so far on this issue:

#1311 (comment)

but I've definitely ruled out visiting the same url as the cause of the problem - I was about to raise a new issue when I saw this.

I've only ever seen the problem on cypress run but for us (as above) it is approximately 1/200 times that visit fails.

As I say in the link - our server definitely responds with the correct and identical html, but its stalled.

It looks like it is something to do with the way in which the initial result is redirected to the proxy - but my knowledge of the inner workings of cypress are preventing me getting further. I'm happy to add any logging or run a special debug version.

@lukeapage
Copy link
Contributor

I've tried:

  1. navigating to a different page first
  2. turning on full logging
  3. waiting for a second before cy.visit

Is there some way to catch the visit failure and try visiting again?

@drewbrend
Copy link
Author

Thanks for the additional info @lukeapage!

@jennifer-shehane cypress run is where we are seeing it most often, because we run that very frequently. I estimate we are averaging 1,000 calls to cy.visit() per day in CI with cypress run, probably more.

I believe I have seen it with cypress open a while ago, but it is very infrequent due to the difference in the amount we run in CI vs local development where one person only runs the few tests they are working on.

@lukeapage
Copy link
Contributor

I’ve ended up solving our problems by retrying :
#1313 (comment)

@drewbrend
Copy link
Author

That is a decent workaround. I'm hesitant to implement auto retries because it will allow for sloppier test writing. If there was a way to implement it for just this issue I'd be all over it.

@lukeapage
Copy link
Contributor

If there was a way to implement it for just this issue I'd be all over it.

You may be able to - if the cli returns the reason for the failures, you can alter that script to only retry tests where this is the problem.

My plan is that for CI and getting PR approval, I will allow retry. But I also have a scheduled run of 20x on master where I will disable retry. Any intermittant failures coming up from that can then be investigated.

However I am wondering how even that will work out - I've spent alot of time fixing intermittant failures the last 5 days and #695 is a big source of problems (click does not retry the get if the element is not visible) and quite often there are situations where it is very difficult to assert with a should in order to make sure the click definitely won't fail.. thats alot of effort that I am not sure if it is worth it, espescially if the cypress team fix #695 . So far it looks like this issue and that issue are the main causes and everything else is a real app problem that should be fixed.

@drewbrend
Copy link
Author

We're in the same situation, one of the commenters on #695 is my teammate. Besides that issue we've been able to fix all intermittent failures with either a cy.route()/cy.wait() or a .should().

Thanks, I may look into modifying the retry script in January - higher priority things right now, then we're shut down for the holidays.

@Wolsten
Copy link

Wolsten commented Dec 14, 2018

I get the same error running on my development computer using MAMP. The error arises in different specs but only when I choose to "Run all specs". The error is somewhat random as different specs fail in different places, though some seem to fail more than others. This is happening where there is a valid target to click() using cy.get() (rather than using cy.visit() to a specific url). I find that the url is always opened correctly when I run each spec individually. I'll take a look at the work around, but it doesn't appear to be ideal.

@drewbrend
Copy link
Author

@Wolsten that sounds like a different issue. This issue is about a page not loading from cy.visit(), not cy.get().click().

@Wolsten
Copy link

Wolsten commented Dec 15, 2018

@drewbrend, thanks for the feedback. I tried replacing the get click with visit(url) and I see the same error, it doesn't appear to matter how the url is determined. The test in question runs fine every time I run in isolation but always times out when run in a sequence of tests. The strange thing is going back through the snapshots, the one for the page I requested through visit(url) is correctly displayed and the following get([name=title] succeeds as shown in the attached screenshot.

screenshot 2018-12-15 at 12 30 03

@Wolsten
Copy link

Wolsten commented Dec 15, 2018

A question about a possible work around. As the specs run without problem individually, is there a "before" command I could use to reinitialise the state of Cypress? I tried putting in a cy.wait(10000) in the "before" block but this didn't help.

@jennifer-shehane
Copy link
Member

There may be an intermittent issue involving the page load event, as I myself have this issue with one of our Cypress projects - this is the isolating factor though. I only have it on our Dashboard project, no other project. I've isolated a few instances in the past 6 months from our develop branch:

CircleCI IDs:
#16251
#15371
#14318
#13936
#8119

Video of failure - looks like the url may have gotten in a weird state before beginning test?
https://dashboard.cypress.io/#/projects/5b79905a-f894-4e91-b60c-fff4d94c218a/runs/47652/specs

Printed errors:
screen shot 2018-12-18 at 2 43 06 pm
screen shot 2018-12-18 at 2 31 05 pm
screen shot 2018-12-18 at 2 30 27 pm
screen shot 2018-12-18 at 2 29 22 pm
screen shot 2018-12-18 at 2 25 57 pm

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Dec 18, 2018
@lukeapage
Copy link
Contributor

@jennifer-shehane you have marked it "needs information" - is there anything we can add? If I were you I would enhance logging, release a new version and then ask for logs of when it occurs again.

@Wolsten
Copy link

Wolsten commented Dec 18, 2018

@jennifer-shehane I suspect that my issue is due to Ajax calls not being fully completed. For example, I update a page via an Ajax call and then click a pre-existing navigation element on the page - but not all new data has been loaded from the Ajax call. This is shown, for example, by tables with only partially drawn new rows in the captured screenshot. I have managed to get a much more stable environment by testing for page elements that should be generated by Ajax commands (I guess this is the right thing to do anyway) and also by extending the "pageLoadTimeout" to 600,000 (this appears to be critical). What would be helpful would be a mechanism to identify exactly which page load url (ajax call) is causing the problem as the error message is often unrelated to the preceding step. If as @drewbrend suspects this is a separate issue would you like me to open a new one to this effect?

@jennifer-shehane
Copy link
Member

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

@drewbrend
Copy link
Author

@jennifer-shehane I'm not sure if that is the same issue. We are calling .visit() in a beforeEach() block, so it is often visiting the same URL, however:

  1. cy.visit() calls are not immediately after one another like that ticket
  2. It is far from 100% reproducible, only happens once every few thousand cy.visit() calls
  3. We are using Jenkins, not CircleCI

@dsimmer
Copy link

dsimmer commented Dec 18, 2018

Unfortunately I cannot offer much more detail, but we are experiencing this on a Mac - Linux machines run the spec fine every time, but the Mac will always fail at the exact same point.

Essentially the test looks like this:

export const goToLoginPage = () => {
  cy.visit('/', {
    onBeforeLoad: win => {
      win.sessionStorage.clear();
    }
  });
};

describe('Account scenarios', () => {
  it('Users can view their account details', () => {
    // All three run without issues
    [kim, david, keith].map(user => {
      goToLoginPage();
      logInAsUser(user);
      clickAccount();
      verifyAccountDetails(user);
    });
  });

  it('Kim can change her default location', () => {
    // Mac always fails with a timeout here, URL '/' never loads and the browser still shows the previous '/account' path after calling goToLoginPage. Linux works every time so far.
    goToLoginPage();
    logInAsUser(kim);
    clickAccount();
    verifyDefaultLocationDropDown();
  });
});

So essentially we are logging in 4 times and on the Mac the 4th time it will consistently fail to navigate to /. There is nothing really special in any of these tests - a couple of clicks, a wait, type some stuff into a field and check the contents of some inputs. I should also note that it is not on the same url - it navigates from /account to /

@Akshaya0309
Copy link

Akshaya0309 commented Jan 4, 2019

@jennifer-shehane I have to run regression , 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 by manual testing.

Now I am not able to run regression due to this issue. Can you please check its blocking whole regression.

image

given('recruiter is logged in', () => {
  cy.clearCookies();
  cy.visit('/' + '?policy=accepted');
  cy.visit('/werkgever/inloggen');
  Login.typeRecruiterCredentials('');
  cy.submit();
  cy.url().should('include', '/werkgever/uw-account');
});

when('recruiter has no products', () => {
  cy.get('.product-item').contains('Je hebt nog geen producten aangeschaft.');
});

when('recruiter selects a profile', () => {
  cy.visit('/recruiter/kandidaten/zoeken');
  cy.get(':nth-child(1) > .search-result').click();
});

it is not able to download /recruiter/kandidaten/zoeken
please check

@jennifer-shehane
Copy link
Member

Hey @Akshaya0309, is there anything printed in the console when opening the devtools?

@mshaaban088
Copy link

@Akshaya0309 I hope the recording key is not real

@mshaaban088
Copy link

@Akshaya0309 Even after editing the comment, the key still shown in the edit history.
Maybe you can delete the comment and re-comment once again

@Akshaya0309
Copy link

Thanks I have deleted the history and update again.

@mattvb91
Copy link

mattvb91 commented Feb 8, 2019

related: #1039

@acSpock
Copy link

acSpock commented Feb 12, 2019

Getting the same issue.

Cypress 3.1.0 - running headless Electron 59

One thing to note is this only occurs when i'm pointing my cypress baseUrl to a non localhost site. ie: my tests all pass when running my app locally but intermittent failure when running against dev/production environments.

At first I discovered certain 3rd party scripts were blocking the page load event that I added to the blocklists in cypress json. This fixed those issues but I have little insight when running headless via network tools to diagnose the issue.

Like others, I can't reproduce a particular test because sometimes they pass and others fail and vice versa.

@lukeapage
Copy link
Contributor

We are also non local.

My plan - see if I can reproduce locally, not in the ci, then hack navigation.coffee to log things and show them on the screen so that the error screenshot tells me what’s wrong - because I’ve never seen this with the ui open

@mattvb91
Copy link

@acSpock can you check in your network timeline if you can see the same issue as this with your blacklist: #1039 (comment)

@acSpock
Copy link

acSpock commented Feb 13, 2019

@mattvb91 is there a way to check this in headless electron with logs? I'm blind running in headless.

Update:::

I'm able to get around this error by updating pageLoadTimeout to 180000 in cypress.json - After running the same test 20+ times I notice the place in the flow stalls at random parts of my test. However, even though I can get my tests to pass, they take a few minutes longer than normal.

@flotwig
Copy link
Contributor

flotwig commented Jun 26, 2019

This is great @maxime1992, I'll start digging in. Do you have the entire log by any chance?

@maxime1992
Copy link

@flotwig yes, here's the full log

cypress-debug-issue-page-not-loading.txt

@lou
Copy link

lou commented Jun 27, 2019

I have the exact same issue as @maxime1992

When upgrading from 3.2.0 to 3.3.+ one of my tests timeout with this error message Your page did not fire its 'load' event within '60000ms'.

cypress_logs.txt

Let me know if you need further debug logs.

Thanks

@zsalzbank
Copy link

I'm getting the same thing too. I increased the timeout as well with no luck. Here are my logs:

error.txt

@flotwig
Copy link
Contributor

flotwig commented Jun 28, 2019

Hmm, I was hoping 3.3.2 would fix this issue but doesn't look like it.

@lou @zsalzbank Could you share the spec that reproduces this behavior?

@zsalzbank
Copy link

This is only happening for me on CI (CircleCI). Interestingly, if I SSH into the instance and then run the test with the same command, the test does run to completion. I'll try to come up with an example repo.

@lou
Copy link

lou commented Jul 1, 2019

@flotwig

describe('login page', function () {
  beforeEach(function () {
    cy.exec('RAILS_ENV=test bin/rake cypress:fixtures')
  })

  it('sets auth cookie when logging in via form submission', function () {
    cy.visit('/users/login')
    cy.get('input[name="user[email]"]').type('user@test.com')
    cy.get('input[name="user[password]"]').type(`aloha42{enter}`)
    cy.url().should('include', '/users')
    cy.getCookie('_test_session').should('exist')
  })
})

FYI I have the exact same kind of tests (same code) for two other kind of users and these 2 tests work as expected.

@zsalzbank
Copy link

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.

@dialex
Copy link

dialex commented Jul 4, 2019

We have had to give up on cypress due to this issue causing our team to loose trust in our tests.
This is a game stopper unfortunately for now.

I'm having exactly the same problem. Blacklisting does not behave as expected (issue), which leads to flaky tests, which leads to team distrust.

@FilepCsaba
Copy link

Giving my experience with this issue, maybe it helps some people.

For us this was caused by some occasional Exception that was visible only in the console, and this exception was caused by a race condition in our code, which in turn was caused, as far as i can tell, from a smaller number of simultaneous network connections in cypress's Chrome and Electron.
So this can also occur from the website not just Cypress.

@goldylucks
Copy link

goldylucks commented Jul 17, 2019

I have the same problem, and intercepting window:load didn't help

$ client/node_modules/.bin/cypress -v
Cypress package version: 3.3.2
Cypress binary version: 3.3.2

@exan-atsui
Copy link

It looks like 3.3.2 did resolve this for us

@mattcrooks
Copy link

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 load

Hoping this helps with the diagnosis

This only happens in Electron not Chrome.

@AxSch
Copy link

AxSch commented Aug 1, 2019

It looks like 3.3.2 did resolve this for us

This seems like the right "fix", went from tests working fine yesterday to completely failing this morning. The moment I update from 3.3.1 to 3.3.2, everything works. Madness.

@lenymo
Copy link

lenymo commented Aug 6, 2019

I was experiencing similar intermittent cy.visit('/') issues using both cypress run and cypress open with about 30-40% frequency on entirely random tests. It was consistently failing in both headless and headed mode, using both Chrome and Electron.

My tests visit the login screen at the beginning of each test but in some instances the "user" was staying logged in (I only realised this after repeatedly running an entire test suite using cypress open).

I was able to solve the issue by dispatching an existing redux RESET_AUTH action during my cy.seedAndLogin custom command. This ensures no login tokens are stored in redux state between tests and has solved my failing tests.

My issue is probably different to the one described above but I thought I'd share my solution in case it helps anyone else who experiences a similar issue and lands on this ticket.

@mariusbutuc
Copy link

mariusbutuc commented Aug 23, 2019

Noticing the same undesired(?) behaviour as @mattcrooks has referenced:

Blocked attempt to show a 'beforeunload' confirmation panel for a frame that never had a user gesture since its load. https://www.chromestatus.com/feature/5082396709879808

while running Electron 61, on

$ node -v
v8.11.3

$ cypress -v
Cypress package version: 3.4.1
Cypress binary version: 3.4.1

$ cypress open --project ./
# …

Update: My current understanding is that, in my particular scenario, Cypress sometimes thinks a test keeps running when there are continuous (BrowserChannel, in this case) long-polling requests. Don't know if this is by design. Maybe somebody from @cypress-io can comment in that?

As a workaround, the strategy on our end is to end those requests so that Cypress can fully complete the specific tests.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Nov 4, 2019

Known beforeload issue

We have found a situation where a Page load may time out if there is an event listener on beforeload on 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.

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.

When this happens:

This situation could happen if you have code similar to any of the code examples below:

window.addEventListener('beforeunload', (e) => {
  e.returnValue = 'Are you sure you want to leave?'
})

window.onbeforeunload = function(){
  return 'Are you sure you want to leave?';
};

Workaround:

There are 2 possible workarounds.

  1. Run your tests in Chrome using the --chrome flag during cypress run or choosing Chrome during cypress open.

OR

  1. Add the code below to your support/index.js file. This will prevent the prompts from occurring - and not hang Electron.
Cypress.on('window:before:load', function (window) {
  const original = window.EventTarget.prototype.addEventListener

  window.EventTarget.prototype.addEventListener = function () {
    if (arguments && arguments[0] === 'beforeunload') {
      return
    }
    return original.apply(this, arguments)
  }

  Object.defineProperty(window, 'onbeforeunload', {
    get: function () { },
    set: function () { }
  })
})

Everyone

Please try the workaround code above. If this solves your issue, refer to #2118 if this is your issue for official updates. This seems to be the issue for @mariusbutuc, @mattcrooks specifically.

@RashmiKalpeshChauhan
Copy link

RashmiKalpeshChauhan commented Nov 20, 2019

I am also facing the same issue. Launching browser is working fine. When I am clicking the "View more market link". it is throwing "CypressError: cy.visit() failed trying to load:"

My code is below:

describe('My firs Test',()=> {
  it('load page',()=>{
    cy.visit("https://www.binance.com/en")
    cy.xpath("//a[text()='View more markets']").click();
    cy.wait(50000);
  })
})

Getting the below error:

CypressError: cy.visit() failed trying to load:

https://www.binance.com/en/trade/ETH_BTC

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

Error: Parse Error

Common situations why this would fail:

  • you don't have internet access
  • you forgot to run / boot your web server
  • your web server isn't accessible
  • you have weird network configuration settings on your computer

The stack trace for this error is:

Error: Parse Error
at TLSSocket.socketOnData (_http_client.js:451:22)
at TLSSocket.emit (events.js:194:13)
at addChunk (_stream_readable.js:296:12)
at readableAddChunk (_stream_readable.js:277:11)
at TLSSocket.Readable.push (_stream_readable.js:232:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:165:17)

@RiZKiT
Copy link

RiZKiT commented Nov 20, 2019

I am also facing the same issue.

I don't think so. The live domain you are testing returns the x-frame-options: SAMEORIGIN header, which prevents that a page is loaded in an iframe.

Cypress uses an iframe to load tests. IMHO you will not be able to test this page in Cypress, unless you are able to modify the return headers and/or use a non-live version of the page, which is normally the better option anyway.

@krawetko
Copy link

krawetko commented Dec 5, 2019

This issue is giving us random build failures on random tests. This does not happen very often - maybe once every 30 builds (more often when the infrastructure is under heavy load). On the video the page is loaded normally, the XHRs have completed - it just stays at cy.visit step and eventually fails with Your page did not fire its 'load' event within '60000ms'. .

Would it be possible to catch this and re-execute the test?

@jmitchell38488
Copy link

@drewbrend great pick up. Was using the same approach but you're right about the intermittent issue when using cy.visit inside a beforeEach call 👍

@clarisights-sharanya
Copy link

@jennifer-shehane The same issue occurs to me more often. Is there a way to capture the error and visit the page again?

@pratik-chakravorty
Copy link

Experiencing the same issue but the strange thing is that the tests are all running fine locally but on CI it fails every single time.
I am using a docker container where I run the tests on my CI build in Jenkins. I am using cypress run --browser chrome. I have xvfb installed in my container along with all the necessary dependencies. I am stuck here completely trying every possible thing to resolve this issue for the past 5 days now. Nothing seems to be working. Any help would be greatly appreciated.

@clarisights-sharanya
Copy link

Experiencing the same issue but the strange thing is that the tests are all running fine locally but on CI it fails every single time.
I am using a docker container where I run the tests on my CI build in Jenkins. I am using cypress run --browser chrome. I have xvfb installed in my container along with all the necessary dependencies. I am stuck here completely trying every possible thing to resolve this issue for the past 5 days now. Nothing seems to be working. Any help would be greatly appreciated.

@pratik-chakravorty try setting --ipc=host if you're Docker, that will resolve the issue. If Kubernetes create a pod with spec hostIPC: true. If not both, can you be specific what's your CI comprises of?
Pls refer this for more info: #350

@jennifer-shehane
Copy link
Member

@RashmiKalpeshChauhan I'm not able to reproduce this issue in 3.8.3, please try upgrading.

We will be closing this issue.

There is one known issue provided in this long thread which is related to #2118 - If you have an onbeforeunload with an alert (or confirm, etc) then a timeout on page load will occur in Electron Please see the workarounds detailed here: #2118 (comment)

Every single other mention of this issue happening has not provided a reproducible example so we have no path forward to investigate.

If you are seeing the exact same error as below:

Screen Shot 2020-01-30 at 12 20 23 PM

  1. Update to the latest version of Cypress - your issue may be fixed.
  2. This may be this issue: Electron browser hangs/errors on apps with window.onbeforeunload alerts #2118 Please comment there.
  3. If the 2 steps above do not address your issue, open a new issue with a completely reproducible example that we can run on our machines. Any issues opened without a reproducible example will be closed as there is no path forward for us to investigate.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Jan 30, 2020
@cypress-io cypress-io locked as off-topic and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests