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

231
Views
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 answers
Answer question

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 Report
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!