Closed jackfranklin closed 4 years ago
That's a very interesting bug!
I've yet to figure out exactly what the cause here is. The particular XHR code is a $.getJSON
(from jQuery call) in a React componentWillMount
lifecycle hook. I don't see why those characteristics would lead to it behaving like this but I'm going to try using a plain fetch
call and see if that helps.
Is there a way from the Cypress GUI to get to the developer console for the page I'm testing to see if there's any useful information in the console / network tab?
Are you using React 16? I have seen this happen in my React app when running in Cypress when there was an error that was not being handled properly by an ErrorBoundary component. I kind of assumed this was reflective of the behavior of my application though and didn't look at the live application in the circumstance. I fixed my ErrorBoundary problem and it hasn't happened since. I could recreate that circumstance if you think there's any chance this sounds related. :thinking:
@jackfranklin just open your Dev Tools. Everything is in there the same as when you use your application outside of Cypress.
@brian-mann that's what I thought; but when I open the dev tools they don't work. I'm assuming this is because the browser is locked in an infinite loop of some sorts.
@jennifer-shehane that sounds relevant, I'll do some digging into that. I'll see if I can fix it by using an error boundary to catch any problems.
We are currently using React 15 and also have this problem. Will an update to React 16 solve this problem as @jennifer-shehane indicates?
This is not possible to track down without a reproducible repo. Cypress works with XHR mocking on a large number of projects including many many react 15 and react 16 projects.
I'm facing the same issue, hope the screenshot helps further. One thing that I'm noticing is that recurrence happens when the resource is required via text/plain. The test remains stuck. UPDATE: It happens only when I'm doing things like
cy.contains('foobar').should('be.visible')
and it's not there in the page yet. If I'm waiting for a route that would eventually display the content, the endless loop is not happening.
We are also facing the same issue while running in the browser, whereas in headless mode its working fine. The actual request is made only once.
We really need a small reproducible example to begin work on this issue.
I have just installed cypress via npm. With just the default settings I get into an infinite loop of GET requests after redirecting to the url below. The requests in browser's console are just like on @lsplogi screenshot.
I'm on Debian 9, using Chrome Version 65.0.3325.146 (Official Build) (64-bit).
My code:
describe('Cypress infinite loop', function() {
it('hangs', function(){
cy.visit('https://evryplace.com/panel');
})
})
Output:
...
GET /panel/i18n/59858b7/app-webvr_en.json 200 190.868 ms - -
GET /panel/i18n/59858b7/app-webvr_en.json 200 187.331 ms - -
GET /panel/i18n/59858b7/app-webvr_en.json 200 195.618 ms - -
GET /panel/i18n/59858b7/app-webvr_en.json 200 150.965 ms - -
GET /panel/i18n/59858b7/app-webvr_en.json 200 191.312 ms - -
Yep, this code does cause this never loading behavior. Thanks @balmar. The behavior looks oddly similar to this other issue's test code I just ran here: https://github.com/cypress-io/cypress/issues/1235#issuecomment-382912229
it('hangs', function () {
cy.visit('https://evryplace.com/panel/')
})
This was my "welcome to Cypress" bug.
I went through the tutorial on my project, and then it got stuck in this XHR loop. I can choose any route too and I get the same response. In this video recording, I chose a bad route. It didn't matter -- XHR loop. Only changing from Canary to Chrome solved it. (See screen cast below)
Hello, @jennifer-shehane Any progress with the issue?
In my case I was migrating tests from nightmare where you need to fire the callback when the test is complete. I had left the callback in the function call.
Was:
it('should test something', (done) => { ... })
Now:
it('should test something', () => { ... })
Tests no longer hang - this wont be a fix for the majority but thought I would add it for others to check.
@jennifer-shehane , i am also facing same xhr waiting scenario any update or alternative code snippets to place in config files like (commands file or cypress.json) wherein we would put timeout for xhr to complete and if there are uable to complete within provided timeframe we could cancel the request and continue with other test cases for time being till we could resolve this bug.
I see it's been almost a year since this thread was last addressed: any updates on this? Works fine when using Electron but hangs forever in Chrome.
I'm trying to decide between using Cypress or something else like WebDriverIO combined with Jest for the React module testing. This is a big red flag right out of the gate, along with a community that doesn't keep up.
I am facing this same issue with infinite xhr loop when using wait.. any workaround would be appreciated
@jennifer-shehane Please help to resolve #5898. It is critical and please let us know if any work around too.
I also have this issue. The xhr request will get stuck in an infinite loop when I run Cypress through the GUI. When I run cypress headless it works perfectly fine. The GUI will freeze and I will have to force close it through the activity monitor. It is a web component using React.
I'm experiencing the same - it doesn't always reproduce, but is much more likely to do so when hitting a slower environment.
I also have this issue. The XHR request will get stuck in an endless loop. Any progress for fixing this?
I just ran into this issue after trying to fix fetch
: https://dev.to/mjsarfatti/how-to-test-your-fetch-requests-with-cypress-bh5
The culprit was the addition of:
Cypress.on('window:before:load', win => {
delete win.fetch;
});
Removing the above fixed my issues.
This is still happening, no updates after 3 years with this issue opened. Problem still happens only in GUI mode.
I also have this issue. The xhr request will get stuck in an infinite loop when I run Cypress through the GUI. When I run cypress headless it works perfectly fine. The GUI will freeze and I will have to force close it through the activity monitor. It is a web component using React.
If you're running Cypress from the terminal (cypress open
), you only have to go to that terminal and kill the process, it's faster to stop the freezing that way :)
I don't know if this is the case for anyone else, but this was happening for me because of a NewRelic script in index.html
. I'm now conditionally including it by environment.
I can't be sure that this is the actual issue that anyone else in this thread is experiencing since no one else provided a reproducible example. If you're facing this issue and need a fix, we suggest providing a reproducible example - as your issue may be different from the one we have.
This issue is still occurring in 4.9.0 with the example below.
it('hangs', () => {
cy.visit('https://evryplace.com/panel/');
})
cypress open
The cy.visit()
does not resolve and the browser locks up in all browsers (Chrome, Electron) during cypress open
. There are infinite requests that go out every second to GET /panel/i18n/7fa71d4/app-webvr_en.json
.
cypress run
The behavior is actually different during cypress run
. The cy.visit()
resolves and the test passes (although it looks like the page doesn't load exactly right still).
Should fully load UI like shown below.
@jennifer-shehane
Another quick way to reproduce it is trying to visit MS Office login:
it('can open office online', () => {
cy.visit('https://www.office.com/launch/excel?ms.officeurl=webapps&auth=2');
cy.contains('Sign in').should('be', 'visible');
});
Cypress output:
Expected page:
I know that there is a redirect, to another page (https://login.microsoftonline.com/
). I am just trying to login to MS Office online to be able to test Office Add-ins
The same behaviour happens, when I enter the login page directly 😢
For reproducible steps. You can create an any application and use the JavaScript snippet from NewRelic, you'll see these infinite redirects.
@swiecaJS Thanks for providing another repro. This does indeed cause infinite XHR loops where the cy.visit()
eventually times out.
I've had the same issue described here, but it's only consistently failing when running cypress run
, with cypress open
it's inconsistent.
But I noticed it doesn't happen when using Firefox, so I've switched CI to use Firefox and so far it's ok.
I really was hoping to test the frontend on Chrome though, so I'm looking forward for a solution.
@swiecaJS That's actually a separate issue here. The Office login page has some code that detects if it's running in an iframe, and if so reload itself / make some requests. Cypress works by running everything within an iframe, so that's where this becomes a problem. However, our new system of source rewriting is designed to fix some issues like this, which you can enable by setting experimentalSourceRewriting
to true
in your config. This fixes some of the issues that page was having with Cypress, but it still doesn't load yet. That's mainly because we're only rewriting sources from the same domain as the main document, but the page is pulling in some scripts from different domains that (also) contain problematic code for iframes. We'll have to reconsider the way that we handle source rewriting in order to make this page work, cc: @flotwig
As far as the original issue goes, I've been able to narrow down the issue and am trying to figure out a viable fix.
As for the original reported bug, it looks like the underlying issue was actually #7187, which has to do with how our snapshot functionality would accidentally interact with documents using custom elements. A PR #8080 has been created to address this, and fixes the issue initially reported here with https://evryplace.com/panel
.
The code for this is done in cypress-io/cypress#8080, but has yet to be released. We'll update this issue and reference the changelog when it's released.
Released in 4.12.0
.
This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v4.12.0, please open a new issue.
Current behavior:
When visiting a page on our site through Cypress we're seeing it never complete loading because something causes the XHR requests being made to be made infinitely.
If we look at the Cypress CLI output when running the test we see:
This request is only made by our application once; if I got to the page in a browser and watch the network tab I can see that the request is made once. Watching the test through the Cypress UI, I can see that the browser just hangs and becomes unresponsive as all these requests are firing.
I'm not sure what, but something is causing these requests to run again and again and again.
Interestingly, this only happens via
cypress open
and then running the test through the UI. If I docypress run
and watch the video, the test does complete and the XHR requests complete as expected.I'm not sure what extra info is useful here but let me know what I can provide to help with this.