Skip to content
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

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

Closed
ChristofFritz opened this issue Nov 25, 2022 · 9 comments
Closed

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

ChristofFritz opened this issue Nov 25, 2022 · 9 comments

Comments

@ChristofFritz
Copy link

ChristofFritz commented Nov 25, 2022

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

@cuadllop
Copy link

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

@ChristofFritz
Copy link
Author

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

@nagash77
Copy link
Contributor

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 nagash77 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2022
@singeryo
Copy link

singeryo commented Feb 6, 2023

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 ?

@dkurucz
Copy link

dkurucz commented Feb 13, 2023

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!

@rspu
Copy link

rspu commented Apr 26, 2023

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.

@mschile
Copy link
Contributor

mschile commented Apr 26, 2023

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

@gilluminate
Copy link

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

@Yihao-G
Copy link

Yihao-G commented Feb 20, 2024

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants