I am trying to automate a website(https://opensource-demo.orangehrmlive.com/index.php/auth/login) I am using Cypress+cucumber
The use case is
1.Login to the application
2.Click on Admin module
3.Click on Add Employee.
However after step 2 the page goes back to the application login page.
I know that cypress clears cookies after each step.
For that i have whitelisted the session id but still its not working.
My question how do we preserve the session state after login so that i can pursue the further steps.
Below is my step defintion file and screenshot.
Step Definition
import { Given,When,Then} from 'cypress-cucumber-preprocessor/steps';
import LoginPage from '../../support/Pages/LoginPage';
import User_AddPage from '../../support/Pages/User_AddPage';
before(() =>
{
Cypress.Cookies.defaults({
whitelist: "token"
})
beforeEach(() => {
Cypress.Cookies.preserveOnce('token');
})
})
Given('I open login page',()=>{
cy.visit("https://opensource-demo.orangehrmlive.com/index.php/auth/login");
})
When('I fill username with {string}',username=>{
cy.get("#txtUsername").type(username);
})
When('I fill password with {string}',password=>{
cy.get("#txtPassword").type(password);
})
And('I click on submit login',()=>{
cy.get("#btnLogin").click();
})
Then('I should see homepage',()=>{
cy.get("h1").contains("Dashboard");
})
Given('I have logged into system',()=>
{
cy.get("a").contains("PIM").should("be.visible");
})
When('I click on Add Employee link',()=>
{
cy.get("a").contains("PIM").click();
cy.get("menu_pim_addEmployee").click();
})
