cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

cy.url() is an empty string after a redirect

Open that-ambuj opened this issue 1 year ago • 0 comments

Description

When I'm testing the login flow via keycloak, the webpage would redirect to a url on localhost and when I try to get the current url using cy.url(), I'm getting an empty string.

URL of Issue(s)

N/A

Steps to replicate

  1. Start an oauth login flow, specifically keycloak.
  2. Use the correct username and password.
  3. Expect to be redirected to a callback url on your local/test server.
  4. Get redirected to an actual page like /home. Or manually call cy.visit('/home').
  5. Test that the cy.url() contains /home.

Browser

Chromium 129

Device

  • [X] PC
  • [ ] Mac
  • [ ] iPhone
  • [ ] iPad
  • [ ] Android Phone
  • [ ] Android Tablet

Additional Information

The test body:

    const email = Cypress.env("username"),
      password = Cypress.env("password");

    cy.visit("/login");

    cy.get("#username").type(email);
    cy.get("#password").type(password);

    cy.contains("Sign In").click();
    cy.visit("/console");

    cy.url().should("match", /.*(\/console|\/teamspace\/create).*/);

Here's the screenshot starting from last third line of the test.

image

that-ambuj avatar Oct 22 '24 12:10 that-ambuj