samedi 10 avril 2021

Cypress authentication with token not working across other tests

I am running my first authentication test in Cypress, the code executes and passes successfully. However when the test starts I can see that I am already logged in via authentication as part of the "Before clause" but when the test 1 executes I am no longer logged in...

Can somebody please point out whether I am incorrectly authenticating or is there another way of authenticating the user prior to all test execution.

Note: I have replaced the website and the token to remove all sensitive data.

Testfile:

     /// <reference types="cypress" />
    
    const token = '6232i3232j3hg23g2jh3gj2hg3jg2jg3j23'
    


    describe('Basic authentication Test', () => {
    before(() => {
        cy.then(() => {
            window.localStorage.setItem('__auth_token', token)

        })
    })
    

    beforeEach(() => {
     
        cy.then(() => {
            window.localStorage.setItem('__auth_token', token)
        })
        cy.viewport(1280, 720)
        cy.visit('https://youtube.com')


    })

    it('Test 1 - Should load webpage 1 correctly', () => {

      //  cy.visit('https://youtube.com/profile1/html')
          cy.get('div')
     //   cy.pause()

    })
})

Aucun commentaire:

Enregistrer un commentaire