https://cypress.io logo
one file and log in a same website with two accoun...
# i-need-help
l
My testing line starts from creating a new client account > login as a new client and create a new project > client logout > create a new employee account > login as a new employee and edit personal information > employee logout > client login > add this employee into the project In my imagination, when running a cypress file, it will be like a user open a new browser, so the tokens will be shared. Therefore, the only way to switch identities is to frequently log in and log out. And one cy.description will open a new browser, so my question is: Is it possible to run a cypress file but log in with two different accounts?
e
Yes. Each
it
is essentially a new session so you can login in with different users. To be safe you can always add a
cy.clearLocalStorage
in a
beforeEach
to prevent any possible session issues.
l
Could you please elaborate further? I do not know what should be chained off when using Each. My idea is still working like log in and out a lot 😅 describe( 'edit information',()=>{ afterEach(() => { cy.logout() cy.clearLocalStorage }) it('client',()=>{ //login and create a new project }) it('employee',()=>{ // login and edit personal information }) it('client login',()=>{ //login and add this employee into the project }) })
e
Copy code
beforeEach(() => {
  cy.clearLocalStorage();
});
Just use that and then run yours
it
should work fine. Unless Im misunderstanding what you are trying to achieve.
l
Thanks for sharing. This is also a good way. I open two different browsers and log in with different accounts when testing manually. This way I don't need to log in and out multiple times. Haha~ I was just thinking about the possibility of working like this in cypress.
m
Cypress automatically clears the data of local storage when it block ends. https://docs.cypress.io/api/commands/clearlocalstorage#:~:text=Cypress%20automatically%20clears%20all%20local,or%20test%20isolation%20is%20disabled. You don't even need to use cy.clearLocalStorage. Just a tip, also to make your login faster, you can save the token and login using that.
l
Thank you~