Restore state of the page in Cypress

  Kiến thức lập trình

I have encountered the following problem.
In the test I need to:

  1. save the state-local storage,
  2. log in with a different account, perform the action
  3. log in under the previous account and restore local storage, continue the test.

I use cypress-localstorage-commands plugin to restore local storage.
The problem is that I can’t restore the state within one test.
It gives me an error, localstorage shows that I’m on wrong account. Even if I use login form instead of login function.

But IF I restore the state in a separate test, everything works correctly.
The question is am I clearing the browser state correctly?

cy.saveLocalStorage('cashier');
// Login on 2nd account
cy.clearCookies();
cy.clearAllLocalStorage();
cy.loginWithArgs(login, password, loginURL).then((userData)=>{
cy.setAuthDataArgs(userData.auth.data.access_token, userData.auth.data.refresh_token,userData);
})
cy.visit(url);
// perform actions
// log in previous account
cy.clearCookies();
cy.clearAllLocalStorage();
cy.loginWithArgs(prevname, prevpass);
cy.loginWithArgs('crm2','crm2', varsEnv.loginURL).then((userData) => {
    cy.restoreLocalStorage('cashier');
})
cy.visit(prevulr);

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT