cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

`cy.visit()` doesn't change the outer(browser) URL when calling it with different subdomains #25518

Open Erenndriel opened 1 year ago

Erenndriel commented 1 year ago

Current behavior

Note: the URLs given below are just placeholders and should not be tested against. Please find any public domain that has subdomains. You can reproduce this with https://docs.cypress.io/ aswell!

Desired behavior

Test code to reproduce

const checkLocalStorageKeys = () => {
  expect(Object.keys(localStorage).length).to.be.gt(0);
};

describe("test Cypress bug for subdomains", () => {
  afterEach(() => cy.wait(500));

  // Preserve the order since the last one despite having `localStorage` values, it won't have it set during the test.
  it(`should visit "docs.cypress.io"`, () => cy.visit("https://docs.cypress.io/"));
  it(`should visit "learn.cypress.io"`, () => cy.visit("https://learn.cypress.io/"));
  it(`should visit "cypress.io"`, () => cy.visit("https://cypress.io").then(checkLocalStorageKeys));
});

Cypress Version

12.1.0

Node version

v19.3.0

Operating System

Windows 11

Debug Logs

No response

Other

Because of this bug/misbehavior me and my team are unable to proceed running our tests in the test env which has URLs with sub-domains.

image

image

AtofStryker commented 1 year ago

Hi @Erenndriel. Thank you for opening an issue. I have been able to reproduce this and it looks like this has been an issue for some time, as least since cypress 9.x.x. What I think is the issue is that we only check for the super-domain to match when changing the iframe's source, even when the difference is in between tests.

What I would expect is each individual test that changes origin to reset top, like your example:

describe("test Cypress bug for subdomains", () => {
  // should set top
  it(`should visit "docs.cypress.io"`, () => cy.visit("https://docs.cypress.io/"));
  // should change top
  it(`should visit "learn.cypress.io"`, () => cy.visit("https://learn.cypress.io/"));
  // should change top
  it(`should visit "cypress.io"`, () => cy.visit("https://cypress.io"));
});

but if these navigations were all in one test, I would not expect them to change top:

describe("test Cypress bug for subdomains", () => {
  it(`should visit "docs.cypress.io", "learn.cypress.io", and "cypress.io" in a single test`, () => {
    // should set top
    cy.visit("https://docs.cypress.io/");
    // should  NOT change top
    cy.visit("https://learn.cypress.io/");
    // should NOT change top
    cy.visit("https://cypress.io");
  });
});

This behavior seems like a bug to me. Going to go ahead and route it to the end-to-end team!

Erenndriel commented 1 year ago

@AtofStryker Hi and thnx for the response! Any news in regards to how prioritized or an estimation whether this bug's fix will be released sooner or later? Me and my team need to know 'cause if it's going to take weeks or months, we cannot afford for such fix to come to fruition and have to resort to buying single domain addresses.

Thnx beforehand and appreciate the effort 🙏

AtofStryker commented 1 year ago

Hi @Erenndriel. My guess is that this is not going to be prioritized anytime soon. My guess would be months unless someone wants to pick this up as an OSS contribution. The good news is it might not be super challenging to fix, but it might be hard to divorce the logic between tests of sub domain changes between tests vs. in general.

mthornton-globality commented 1 year ago

Does anyone have any suggestions as to a workaround for the above?

activedecay commented 3 weeks ago

the only workaround that I have is using my angular app's functionality to change the route by invoking clicks on buttons that implement routerLink. this changes the URL for me. your mileage may vary.