cy-api icon indicating copy to clipboard operation
cy-api copied to clipboard

cy.visit() loads blank page on an app using the hash router

Open aubincc opened this issue 2 years ago • 5 comments

Inspired from https://github.com/cypress-io/cypress/issues/27050

Current behavior

If my Web app uses the hash router, I cannot seem to be able to visit the same url twice.

If I have Cypress.env("baseUrl") = "https://my-example-app.com/"

I cannot have cy.visit("#/login") or cy.visit("https://my-example-app.com/#/login") in the first and the second it().
I cannot have it in a beforeEach() hook with two tests either.

However cy.visit("") and cy.visit("https://my-example-app.com/") work well, even though I am redirected by the page to #/login immediately.

image

Desired behavior

The cy.visit("#/login") in the second it() or second trigger of beforeEach() should load the page correctly.

Test code to reproduce

describe("Visit login page", () => {
  it("Working", () => {
    cy.visit("#/login"); // loads page correctly
    cy.get("img.logo").should("be.visible"); // finds the logo image 
  });
  it("Page is blank", () => {
    cy.visit("#/login"); // loads a blank page
    cy.get("img.logo").should("be.visible"); // does not find the logo image 
  });
});

Pivot point

I have this behaviour when cypress\support\e2e.(ts|js) contains import "@bahmutov/cy-api";.

This problem is gone when I comment it out.

Cypress Version

v12.14.0

Node version

v18.16.0

Operating System

Windows 11 Pro 22H2 Build 22621.1702

Debug Logs

No response

Other

No response

aubincc avatar Jun 19 '23 13:06 aubincc

Do you have baseUrl set in your config? Do you have fallback route in your backend?Sent from my iPhoneOn Jun 19, 2023, at 09:57, Nicolas AUBIN @.***> wrote:

Inspired from cypress-io/cypress#27050

Current behavior If my Web app uses the hash router, I cannot seem to be able to visit the same url twice. If I have Cypress.env("baseUrl") = "https://my-example-app.com/" I cannot have cy.visit("#/login") or cy.visit("https://my-example-app.com/#/login") in the first and the second it().I cannot have it in a beforeEach() hook with two tests either. However cy.visit("") and cy.visit("https://my-example-app.com/") work well, even though I am redirected by the page to #/login immediately.

Desired behavior The cy.visit("#/login") in the second it() or second trigger of beforeEach() should load the page correctly. Test code to reproduce describe("Visit login page", () => { it("Working", () => { cy.visit("#/login"); // loads page correctly cy.get("img.logo").should("be.visible"); // finds the logo image }); it("Page is blank", () => { cy.visit("#/login"); // loads a blank page cy.get("img.logo").should("be.visible"); // does not find the logo image }); }); Pivot point I have this behaviour when cypress\support\e2e.(ts|js) contains import @.***/cy-api";. This problem is gone when I comment it out. Cypress Version v12.14.0 Node version v18.16.0 Operating System Windows 11 Pro 22H2 Build 22621.1702 Debug Logs No response Other No response

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

bahmutov avatar Jun 19 '23 14:06 bahmutov

I will try and find the pivot point where this behaviour comes and goes. I do not have a clue yet, but I will try harder in the next couple of days.

Do you have baseUrl set in your config?

Originally I had the backend url as baseUrl because I use cy.api() a lot.

I have also tried setting the baseUrl to the frontend, but it did not change.

For the moment, this behaviour disappears when I comment out the import of this plugin.

Do you have fallback route in your backend

No

aubincc avatar Jun 19 '23 14:06 aubincc

Ok then I will need a reproducible example to debug this since there could be so many things in your two apps and specs to say anything definitive Sent from my iPhoneOn Jun 19, 2023, at 10:23, Nicolas AUBIN @.***> wrote: I will try and find the pivot point where this behaviour comes and goes. I do not have a clue yet, but I will try harder in the next couple of days.

Do you have baseUrl set in your config?

Originally I had the backend url as baseUrl because I use cy.api() a lot. I have also tried setting the baseUrl to the frontend, but it did not change. For the moment, this behaviour disappears when I comment out the import of this plugin.

Do you have fallback route in your backend

No

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

bahmutov avatar Jun 19 '23 14:06 bahmutov

testIsolation: false seems to be what causes pain


Reproducible example

https://github.com/aubincc/bahmutov-cy-api-testIsolation-false

Lines to fiddle with

aubincc avatar Jun 20 '23 07:06 aubincc

I could try and find a fix, but I do not know where to log what is happening.

I have been looking, but I have no clue. Sorry I tried

aubincc avatar Jun 21 '23 06:06 aubincc