赛普拉斯无法识别会话ID

时间:2020-07-29 09:19:03

标签: automation cypress

我尽力了,但是我无法保留测试之间的登录会话。

我正在使用以下网站

https://jpetstore.aspectran.com/

我的用例分为以下几个步骤

1。注册

2。登录

3。购买多个类别

4。添加到购物车

5。最终订单

但是在第2步之后,登录凭据不会保留。

下面是我的代码

import LandingPage from "../../support/Pages/Generic/LandingPage"
import FishPage from "../../support/Pages/Fishes/FishPage";
import Fish_Description from "../../support/Pages/Fishes/Fish_Description";
import Fish_Details from "../../support/Pages/Fishes/Fish_Details";
import ShoppingCart from "../../support/Pages/Generic/ShoppingCart";
import RegisterPage from "../../support/Pages/Generic/RegisterPage";
import DogPage from "../../support/Pages/Dogs/DogPage";
import Dog_Description from "../../support/Pages/Dogs/Dog_Description";
import Dog_Details from "../../support/Pages/Dogs/Dog_Details";
import PaymentForm from "../../support/Pages/Generic/PaymentForm";
import Pre_Confirmation_form from "../../support/Pages/Generic/Pre_Confirmation_form";
import Final_Payment_Confirmation from "../../support/Pages/Generic/Final_Payment_Confirmation";
import SigninPage from "../../support/Pages/Generic/SigninPage";

describe('E2E Framework for Cypress Signin,Purchase and Payment',()=>

{
beforeEach(() => {
    cy.restoreLocalStorage();      
});
afterEach(() =>  {
    cy.saveLocalStorage();

});



it('Register Details', () => {
    LandingPage.fetchUrl();      
    LandingPage.goToRegisterPage();
    RegisterPage.clickONRegisterLink();
    RegisterPage.fillDetails();
    
});
it('Sign in to Page', () => {
    SigninPage.submitCredentials();
    
});
it('Purchase Fish from Categories', () => {
    LandingPage.clickONFishCategory();
    FishPage.clickOnFishCategory();
    Fish_Description.Assert_ItemId();
    Fish_Description.click_On_Fish_Details();
    Fish_Details.assertText();
    Fish_Details.add_To_Cart();
    ShoppingCart.returnToMainMenu();
});
it('Purchase Dog from Categories', () => {
    LandingPage.clickONDogCategory();
    DogPage.clickOnDogCategory();
    Dog_Description.Assert_ItemId();
    Dog_Description.click_On_Dog_Details();
    Dog_Details.assertText();
    Dog_Details.add_To_Cart();
    
});
it('Finalise Payment and Assert Order Details', () => {
    ShoppingCart.addToCartAndUpdate();
    ShoppingCart.click_On_Checkout();
    PaymentForm.clickOnContinue();
    Pre_Confirmation_form.clickONConfirm();
    Final_Payment_Confirmation.assertPayment();
    Final_Payment_Confirmation.clickONLogout(); 
});

});

我的Command.js看起来像

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

0 个答案:

没有答案