I have a problem as below. I need to test login functionality, but facing with this problem.
I looked for some solutions here in Stackoverflow as well but did not help any of them. please look at it and kindly share your thoughts. Thank you!
describe("LoginFunctionality", function () {
beforeEach(() => {
cy.restoreLocalStorage();
Cypress.Cookies.defaults({
preserve: /[\s\S]*/,
});
});
afterEach(() => {
cy.saveLocalStorage();
});
let href;
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");
});
});
it.only("LoginFunctionality", function () {
cy.visit("xxx");
cy.get(".chakra-stack > .css-1n94901").click();
cy.contains("Login with aaaa").click();
cy.url().then((url) => {
href = url;
cy.log("href ", href);
});
});
it.only("Verification of login", function () {
cy.visit(href);
cy.url().should("include", "bbbb"); //assertion of that we are in this url
});