cypress: 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
Current 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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 18 (9 by maintainers)
@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 thegetCookieissues might still persist, but hopefully correct cookies are now being sent from the proxy server.