ISTQB Certified Software Test Engineer

Thursday, March 29, 2012

Running a Selenium Script Parallelly using Web Driver

If we want to run a Selenium Script across multiple machines parallelly we are using Selenium Grid.
Using Selenium web driver we can achieve this parallel execution with the help of Remote Web driver class and starting Standalone jar on the remote machine(remote machine may be your local some times).
But with this approach you can run the script in multiple browsers in the same
The prerequisites to implement this using web driver are
1.Browsers to be installed in the machine
2.Standalone Selenium Server jar has to be started.
Here is the sample code

import static org.junit.Assert.assertTrue;


import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class GoogleTest {

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

DesiredCapabilities browsers[] ={DesiredCapabilities.firefox(),DesiredCapabilities.internetExplorer()};

for(DesiredCapabilities capabilities :browsers){

System.out.println("Executing Google Test in"+capabilities.getBrowserName());
driver =new RemoteWebDriver(new URL(""), capabilities);

WebElement element = driver.findElement("q"));
System.out.println("Page title is: " + driver.getTitle());




  1. Hi Kumar,

    I read your blog, here you hav mentioned that if we want to un a Selenium Script across multiple machines parallelly
    we can use Selenium Grid.

    I am actually trying to acheieve similar things where I need to distribute my test suite(100 tcs) to multiple machine for the execution and i am looking for parallel execution.
    As mentioned I have started standalone jars on all of my virtual machines.

    Can you please clarify on what code changes will be needed to redirect it to different machines.
    I am using selenium wbdriver with junit.

    Your help is appreciated..

  2. You have to make one machine has Hub,and others as nodes registering to the hub.Then you have to specify your test cases(Name of the test suite) in xml file

  3. Hi,

    I want to do above things in perl. Please help in this?


  4. does not works..m getting a exception "java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map" in new remote driver line..Please help.