Running Tests on Selenium Grid 2.0 with Web Driver

In this section, you will use one computer as a hub and as a node to run a test with Web Driver on Selenium Grid 2.0.


Step 1: launch the hub with the command line below. 

C:\Selenium Server>java -jar selenium-server-standalone-2.39.0.jar -role hub

Step 2: launch the node with the command line below. 


C:\Selenium Server>java -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5566


Step 3: verify Selenium Grid Hub console to make sure that hub and node are running. Open a browser and type the URL "http://localhost:4444/grid/console".


Step 4: on Eclipse, create a test project and write scripts. Create a Java project named "SeleniumGridWithTestNG". Add a package named "com.seleniummaster.seleniumgridtestng" and add a TestNG class. Make sure that selenium-server-standalone-2.39.0.jar and selenium-driver.jar file are added to the build path. If TestNG plug-in has not been installed, you can install it from the Eclipse market place. 


SeleniumMasterLoginTest.Java source code

package com.seleniummaster.seleniumgridtestng;
import static org.testng.AssertJUnit.assertEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class SeleniumMasterLoginTest {
WebDriver driver;
String baseUrl, nodeUrl;
  public void LoginTest() {
    driver.findElement("login_login_password")).sendKeys("XXXXXXX")//here password is omitted
     for (int second = 0;; second++) {
      if (second >="timeout");
        assertEquals("Online users", driver.findElement(By.cssSelector("#sb-onlineusers > h3")).getText());
      catch (Exception e) {}
  public void setup() throws MalformedURLException {
 DesiredCapabilities capability=DesiredCapabilities.firefox();
 driver=new RemoteWebDriver(new URL(nodeUrl),capability);

  public void afterTest() {


Step 5: run the project as TestNG Test. 

Test result showed that test passed. In this test:

  • DesiredCapabilites is used to set the type of browser and OS that we will automate
  • RemoteWebDriver is used to set which node (or machine) that our test will run against.