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 session storage workaround is not consistently functioning

See original GitHub issue

Current behavior:

While logging in targeting the User Interface I have to clear session storage because we store route history in there. The first time the test is run and the initial test runner browser is opened, but the session storage is not cleared. Refreshing the test without closing the browser lets the test succeed the second time and any time after that as long as you don’t close the test runner browser window.

I am using the clear session storage workaround by using cy.visit(activeEndpoint, { onBeforeLoad: (win) => { win.sessionStorage.clear(); } });

Desired behavior:

The expected behavior is that session storage is cleared using win.sessionStorage.clear() on the initial firing of my login test allowing me to visit the login page and be able to log. It’s bothersome to have to run the test a few times to get it to succeed.

Steps to reproduce:

describe('Logs In Using the UI', () => {
    beforeEach('Clear session storage', () => {
        cy.visit(url, {
            onBeforeLoad: (win) => {
                win.sessionStorage.clear();
            }
        });
    });
   it('Logs in to url using the UI', () => {
       cy.get(loginSelectors.usernameInput).type('username');
       cy.get(loginSelectors.passwordInput).type('password');
       cy.get(loginSelectors.loginButton).click();
       waitOnLoginXhr();
   });
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

6reactions
shcallawaycommented, Jul 11, 2018

I was under the impression that Cypress clears local storage and cookies (ie session state) before each test. However, I have noticed that since switching to 3.0 we occasionally see session state “leak” between tests, which causes flakiness.

I can provide a link to our (private) dashboard if it helps.

0reactions
jennifer-shehanecommented, Aug 25, 2021

We released cy.session() as an experimental command (set experimentalSessionSupport to true in config) in Cypress 8.2.0. This command can be used to cache and restore cookies, localStorage, and sessionStorage. We especially see this command as being useful for testing Auth flows and recommend giving it a try to replace your existing tests around authentication and login.

If you have any feedback about cy.session() for general UX improvements, new features, or unexpected behavior, please leave your feedback in our Cypress Session Experimental Feedback Discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Session Storage not reset when iFrame closed - Stack Overflow
I have my iframe in its own component which I display styled as a modal popup. When closing the modal I verified that...
Read more >
Window.sessionStorage - Web APIs - MDN Web Docs
The read-only sessionStorage property accesses a session Storage object for the current origin. sessionStorage is similar to localStorage ...
Read more >
Clearing cache has no effect on HTML5 localStorage or ...
Clearing cookies won't always empty the local storage. It depends on the browser. If you want to demonstrate persistence of data after cookies ......
Read more >
Enable consistent experience across sessions using ...
In this article, we'll learn how to use the LoadData() and SaveData() functions to store the session data within the app to avoid...
Read more >
LocalStorage, sessionStorage - The Modern JavaScript Tutorial
Unlike cookies, web storage objects are not sent to server with each request. Because of that, we can store much more. Most modern...
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