cypress
cypress copied to clipboard
cypress reloads in infinite loop when calling cy.visit to http URL that upgrades to https.
Current behavior
When visiting a page that triggers certain redirects, the test runner keeps reloading and looping endlessly.
https://user-images.githubusercontent.com/39823861/220307457-9c30ff6e-a37d-4abf-b370-2431082d3aae.mp4
Desired behavior
Not reload the test runner and follow redirects.
Test code to reproduce
describe('example cypress reload issue', () => {
it('keeps reloading', () => {
cy.visit('https://enexis.nl/mijn-enexis/mijn-aanvragen')
})
})
Cypress Version
12.6
Node version
18.12.1
Operating System
Win 11
Debug Logs
No response
Other
No response
Thanks for opening an issue @Jsijbel. Confirmed that I can reproduce this behavior. Is there a specific version this started occurring on for you?
It seems like there is a 301 and two 302's before landing back on inloggen
, possibly this redirect chain is causing Cypress to become confused:
I'll get this routed and prioritized for a fix.
Thank your for your response and acknowledgement. I honestly can't remember when this issue wasn't present, and we have been working with cypress in our teams for several years now. Normally this isn't a real issue for us as we collect the authentication programmatically in most cases, however for a new test case this is causing issues for us.
Was curious if there was a workaround ever found for this issue? I think I am perhaps hitting a similar issues (v12.9.0)
I am also curious about some workaround. Also having this issue (12.11.0) with an Angular app (redirects when authenticating).
Hi, I'm having the same issue. Is there any news about this problem? or any workaround? Thank you
I have the same problem..any news about this bug?
We observed this unexpected looping behaviour when Cypress was running on https:// in the Chrome browser that it was driving. The server for our system under test (SPA web app) only supports the http:// protocol. When we manually removed the s in the URL bar in the Cypress-driven Chrome, it began behaving as expected again (no looping).
We observed this unexpected looping behaviour when Cypress was running on https:// in the Chrome browser that it was driving. The server for our system under test (SPA web app) only supports the http:// protocol. When we manually removed the s in the URL bar in the Cypress-driven Chrome, it began behaving as expected again (no looping).
As first, Thanks a lot for solving our problem.. But need to ask..is it correct to leave tests like that...I mean is it good to work only on http protocol instead of both? Thanks
Between our tests running fine on Firefox and the comment above by @BevanR (thank you!), I'm wondering if this may be related to Chrome's recent change to use HTTPS by default.
@flotwig - Our team is also facing the same issue. URL starts with https
. This problem is happening only on Chrome. Firefox works perfectly fine.
Also having this issue - Chrome only
Also having this issue - Chrome only
Cypress suport only http protocol. Use http protocol instead of https..like this example:
*EROR
httpS://www.someexampe.com(when u test website with https its strating realoding)
acceptable :
http://www.someexampe.com (when u test website with http its NOT reloading)
exactly same issue here on Cypress [13.5.0]
To summarize, the issue arises only with newer versions of Chrome (it worked for me with an older version). The problem likely started with the introduction of https://blog.chromium.org/2023/08/towards-https-by-default.html.
Workaround: change the URL from https to http in the address bar of chrome and reload the web specs runner. After that, the tests run smoothly.
or a more permanent workaround is here: https://superuser.com/questions/565409/how-to-stop-an-automatic-redirect-from-http-to-https-in-chrome/881431 (the solution with the most upvotes)
We would recommend having your cy.visit visit the correct protocol (http/https) to avoid the redirection loop for now to get around this issue. We're looking into if anything can be done with the Chrome's new logic.
I am only seeing this with cypress open
, I don't see this with cypress run
Does anyone see the same?
I am only seeing this with
cypress open
, I don't see this withcypress run
Nevermind.....I am now seeing this issue with cypress run
does any of you have a solution for headless mode.... since I upgraded chrome to v120 I can't find a solution for making chrome use http instead of https and yes it falls in loop in headless mode. I tried all above mentioned possible solutions but no success yet.
@JohnnyTheBoy in my case I solved it by using this configuration
export default defineConfig({
video: false,
e2e: {
baseUrl: 'http://localhost:4273',
specPattern: '**/*.feature',
chromeWebSecurity: true, //using true prevents the page reload loop
defaultCommandTimeout: 10000, //Extended the default timeout, might be slower in docker
experimentalModifyObstructiveThirdPartyCode: true,
setupNodeEvents
}
});
the chromeWebSecurity: true
fixed the loop issue
Well, the problem with setting chromeWebSecurity
to false
is that I can no longer manipulate iframes (as described in this post: https://www.cypress.io/blog/2020/02/12/working-with-iframes-in-cypress), so unfortunately that is not an option for me.
@joaconigro It's not working for me.... Can you confirm that you have chrome v120
@joaconigro It's not working for me.... Can you confirm that you have chrome v120
Actually, I'm not using Chrome, but Microsoft Edge v120. I thought it should work as well :(
I updated the workaround here: https://github.com/cypress-io/cypress/issues/25891#issuecomment-1861098656
@alexsch01 Nope..... still not working with Cypress v 13.6.1 and Chrome v120 .... you can test that by adding code to the scaffolded cypress tests.
Hi, I'd like to get some understanding on why this workaround doesn't work for people. To visit the correct URL to begin with. Is there a reason you need to visit the http
or https
and have it resolve to the other protocol?
We would recommend having your cy.visit visit the correct protocol (http/https) to avoid the redirection loop for now to get around this issue.
Hi, I'd like to get some understanding on why this workaround doesn't work for people. To visit the correct URL to begin with. Is there a reason you need to visit the
http
orhttps
and have it resolve to the other protocol?We would recommend having your cy.visit visit the correct protocol (http/https) to avoid the redirection loop for now to get around this issue.
Internal (not exposed to the Internet) company apps generally use http
- I am using the correct protocol (http) for the URL I'm visit'ing
Yah I can recreate this infinite loop with this example which has no https
protocol.
it('loops forever', () => {
cy.visit('http://http.badssl.com/')
})
Lets say test1
and test2.com
are both in the host file and they go to the same IP Address
and there is no https version
cy.visit('http://test') - won't have the looping issue cy.visit('http://test2.com') - will have the looping issue
for the httpforever.com example
cy.visit('http://146.190.62.39') - won't have the looping issue cy.visit('http://httpforever.com') - will have the looping issue
@jennifer-shehane In DevTools running in Cypress Chrome window,
location.href = location.href.replace(location.origin, 'http://httpforever.com')
It automatically upgrades it to https
I have also issue with opening http
protocol - tried chromeWebSecurity: true
- but strange that in 1 application it worked, but in another doesn't.
Issue occurred after updating to chrome 120
Not reproducible on Firefox 120