Clear all localStorage data in Cypress?

Answered
itsbambi asked this question 1 month ago
itsbambi on Mar 27

Before running a new Cypress test, how can I clear all the localStorage data that may be saved in the browser. I want to make sure I have a clean slate on my localStorage before running a new test.

I can remove each individual localStorage item, but that seems overkill.

Any ideas on how to do this?

2 suggested answers
coderguy on Mar 27

Cypress provides a clearLocalStorage() method:

cy.clearLocalStorage()

To prevent shared state from overlapping between tests, Cypress runs this automatically before each test starts. So you should only have to use this inside tests to clear localStorage data.

0 replies
moon_man41 on Mar 27
cy.clearLocalStorage()
0 replies
Answered