Hi everyone, I am having a strange issue with the ...
# help
h
Hi everyone, I am having a strange issue with the
cy.session
command I don't explicitly logout the user between tests from the same spec file (I am still using Cypress version 9.7.0) and the login credentials that are passed to the session command are different than the previous ones (I see it in the command logs as well). However the command proceeds to the
validate
method to check if the session is valid, even though the user credentials were different. In the
validate
method I use
expect().to.be.false
type of validations to check if the token is still valid and since we do have a valid token it proceeds to use the previous user instead of logging in with the new one. Has anyone encountered such an issue and how did you handle it?
**UPDATE**: It seems that when
cy.session
caches the user (with the new username password combination) for the first time, it works, but in the second test when it restores the session data based on the existing cached ID it uses the session data of the previous user
**SOLUTION**: I actually found what was the issue and thought I share it here before closing the thread: I am using the
cypress-localstorage-commands
plugin for restoring the local storage data in the
validate
method of
cy.session
so the session can be correctly validated in our application. I was not passing an argument for a
snapshotName
when saving and restoring the local storage data which lead to incorrect data being restored. Adding the
snapshotName
value in the restore and save commands resolved this issue
3 Views