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

Visits with a hash (#) where you are visiting the same base url will not re-visit the page. #17479

Closed
nishio opened this issue Jul 26, 2021 · 5 comments
Labels
stage: awaiting response Potential fix was proposed; awaiting response

Comments

@nishio
Copy link

nishio commented Jul 26, 2021

Current behavior

When I use cy.visit('/'), the page is re-visited and states are reset. (see code A, C)
However, when I use cy.visit('/#blank') (URL with hash), the page is not re-visited and states are retained. (see code B)

It cause unexpected influence between tastcases.

Desired behavior

cy.visit should always visit the specified page.

Test code to reproduce

  it("main", () => {
    cy.visit("/");
    cy.window().its("x").should("eql", undefined);
    cy.window().then(window => {window.x = 1})
    cy.window().its("x").should("eql", 1);

    cy.visit("/");
    cy.window().its("x").should("eql", undefined); // (A)
    cy.window().then(window => {window.x = 2})
    cy.window().its("x").should("eql", 2);

    cy.visit("/#blank");
    cy.window().its("x").should("eql", 2);  // (B)

    cy.visit("/");
    cy.window().its("x").should("eql", undefined);  // (C)
  });

Cypress Version

8.0.0

Other

It may related to #225

@jennifer-shehane
Copy link
Member

I believe this is expected behavior with hashes - to not revisit the page since it's just traversing to a hash. Go to https://docs.cypress.io/guides/overview/why-cypress then click on a menu on the righthand side, the page does not reload to go to https://docs.cypress.io/guides/overview/why-cypress#Setting-up-tests

@jennifer-shehane jennifer-shehane added the stage: awaiting response Potential fix was proposed; awaiting response label Jul 26, 2021
@nishio
Copy link
Author

nishio commented Jul 26, 2021

It is expected behavior of browsers, not test runners. We need to isolate each tests.

@nishio
Copy link
Author

nishio commented Aug 17, 2021

Are there any way to force browser reload? I am developing single page application whose all URLs have a hash. I need methods to isolate each test cases.

@JessicaSachs
Copy link
Contributor

JessicaSachs commented Aug 18, 2021

If you need to force route reloading, you can make a new test (this will destroy the entire iframe) or you can use cy.reload which is defined here after setting the hash with cy.visit(...).

cy.reload basically calls document.location.reload under the hood.

it("main", () => {
  cy.visit("/#blank")
  cy.window().then(window => {window.x = 2})
  cy.window().its("x").should("eql", 2);

  cy.visit("/").reload()
  cy.window().its("x").should("eql", undefined);  // (C)  
});```

@nishio
Copy link
Author

nishio commented Aug 20, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: awaiting response Potential fix was proposed; awaiting response
Projects
None yet
Development

No branches or pull requests

3 participants