I have a web application which I am testing with Selenium and Maven running parallel tests. At the moment, I am defining the login ids for every test. What I need is a solution where I will have a pool of users available to the tests. While the execution runs the tests will pick user ids to login from this pool. Once a parallel test is done the user Id should be released and become available to the next tests. The pool should be monitored and tests should be executed only when one or more users are available so I will avoid failures due to users unavailability.

I am new to this, so I am looking for some ideas / advises how I can implement the above. I am using Java.

1

There are 1 best solutions below

4
pburgr On

You can do this by defining user's availability as boolean. Consider those four classes:

Class to define testUser as a Object:

package theo;

public class testUser {

    public String id;
    public String pwd;
    public boolean availability;

    public String getId() {
        return id;
    }

    public String getPwd() {
        return pwd;
    }

    public boolean getAvailability() {
        return availability;
    }

    public void setAvailability(boolean availability) {
        this.availability = availability;
    }

    public testUser(String id, String pwd, boolean availability) {
        this.id = id;
        this.pwd = pwd;
        this.availability = availability;
    }
}

Class with testUsers:

package theo;

public class testUsers {

    testUser Jessica = new testUser("Jessica", "Jessica's password", true);
    testUser Julie = new testUser("Julie", "Julie's password", false);
    testUser Jane = new testUser("Jane", "Jane's password", true);

    public testUser[] allTestUsers = {
            Jessica,
            Julie,
            Jane
    };
}

Class with test method:

package theo;

public class testMethod extends testUsers {

    public void testWhatever(testUser user) {

        System.out.println("Starting test with " + user.getId() + "'s credentials.");       
        user.setAvailability(false);        
        System.out.println(user.getId() + "'s availability is: " + user.getAvailability());     
        String id = user.getId();
        String pwd = user.getPwd();     
        // load login page, perform login and desired tests
        // ...      
        // possibly logout the user
        // ...      
        System.out.println("Login test finished, going to release user.");

        // and releasing the user
        user.setAvailability(true);

        System.out.println(user.getId() + "'s availability is: " + user.getAvailability());

    }
}

Class to perform tests due to user's availability:

package theo;

import org.junit.Test;

public class testDemo extends testMethod {

    @Test
    public void performTestDueToUserAvailability() {
        for (testUser testUser: allTestUsers) {
            if (testUser.getAvailability()) {
                testWhatever(testUser);
            }
            else {
                System.out.println("User locked, skipping test.");
            }
        }
    }

}

Output:

Starting test with Jessica's credentials.
Jessica's availability is: false
Login test finished, going to release user.
Jessica's availability is: true
User locked, skipping test.
Starting test with Jane's credentials.
Jane's availability is: false
Login test finished, going to release user.
Jane's availability is: true