cypress icon indicating copy to clipboard operation
cypress copied to clipboard

.origin() doesn't differentiate subdomains as individual origins

Open ChristofFritz opened this issue 1 year ago • 2 comments

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

ChristofFritz avatar Nov 25 '22 14:11 ChristofFritz

Same scenario happens also for me, having node v16 and 11.2

cuadllop avatar Nov 28 '22 10:11 cuadllop

It works if you just remove the .origin(). But that can't be the solution... right?

ChristofFritz avatar Nov 28 '22 10:11 ChristofFritz

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.

nagash77 avatar Nov 28 '22 19:11 nagash77

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 ?

singeryo avatar Feb 06 '23 12:02 singeryo

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!

dkurucz avatar Feb 13 '23 15:02 dkurucz

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 avatar Apr 26 '23 11:04 rspu

@rspu, @dkurucz, you could try using experimentalSkipDomainInjection which would require you to use cy.origin for all subdomain navigation.

mschile avatar Apr 26 '23 16:04 mschile

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);
});

gilluminate avatar Dec 08 '23 21:12 gilluminate

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);
});

~~I think~~ this works until you have Cypress.require() called in the callback ~~?~~

Yihao-G avatar Feb 20 '24 06:02 Yihao-G