I am playing around with Cypress for e2e testing and want to execute login flow on each of the spec file. I know that we can do it by storing it locally by writing custom commands like this :
Cypress.Commands.add('login', ()=> {
cy.request({
method : 'POST',
url : 'url',
...
}
}).then((resp) => {
window.localStorage.setItem('jwt',resp.body.user.token)
})
})
and then calling this function in our actual spec file.
But with my application, there are multiple api calls to be made one after the other in order to actually land up inside the application. How can I achieve this in custom commands? My application actually takes username and password in step-1, and then from the jwt received it executes another api call, and then a final one. I want to store the last jwt value so that I can continue with the rest of the application.