I Have pageObject Login File in which I am creating a session while login
login(username,password){
cy.session( sessionId , () => {
cy.visit( / );
this.getUsername().type(username);
this.getPassword().type(password);
this.getLoginButton().click();
cy.url().should( contain , /inventory.html );
},
{
validate: () => {
cy.url().should( contain , /inventory.html );
}
}
)
}
I have stored username and passwords in cypress.config file in form of objects
env : {
users : {
standard : {
username : "standard_user",
password : "secret_sauce"
},
lockedout : {
username : "locked_out_user",
password : "secret_sauce"
},
problem : {
username : "problem_user",
password : "secret_sauce"
},
glitch : {
username : "performance_glitch_user",
password : "secret_sauce"
}
}
I am calling this page object login function for different username but Cy.session recreates session with same username for evry test
describe( All users , () => {
const login_page = new LoginPage();
const users = Cypress.env("users");
Cypress._.each(users,(user) =>{
it( work for the user , () => {
cy.log(user.username);
login_page.login(user.username,user.password);
});
})
});
Please guide me how can i login everytime with a new user.