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
})
})