Tuesday, 29 January 2013

Selenium GRID with WebDriver

Selenium Grid is a tool that dramatically speeds up functional testing of web-apps by leveraging your existing computing infrastructure. It allows you to easily run multiple tests in parallel, on multiple machines, in an heterogeneous environment.

Stop waiting hours to get the results of your web acceptance builds! Selenium Grid transparently distribute your tests on multiple machines so that you can run your tests in parallel, cutting down the time required for running in-browser test suites. This will dramatically speeds up in-browser web testing, giving you quick and accurate feedback you can rely on to improve your web application.

How to Configure Selenium GRID

1) Download latest Selenium-server-standalone-2.25.0.jar
2) Download TestNG (should have TestNG framework)
3) Download ChromeDriver.exe

Test Script

package testNG;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.thoughtworks.selenium.Selenium;

import junit.framework.Assert;

public class Google {

 private Selenium selenium;


 public void beforeClass(String browser,String port){
  DesiredCapabilities capability= new DesiredCapabilities();
  try {
   WebDriver driver= new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capability);
   selenium = new WebDriverBackedSelenium(driver, "http://www.google.com");
  } catch (MalformedURLException e) {
 public void search() {
  selenium.type("id=lst-ib", "testing");
  selenium.click("//input[@value='Google Search']");

 public void afterClass(){

Create the TestNG.xml file by copying the below code: 

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="tests"

    <test name="Selenium TestNG - 1">
        <parameter name="browser" value="firefox" />
        <parameter name="port" value="4444" />
            <class name="testNG.Google" />
    <test name="Selenium TestNG - 2">
        <parameter name="browser" value="chrome" />
        <parameter name="port" value="4444" />
            <class name="testNG.Google" />


Now run the Test Suite by right clicking the TestNG.xml file from eclipse

Just Before running the script you should run Selenium-Grid server

Selenium-Grid server

For Hub:
java -jar selenium-server-standalone-2.25.0.jar -role hub

For a firefox based node:
java -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556 -browser browserName=firefox

For Google-Chrome based node:

java -Dwebdriver.chrome.driver="C:\.......\chromedriver.exe" -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5555 -browser browserName=chrome


  1. it is not connecting to the remote computer what to do,it is not showing any issue also please help me out from this

  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

  3. Thanks for the great information in your blog Selenium Training in Chennai

  4. Selenium is used in many IT companies due to its numerous advantages compared to other automation testing tools in the market. There is massive demand for automation testers to validate software and mobile applications across the world. Taking Selenium Course in Chennai
    will assist aspirants to enter automation testing industry!!!

  5. I have been reading your blog posts. You blog posts are awesome. They provide good and extremely information which is more valuable. Online selenium training in chennai is predominant famous for Selenium Automation Training and how to get the necessary knowledge about the technology and implement it in a effective way.