cypress
cypress copied to clipboard
.origin() doesn't differentiate subdomains as individual origins
Current behavior
The .origin() command doesn't accept new origin that haves the same domain but a different subdomain.
This worked in cypress 10, but stopped working after the upgrade to 11.
Desired behavior
Being able to use new origin with different subdomain but the same domain.
Test code to reproduce
https://github.com/ChristofFritz/cypress-test-tiny
Downgrade to 10.3.0 and it works
Cypress Version
11.2.0
Node version
v18.10.0
Operating System
macOS 12.6
Debug Logs
cy.origin() requires the first argument to be a different domain than top. You passed https://submit-e2e-fix.review.redacted.de to the origin command, while top is at https://app-e2e-fix.review.redacted.de
Other
No response
Same scenario happens also for me, having node v16 and 11.2
It works if you just remove the .origin(). But that can't be the solution... right?
Hi @ChristofFritz , in this use case you would not use cy.origin. We have a couple of discussions and a thread on an issue related to this topic. This is a topic we will be following how real world utilization goes for cy.origin and see if this is something that we should alter in the future. However for now we do not have plans to change this behavior.
Hi ! Not sure if anyone will see this comment but i feel there are things to add here.
In my scenario, more specifically using SSO Authentication (identidy provider is on a super-domain that we own), there are situations where the identity provider is or is not on the same super domain than top origin, depending on the environment on which the tests are run.
Examples:
- Testing on localhost:3000 + identity provider on somedomain.example.com -> cy.origin required for tests to function.
- Testing on our testing environment (testing.example.com) + identity provider on somedomain.example.com -> cy.origin fails and tests will fail.
What are we to do ?
echoing @singeryo's scenario as well... origin()
should probably account for subdomains, or at least expose a configuration parameter or alternate method to account for this kind of usage!
We have exactly the same problem as @singeryo. Will there be a solution for this scenario or do you have a good workaround? I don't want to execute different test code depending on the environment.
@rspu, @dkurucz, you could try using experimentalSkipDomainInjection which would require you to use cy.origin
for all subdomain navigation.
here's a solution for @singeryo's situation that many of us find ourselves in.
This will use origin if the environment variable CYPRESS_BASE_URL
is set to something like https://localhost:3000
and otherwise it will ignore the origin and just run the test without it.
Cypress.Commands.overwrite('origin', (originalFn, origin, options, callback) => {
if (Cypress.env('CYPRESS_BASE_URL')?.includes('localhost')) {
return originalFn(origin, options, callback);
}
return callback(options.args);
});
here's a solution for @singeryo's situation that many of us find ourselves in.
This will use origin if the environment variable
CYPRESS_BASE_URL
is set to something likehttps://localhost:3000
and otherwise it will ignore the origin and just run the test without it.Cypress.Commands.overwrite('origin', (originalFn, origin, options, callback) => { if (Cypress.env('CYPRESS_BASE_URL')?.includes('localhost')) { return originalFn(origin, options, callback); } return callback(options.args); });
~~I think~~ this works until you have Cypress.require()
called in the callback ~~?~~