Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

390
Views
unable to invoke Cypress custom commands in test files

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

Project Structure: enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!