How to keep token login status in multiple test cases?
Allen2898168 opened this issue · comments
before(() => {
cy.login_request(LoginUrl, LoginMethod, LoginHeaders, LoginBody)
}).its('headers')
.then((headers)=>{
const csrf = headers['x-auth-token']
cy.log(csrf)
})
})
I have obtained the token, but the subsequent UI test cases, how to keep the login status, support to directly open the web page, do not need to log in again
I look forward to your reply
Please look at our https://github.com/cypress-io/cypress-example-recipes#logging-in-recipes again - if you use begin
hook it runs once. The second test will have its window and cookies cleared automatically. Thus you need to set the cookie / header again before each test. Something like this
let csrf
before(() => {
cy.login_request(LoginUrl, LoginMethod, LoginHeaders, LoginBody)
.its('headers')
.then((headers)=>{
csrf = headers['x-auth-token']
})
})
beforeEach(() => {
cy.log(csrf)
// set the csrf or cookie
})