Search code examples
angularintegrationcypress

How to stop re-logins in after each test (Cypress-Angular)?


I don't want it to login in each time I write a test. When I write "it (cypress)" more than once, it goes back and does a re-login, which I don't want it to happen.

It logins, and after the first test pass, it goes on second test but it does a second login to do the "second it" test. How can I stop it?

describe('Integration Tests', function () {
  beforeEach(() => {
    cy.login()
  })
  it('first it', function () {
    cy.get('.css-vj8t7z')
    cy.get('.css-1ep9fjw')
  })
  it('second it', function () {
    cy.get('.css-1ep9fjw')
  })

Solution

  • Here is the solution:

      Cypress.LocalStorage.clear = function (keys, ls, rs) {
        return;
    
    
    describe('Integration Tests', function () {
      before(() => {
        LocalStorage.clear();
        cy.login()
      })
      it('first it', function () {
        cy.get('.css-vj8t7z')
        cy.get('.css-1ep9fjw')
      })
      it('second it', function () {
        cy.get('.css-1ep9fjw')
      })