Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda