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

228
Visualizações
cy.saveLocalStorage is not a function Because this error occurred during a after each hook we are skipping the remaining tests in the current suite:

1

guys. I am very fresh in Cypress. Would like to get your help/advice: 1.For login I used below-mentioned way but I get error of: "cy.saveLocalStorage is not a functionBecause this error occurred during a after each hook we are skipping the remaining tests in the current suite: LoginFunctionality"

And I do not know where to store my credentials. Support->Command.js


let LOCAL_STORAGE_MEMORY = {};

Cypress.Commands.add('saveLocalStorage', () => {
    Object.keys(localStorage).forEach(key => {
        LOCAL_STORAGE_MEMORY[key] = localStorage[key]
    })
})

Cypress.Commands.add('restoreLocalStorage', () => {
    Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
        localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key])
    })
})

Cypress.Commands.add('visitMultipleURL', url => {
    cy.window().then(win => {
        return win.open(url, '_self')
    })
})
import 'cypress-iframe';

In login.spec.js

describe('LoginFunctionality', function () {

    beforeEach(() =>{
        cy.restoreLocalStorage();

        Cypress.Cookies.defaults({
            preserve: /[\s\S]*/,
        })
    })//

    afterEach(() =>{
        cy.saveLocalStorage();
    })

    let href;

    it.only('LoginFunctionality', function () {

        //cy.visit(Cypress.env('url'))
        cy.visit('xxx')
        cy.get('.chakra-stack > .css-1n94901').click()
        cy.contains('Login with xxxx').click()
        cy.url().then((url) => {
            href = url;
            cy.log('href ', href);
        })
    })

    it.only('LoginFunctionality', function () {
        cy.visit(href)
        cy.url().should('include','xxxxx[![enter image description here][1]][1]')//assertion of that we are in this url
        
    })

})

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Something similar happened to me before.

I suggest you debug it by trying the code directly in your test first to check what's happening.

Also, do a console log in LOCAL_STORAGE_MEMORY and see if you have access to its value because cypress does not handle variables the way we would expect it if this was pure javascript (even when it might seem as if it's taking the value)

try

let LOCAL_STORAGE_MEMORY = {anyAttribute: "VALUE"};

To see if you get that attribute from inside the command

Usually that's what my problem was related to.

about 4 years ago · Juan Pablo Isaza Relatório
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