https://cypress.io logo
I was able to figure this out for you! First, you ...
# e2e-testing
s
I was able to figure this out for you! First, you were right, you didn't really understand what cy.session is doing behind the scenes, specifically understanding that even when your login function is wrapped in the session, you still have to call it at the top of each test (or, in this solution, a beforeEach in the e2e.js file). The first time it's run, it sets your session. Every other time it runs, it runs THE SESSION, not the login process. So, the pattern is as follows: Write your login function as a custom command, making sure that cacheAcrossSpecs = true, and do everything you need for your session. Wrap that command in cy.session. Put that command either directly in your e2e.js OR put it in a login file and import it from commands.js. Call the login in a beforeEach on the e2e.js (so it runs every time after every spec) and that should take care of that!
2 Views