question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clear sessionStorage in between tests

See original GitHub issue

Currently we clear cookies and localStorage but somehow we missed automatically clearing sessionStorage as well.

This needs to be added, and we likely need to add a new cy.clearSessionStorage API command.

Thanks to @abadstubner for finding this one.

Currently as a workaround you can manually clear sessionStorage like this:

cy.window().then((win) => {
  win.sessionStorage.clear()
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:124
  • Comments:29 (10 by maintainers)

github_iconTop GitHub Comments

26reactions
brian-manncommented, Jan 11, 2018

clearing sessionStorage are just synchronous methods you call on the window.

cy.visit('...', {
  onBeforeLoad: (win) => {
    win.sessionStorage.clear()
  }
})

Read https://docs.cypress.io/api/events/catalog-of-events.html as well.

17reactions
single-stop-justincommented, Aug 14, 2020

When will cy.clearSessionStorage be implemented?

None of the workarounds have worked here. I am even clearing session store beforeEach and onBeforeLoad. The result is tests randomly passing, definitely a race condition.

One time the entire suite passes. The next time one test fails. The next time three fails. The next time two different tests fail…

Read more comments on GitHub >

github_iconTop Results From Across the Web

session - Cypress Documentation
When running Cypress in "open" mode, you can explicitly clear all spec and global sessions and re-run the spec file by clicking the...
Read more >
Why do I need to explicitly clear sessionStorage when using ...
The controller stores the current page in $sessionStorage.pagination. If I don't explicitly clear the session storage between tests, ...
Read more >
How to clear session storage data with specified session ...
We can get specified session storage using the getItem() method. We can clear the session storage by using the clear() method.
Read more >
How to preserve localStorage between Cypress tests
Cypress by default clears localStorage between tests, which may be a problem when you are trying to test features related to it.
Read more >
How to clear localStorage using selenium and webdriver
I have confirmed by testing both the Firefox and Chrome drivers, that upon instantiating the driver, the browser's localStorage is empty. This is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found