English 中文(简体)
I want to login everytime with new user but Cy.session recreate session with same user again
原标题:

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.

问题回答

If you take a look at the examples there s an option to base the session id on the incoming parameters.

So instead of

cy.session( sessionId , () => {

using

cy.session([username, password], () => {

will provide a unique session id for each combination of username and password.

You could also use cy.session(username, () => { but including the password allows you to run tests for same user but with both valid and invalid passwords.

Each session data is stored separately for each login.





相关问题
Cypress 在自定义命令上无法工作。

我在support/header.js下创建一个新文件,用于重复检查头文件,我还将它导入到e2e.js中。 header.js Cypress.Commands.add(checkHeader, () => {     //* FAVICON     it(Check Favicon 1,(...

value of hidden element is not changed

I have the following checkbox element <div _ngcontent-qcu-c225="" class="checkbox-section terms-of-sale"><div _ngcontent-qcu-c225="" class="checkbox-wrapper&...

热门标签