Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda