-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
"CypressError: cy.visit() failed because you are attempting to visit a second unique domain." on same super domain, different sub-subdomains, different ports #1265
Comments
It considers the 2nd to be a unique domain because they share different origin policies. One has a port of It is possible to relax these rules when We have written a guide for this because this is almost always due to logging in which can be bypassed and achieved with https://on.cypress.io/best-practices#Visiting-external-sites |
What I'm trying to test is session persistence across two sites, which happens via cookie. I can manually complete the test I'm trying to do with Cypress, and it works, so I'm surprised to hear these sites can't communicate by cookie. It certainly looks like they can. Here's what the relevant code looks like: beforeEach(function () {
cy.visit(login_url)
cy.get('#inputEmail')
.type(email)
cy.get('#inputPassword')
.type(pass)
cy.get('input[value=Login]').click()
cy.visit(other_url)
})
it('has authenticated nav', function () {
cy.get('#header').should('contain', username)
}) Where I do have |
Okay you are correct in regards to same origin policy for cookies. For historical reasons - port and scheme are not considered when setting cookies. Even though browsers restrict same origin policy to scheme and port, cookies are the exception. So in your case, yes they can set cookies.
To clarify - what I meant was that with When we do that your situation will work. As of today, these are still not considered same origin to the browser or Cypress and therefore the error message is correct (even though the cookies are accessible). |
I'm curious though - you should still be able to test this situation by using It would go something like.. cy.request(...) // to the auth server and get back cookies
cy.visit(...) // the app server which should have the cookies and be logged in |
@brian-mann Is there some documentation on how to make the I'm also trying to specifically test the OAuth process between two websites and I need domains to be different. This seems like a very common scenario. I know it can be solved with I'd rather have |
I have a login server I have no control over, and stubbing responses is too complicated and feels incorrect, since I also have other api requests that rely on cookies I get from said login server. |
Duplicate of #944 |
Is this a Feature or Bug?
I believe a bug. I was hoping #600 would fix it, but it didn't.
Current behavior:
cypress.json
has"chromeWebSecurity": false
. My test visits two sites, with URLs that look likehttps://foo.example.org
andhttp://bar.baz.example.org:8080
This throws a "second unique domain" error.Desired behavior:
Ideally this test would work without error. If that's just impossible for some reason, then a fallback desired behavior: https://on.cypress.io/web-security#One-Superdomain-per-Test explains why these are considered different super domains.
How to reproduce:
Sorry, I'm not sure. The exact domains I'm testing on are not publicly available and I haven't found a publicly available example that uses the same pattern.
The text was updated successfully, but these errors were encountered: