I am working on managing the session cookie for each test case by setting it in beforeEach() and afterEach() block.
Using the below custom session command in C:\cypress\support\commands.js
Cypress.Commands.add('saveSessionStorage', () => {
Object.keys(localStorage).forEach(key => {
LOCAL_STORAGE_MEMORY[key] = localStorage[key];
});
});
Cypress.Commands.add('restoreSessionStorage', () => {
Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
});
});
And imported in cypress/Support/Index.js
import './commands'
In test.js file used custom commands as below
beforeEach(() => {
cy.restoreSessionStorage()
});
afterEach(() => {
cy.saveSessionStorage()
});
But I am getting the below error while implementing the custom commands such has cy.restoreSessionStorage() & cy.saveSessionStorage() in test.js file as below
Property 'restoreSessionStorage' does not exist on type 'cy & EventEmitter'.ts(2339)
and
Property 'saveSessionStorage' does not exist on type 'cy & EventEmitter'.ts(2339)
What could be the problem? Please help