May 2013
« Apr   Jun »

Selenium Grid Configuration [ Hub and Node Communication]

This is one of the special technology Edition targeted to Testers which is far away from Sys-Admin handy tasks. Recently I had an opportunity to commit this job through Jenkins(a Continuous Integration system). So Ihave to learn it and have no idea about this unit test, Selenium server at initial time. Then gradually I’m started to eating up Google for more detailed and finally got succeeded in understanding the working principle of Selenium.. is a Long story but simple in technical terms to setup.

This blog help to get it worked

This chapter will be useful for QA team those are working on a long term based projects. My Initial questions are listed one by one,

a. Unit Tests : This is some automation tests which is the same way a user work with web application. We can record our browser actions using the browser plugins like Selenium IDE or Selenium Builder. Selenium IDE is free firefox extension which allow you to record, edit any browser action and you can export those action as preferred format of our unittest platform. There are certain Unitest frame available for diff. platform such as PHPUnit for php , Jnuni for Java etc.

b. Selenium Server :- This is the most confused term. Actually selenium server does work with standalone mode for most of the purpose. It is commonly called Selenium GRID which helps to run the browser based test which created through the test framework like JUNIT or PHPUNIT in enterprise level.

Selenium Server has two major role,

a. Selenium server as a Standalone (For independent machine)
b. Selenium as Grid 2 sever [Hub +Node model] (for distributed machines)

We can setup the selenium server either in HUB or Node. If you want to run the test on your laptop/desktop, you may need to start Selenium as Hub. Hub can use only local machine resource unless the node are registered in it. A default Selenium server can have 11 browsers contains 5 Firefox, 5 Chrome, 1 Internet Explorer. This does not mean you can have all these browsers installed when Selenium starts, It’s just provide the support drivers for 11 web browsers mentioned above.

How to start Selenium standalone server

-bash-3.2# java -jar selenium-server-standalone-2.32.0.jar
May 3, 2013 12:42:02 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
00:42:03.135 INFO - Java: Sun Microsystems Inc. 20.1-b02
00:42:03.158 INFO - OS: Linux 2.6.18-238.el5 i386
00:42:03.186 INFO - v2.32.0, with Core v2.32.0. Built from revision 6c40c18
00:42:03.632 INFO - RemoteWebDriver instances should connect to:
00:42:03.634 INFO - Version Jetty/5.1.x
00:42:03.646 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
00:42:03.658 INFO - Started HttpContext[/selenium-server,/selenium-server]
00:42:03.659 INFO - Started HttpContext[/,/]
00:42:03.686 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@b8deef
00:42:03.687 INFO - Started HttpContext[/wd,/wd]
00:42:03.692 INFO - Started SocketListener on
00:42:03.692 INFO - Started org.openqa.jetty.jetty.Server@1ef9157

Once it’s started successfully, you will get the browser windows like this,

Now you can run the tests fro yur desktops.

2. Configuring Selenium Grid 2 as Hub-Nodes

This is a very popular testing environment setup where we can run unit tests against all the browsers which registered to this Hub server. Goal and requirement of this setup are,

a. Can use all the browsers around your Hub machine
b. Test should be initiated/run from HUB server only.
c. It can be implemented only in LAN where you can setup node machine.
d. Required more hardware resources.

If you want to run unit tests on different browsers ( more than 25) Feel free to use SauceLab service. They are providing Selenium plugin (sauce-grid-plugin-1.0.10.jar) to run the test in their web browsers cloud.

Here we go with the Selenium Grid2 implementation.

We need at lease two machine for this Grid setup.

Server IP Role
1. Selenium Hub
2. Node-1 [Linux]
3. Node-2 [ Windows] ( Optional)

Setting up Selenium Hub server []

a. Download the latest selenium server jar file from site. Eg : selenium-server-standalone-2.32.0.jar
b. Move the jar file to Selenium server and Launch the server in Hub mode (java -jar selenium-server-standalone-2.32.0.jar -role hub)

 -bash-3.2# java -jar selenium-server-standalone-2.32.0.jar -role hub
May 3, 2013 2:04:59 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid server
2013-05-03 14:05:01.353:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2013-05-03 14:05:01.488:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2013-05-03 14:05:01.533:INFO:osjs.AbstractConnector:Started SocketConnector@

Verify the Hub is running

You can verify it fro the Hub machine itself http://localhost:4444/grid/console

1. Configuring Selenium Node []

Steps are same for node except of command line parameter for mentioning web driver and Selenium Hub server url. I’ve copied the Selenium jar file and start the Node using the following parameter.

java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub  -port 5566

Output will look like this,

Pls note down the message “INFO – Registering the node to hub :” which stating that you’re connected to HUB 🙂

Hub console will look like this as shown below,

Perfect ! You’re Done !

Again I’m planning to add second Windows Node to this Hub,

Installed JDK library and copied the selenium-server-standalone-2.32.0.jar on machine. So that I can run the tests against Windows platform as well.
start the Node by executing the command

D:\>java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub

Now you can see the Hub server consists of two nodes listed in it. Each node should have registered to this hub in-order to use GRID features. Look at the following picture,

You can now add any number of Nodes in this hub. Now you need to concentrate on unit test either using PHPUnit or JUnit projects. Also you may get help from creating selenium scrip (base model) from Selenium IDE Firefox extension easily.

Here is the exact diagram of Selenium Grid2 is

Another diagram is here

Important : You may need to start nodes in GUI in Linux. Otherwise tests will not be succeeded.

Building Sample JUnit Test
I’ve created a sample JUnit test script which open and navigate the RDS category in a short while. It can be download over here and folder structure will be like this.

-bash-3.2# pwd
-bash-3.2# tree
|-- bin
|   |-- com
|   |   `-- hubnodetest
|   |       `-- HubNodeCommunication.class
|   |-- junit-4.10.jar
|   |-- selenium-firefox-driver-2.0a6.jar
|   |-- selenium-java-2.32.0.jar
|   |-- selenium-java-client-driver.jar
|   `-- selenium-server-standalone-2.32.0.jar
|-- build.xml
|-- junit
|   `-- TEST-com.hubnodetest.HubNodeCommunication.xml
|-- lib
|   |-- junit-4.10.jar
|   |-- selenium-firefox-driver-2.0a6.jar
|   |-- selenium-java-2.32.0.jar
|   |-- selenium-java-client-driver.jar
|   `-- selenium-server-standalone-2.32.0.jar
`-- src
    `-- com
        `-- hubnodetest
8 directories, 14 files

You may need to necessary library files (Junit,firefox driver, selenium server standalone) to be copied under lib folder. The important file is “” I’ve created for running my UX test.

Selenium Node configuration in JUnit

See the below lines and you can see that you are mentioning the Node where the target test to be executed. In this example, I’m using the firefox to run on the node and this Junit test should be executed only from the HUB server itself.

 public void setUp() throws MalformedURLException {
    baseUrl = "";
    nodeUrl = "";
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    driver = new RemoteWebDriver(new URL(nodeUrl), capability);

How do run my sample JUnit test

You may download this file and open this project through latest Eclipse IDE. Then add/write your selenium scripts and finally build a package for ANT. So that you can automate this testing using any of Continuous Integration system like I used Jenkins.

Once you modified the Unittest file, you may need to rebuild the package using ant build command. To run your UXTest, execute ant your test_name. My JUnit project output will be like this,

-bash-3.2# ant HubNode
Buildfile: /root/HubNode/build.xml
    [junit] Running com.hubnodetest.HubNodeCommunication
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 20.168 sec
Total time: 22 seconds

Note : you should ensure that Selenium node started from graphical User interface as the browser need to run. When you run the ANT script, you can see that Firefox browser will automatically fired up and navigate through menu I’ve listed in script.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>