cypress
cypress copied to clipboard
injectDocumentDomain:false When changing origin many times via redirect seems to be confused.
Current behavior
Hello. We are having issues with injectDocumentDomain: false.
We get this error and at other time we get the error about "top" domain and cy.origin not being required. (when it clearly is) Actuall the error message reports something and states that the domains are the same - when the domains that it says are the same are two different addresses ( but it is true they are the same domain eventually)
I'm documenting the general path of the test case. It's quite complex with all the redircts and the number of times the origin changes and also makes use of "cy.request" - as soon as the injectDocumentDomain becomes "false" then I get the error ( at the bottom ) if i adjust the code to handle the error, then i get the inversion of the error. It goes back an forth like that - no matter which order (or even if i clear the origin between sections with "about:") it doesn't fail to keep generating one of the two error.s
Here are some details which i think are contributing to confusion for cypress. There are quite a number of redirect that happen automatically.
app.domain.com automatic redirect to => identity.domain.com
If there is no session:
subdomain.domain.com automatic redirect to => subdomain.domain.com/sign_in
If there is no session:
subdomain.domain.com/sign_in automatic redirect to => identity.domain.com/?someparams
If there is no session:
identity.domain.com/?someparams automatically redirect to => identity.domain.com/oauth/authorize?acr=etc&lots_of_outh2_params
Given thats how the system redirects
Then the test is the following:
visit "subdomain.domain.com" (end up on "identity.domain.com") enter email / password and then "submit"
( "submit" causes another redirect if the password and email are valid this returns the browser to "subdomain.domain.com")
Now use cy.request to make an API call ( that disables the users session ) # this is eventually consistent
Now visit
visit "subdomain.domain.com/private-area"
and use a recursive wait loop that checks up to 10 times
subdomain.domain.com/sign_in?user_return_to=/private-area
and expects the session to be destroyed and send the user via a redirect to identity.domain.com
CypressError: Timed out retrying after 4000ms: The command was expected to run against origin `https://identity.domain.com` but the application is at origin `https://subdomain.domain.com`/.
This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.
Using `cy.origin()` to wrap the commands run on `https://subdomain.domain.com` will likely fix this issue.
`cy.origin('https://subdomain.domain.com', () => {`
`})`
If i follow the suggestion above then I can write the test in such a way that the error it gives me is
CypressError: Timed out retrying after 4000ms: The command was expected to run against origin `https://subdomain.domain.com` but the application is at origin `https://identity.domain.com`.
This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.
Using `cy.origin()` to wrap the commands run on `https://identity.domain.com` will likely fix this issue.
`cy.origin('https://identity.domain.com', () => {`
` <commands targeting https://identity.domain.com go here>`
`})`
Desired behavior
I'm not sure to be honest.
Test code to reproduce
I can't isolate this as it's requires accounts and non public secrets.
Cypress Version
14
Node version
22.16
Operating System
mac
Debug Logs
Other
No response