DEV Community

Discussion on: How to preserve localStorage between Cypress tests

Collapse
 
gsaran profile image
gsaran

Hey!
No I couldn't find a way to accomplish that.

When I ran cypress run --browser chrome --headed, I observed that new browser (incognito) window was opening for each test file. Although I was doing cy.saveLocalStorage, local storage was cleared when the browser window was closed.

So I re-organized my tests so that I can test multiple related scenarios as part of one test file, logging in the start & logging out in the last test. Within each test file I do login & logout process & that's working fine.

Thread Thread
 
javierbrea profile image
Javier Brea

Hi @gsaran and @geabby ,
The version v2.2.0 of the plugin already supports preserving localStorage across spec files. The only requirement is to install the plugin's Node events, you can checkout its installation docs for further info.

Thread Thread
 
panoshlk9 profile image
panoshlk9

That's brilliant. I was looking for that for a long long time. Thanks so much