After updating to Cypress 10.4.0 localStorage and sessionStorage are not populated with part of login happening in cy.origin() and login process fails
See original GitHub issueCurrent behavior
Before Cypress 10.4 update, the test framework had the current workflow:
- In each test, beforeEach runs Commands.login()
- Commands.login() contains the login wrapped inside cy.session to preserve session data
- Inside the cy.session, part of the login is inside cy.origin, because a part of login process is done in secondary domain
- Rest of the steps are done in the initial first domain
Problem with part 4: now after Cypress 10.4 update, when it returns from the secondary domain, it looks like both localStorage and sessionStorage are emptied, thus the test cannot continue without the data stored in both of the storages.
Desired behavior
cy.session() should preserve localStorage and sessionStorage as documented.
Test code to reproduce
import { Commands } from '../support/commands';
beforeEach(() => {
cy.viewport(1412, 937);
cy.log('I run this text and login before every test in every spec file!');
Commands.login(Cypress.env("username"), Cypress.env("password"));
});
…/support/commands.ts
public static login = (username: string, password: string): void => {
cy.session([username, password], () => {
// Visit main page, we are in firstdomain.com
cy.visit(Cypress.env("testUrl"));
// Click the button in the firstdomain that redirects to secondary domain
cy.get(':nth-child(1) > .--span-s-12 > .c-button > .button-container > .button-text').click();
// Commands that need to run in another domain
// Anything that runs in the secondary domain needs to be wrappen inside cy.origin for the test to continue
cy.origin('different.domain.com', { args: [username, password] }, ([username, password]) => {
// Enter login info in secondary domain
cy.get('#email').click();
cy.get('#email').type(username);
cy.get('#password').click();
cy.get('#password').type(password);
cy.get('#next').click();
});
// Now we're redirected back at the original firstdomain.com, so we need to continue commands outside of cy.origin
// PROBLEM: In Cypress 10.4.0 the sessionStorage and localStorage are not preserved at this step, at least it looks like that from DevTools
// Select company from list, which can't be found in 10.4 because it's not in the correct page
cy.contains("72", { timeout: 6000 }).click();
// Do other stuff in firstdomain.com..
// Session ends
});
};
Cypress Version
10.4.0
Other
This worked fine until 10.3.2
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:18 (9 by maintainers)
Top Results From Across the Web
Changelog - Cypress Documentation
Testing multiple origins in a single test with the new cy.origin() command. Caching and restoring cookies, localStorage , and sessionStorage between tests ...
Read more >cypress-io/cypress - Gitter
Hi, I'm looking into skipping through the login parts of all our tests, through api-calls. I got the idea from watching your talk...
Read more >Local storage not clearing during Cypress test - Stack Overflow
There is some Session Storage that you're not clearing. The simplest way would be before(() => { cy.clearLocalStorage('bluelibs-token') cy.
Read more >Cypress Local Storage Commands - YouTube
If you want to preserve local storage between Cypress tests or disable local storage to check error handling. You can extend Cypress Cy...
Read more >Use LocalStorage From Cypress Test To Set Initial Data
We can set the initial data to be read by the application by using localStorage from the Cypress test. We can then verify...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AtofStryker I can happily confirm that after updating 10.8.0 the login is now working and cookies/storages are preserved.
Was the fix this item on the release notes? “Fixed an regression introduced in Cypress 10.3.0, and further exposed in 10.4.0, that omitted same-site cookies when the URL Scheme, Domain, and Top Level Domain matched, but the ports are different (i.e. same-site). Fixes #23132.”
I believe the issue can be closed, hopefully not introduced again 😃
@Wilhop We released some cookie changes today with
10.8.0
. Are there any improvements with your issue? My guess is thegetCookie
issues might still persist, but hopefully correct cookies are now being sent from the proxy server.