Here are the general description of what you should do:

  1. Set up SeleniumGrid hub
  2. Set up nodes within different you would like to your tests
  3. Isolate your test code within a separate method (of course it is better to use test frameworks like JUnit or TestNG). Your test method should take WebDriver as a parameter because you will have to re-instantiate drivers for different environments.
  4. Where you will call your test code you need to loop through your environment configurations which you will define via DesiredCapabilities class, create a RemoteWebDriver with those capabilities and call your test method sending your new WebDriver there.

This is basically how you will achieve running one test against several different environments.

So the code would look approximately like:

public static void main(String[] args) throws Exception {

    List<Environment> envs = new ArrayList<>();
    envs.add(new Environment(Platform.LINUX, BrowserType.CHROME));
    envs.add(new Environment(Platform.WINDOWS, BrowserType.CHROME));
    envs.add(new Environment(Platform.WINDOWS, BrowserType.EDGE));

    for(Environment env: envs){
        DesiredCapabilities caps = new DesiredCapabilities();
        WebDriver driver = new RemoteWebDriver(new URL("YOUR_URL"), caps);


Where YOUR_URL is the URL of your SeleniumGrid hub and test(driver) is a method where you put all your test code. This code also uses one custom class that is defined as shown below:

public class Environment {

    Platform platform;
    String browserType;

    public Environment(Platform platform, String browserType) {
        this.platform = platform;
        this.browserType = browserType;

    public Platform getPlatform() {
        return platform;

    public String getBrowserType() {
        return browserType;

This approach lets you add new environments or remove ones that are not required any more.

Source link


Please enter your comment!
Please enter your name here