Hey, I have the following code for cy.session and ...
# help
l
Hey, I have the following code for cy.session and Auth0. Wondering if I'm using cy.session correctly here. My thinking is after the initial login, I should be able to use the existing session completed in the beforeEach for subsequent tests. Is this wrong or am I missing something? I'm also running into an issue with tests on chrome being flaky, sometimes I'm able to successfully login to my app and view the dashboard, other times I get redirected again to login
Copy code
// commands.js
Cypress.Commands.add('login', (email, password, { cacheSession = true } = {}) => {
  const args = { email, password }
  Cypress.log({
    name: 'loginViaAuth0',
  });
  const login = () => {
    cy.visit("/auth/login")
    cy.origin('https://myDomain.us.auth0.com', {args}, ({ email, password }) => {
      cy.get('[id=organizationName]').type("orgNameHere")
      cy.get('button').contains('Continue').click()
      cy.get('[id=username]').type(email)
      cy.get('[id=password]').type(password)
      cy.get('[name=action]').click()
  })
  }
  if (cacheSession) {
    cy.session('login', login)
  } else {
    login()
  }
})

// test.spec.ts
describe("home page tests", () => {
  beforeEach(() => {
    cy.login(Cypress.env("auth_username"), Cypress.env("auth_password"));
    cy.visit("/app/dashboard");
  });

  it("should navigate to dashboard manage sets", () => {
    cy.wait(3000);
    cy.get("div").contains("drawer1").click();
    cy.get("div").contains("Manage Sets").click();
    cy.get("p").contains("Select Set to Login");
  });

  it("should navigate to dashboard manage sets", () => {
    cy.wait(3000);
    cy.get("div").contains("drawer2").click();
    cy.get("div").contains("Manage Sets2").click();
    cy.get("p").contains("Select Set to Login2");
  });
});