Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
  })
like image 310
Leo Davtyan Avatar asked Jan 31 '26 03:01

Leo Davtyan


1 Answers

First find out the cookie it used to login.

Then try some code like below

describe('Integration Tests', function () {

  before('login once', function () {
    cy.login()
  }

  beforeEach('keep using the session', function () {
    Cypress.Cookies.preserveOnce("YourCookie")
  })

  it('first it', function () {
    cy.get('.css-vj8t7z')
    cy.get('.css-1ep9fjw')
  })
  it('second it', function () {
    cy.get('.css-1ep9fjw')
  })

read more here

like image 157
Pigbrainflower Avatar answered Feb 02 '26 21:02

Pigbrainflower