abundant-hydrogen-26466
08/22/2022, 9:40 PMlet LOCAL_STORAGE_MEMORY = {};
Cypress.Commands.add("saveLocalStorage", () => {
cy.window().then(window => {
Object.keys(window.localStorage).forEach(key => {
LOCAL_STORAGE_MEMORY[key] = window.localStorage[key];
});
});
});
Cypress.Commands.add("restoreLocalStorage", () => {
cy.window().then(window => {
Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
window.localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
});
});
});
put that into your commands.js, and then at then at the top of your tests after your describe( and before your first it( test, call it this way:
beforeEach(() => {
cy.restoreLocalStorage();
});
afterEach(() => {
cy.saveLocalStorage();
});