Skip to main content

Selenium Grid

Selenium WebDriver is a great and powerful tool when it comes to web test automation. The pros would be appreciated by everybody who test web based applications. However, along with the enlargement of our test base, there are some limitations, and use of single WebDriver implementation on the local machine becomes insufficient. The answer to this problem can be Selenium Grid tool, which distribute tests execution to remote machines.

What is Selenium Grid and why use it? 

Selenium Grid allows you to perform tests execution on different machines, with multiple browsers and operating systems at the same time, regardless of the local development environment. It creates a central hub, which distributes the execution to remote nodes. 

Grid architecture consists of one hub and one or more nodes. Hub is placed on the single machine (local or remote). It is the central point which distributes tests to nodes, depending on configuration and accessibility. Nodes are machines on which the tests are performed. Nodes may differ from each other with operating systems and browsers. 

In this tutorial we will install and set up basic grid configuration on the local machine, consisting of a hub and two nodes. Then we will write simple WebDriver test and execute it on our grid.


First of all – make sure you have java jdk installed. Second – install Selenium Grid 2.0. To do it, simply download Selenium Server jar from seleniumHq website: (look under the section “Selenium-Server (formerly Selenium-RC).” When the installation is complete, unzip the downloaded archive and you’re done!

Setting Up 

We’ll start with the hub configuration. To start selenium grid hub on the local machine, open the terminal, go to the directory where you’ve downloaded selenium-server and run the command (for version 2.45.0):

java -jar selenium-server-standalone-2.45.0.jar -role hub

you should see information about booting services under the default 4444 port:

Open any browser and go to http://localhost:4444/grid/console . You should see empty console of our grid:

The next step is to set up nodes. By default, a single node will have an operating system same as host machine, and will have five Firefox and Chrome instances and one Internet Explorer. To register a node on localhost at port 5555 open a new terminal and run the command:

java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register

Node will be created under default 5555 port:

Refresh grid console and you should see our first node:

Of course nothing prevents us from registering node located on a remote machine. Instead of pointing to localhost, just give a host name of another machine. We can also override the default configuration node parameters. To do this, we will register a second node, but this time with changing default configuration. We want our node to run on Linux, and to have only Firefox in version 30.0. We also need to override the default port, because port 5555 we have already taken for the first node. Open a new terminal and execute:

java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox,version=30.0,maxInstances=5,platform=LINUX -port 6666

Second node should register under 6666 port:

Refresh console tab again and there should be our second node with custom configuration:

Writing tests 

The only thing we need to change to run selenium tests on the grid is the WebDriver initialization. We must indicate on which browser and system you want them to be executed. To determine the browser, initialize DesiredCapabilities object with firefox method:

DesiredCapabilities capability = DesiredCapabilities.firefox();

Next thing is the RemoteWebDriver initiation with our hub address and capability object:

WebDriver driver = new RemoteWebDriver(new URL(“http://localhost:5555/wd/hub”), capability);

Above configuration will execute tests on the hub. The hub will send them to nodes which meets specified requirements (in our case it is firefox browser). Nothing stands in the way to determine our execution requirements more accurately. For example, if you declare the requirements as follows:

DesiredCapabilities capability = DesiredCapabilities.firefox();

This test will be performed only on the nodes that have Linux and firefox installed and with version 30.0. Whole example code below:

Popular posts from this blog

Test Automation: Good, Bad and Ugly

The modern approach to software quality and software development life cycle requires that business guys, developers and testers understand that the long manual test phase, although often still necessary, must be reduced to a minimum and replaced by test automation. Working in continuous delivery and continuous integration environment requires us to create automated tests that run on demand, checking our application integration and it’s core functionality correctness. However, there are still many problems with designing and writing automated tests, resulting in their costly maintenance or abandonment in favour of a return to manual processes.
In this article I will focus on describing common good practices of test automation. This post is more than an overview than complete reference guide. Broader aspects, such as the Page Object pattern or Page Factory will be described in detail in a separate article on this blog. Although most practices apply for every types of automated tests, thi…

REST-Assured framework overview

In modern software development, REST services becomes most popular choice for implementing distributed and scalable web application. They are light and easy to maintain, which results in faster and more effective implementation and system integration.
I recommend you also my other posts about REST-Assured and building microservice’s test automation frameworks: REST-Assured: going deeperBuilding microservices testing framework
With the increase popularity of RESTful services, there is a need for fast and lightweight tool for REST webservices testing automation. One of the most popular choice is Rest-Assured framework from Jayway. It introduces simplicity of testing web services from dynamic languages like groovy or ruby to java. In this post we will get our hands dirty and write automatic test in Rest-Assured framework.
In order to create complete implementation of automated tests in Rest-Assured framework, we need to write our code against some example API. We’ll use standalone Wiremock m…

REST-Assured: going deeper

In my previous post I described the basic REST-Assured usage – the lightweight framework for testing RESTful services. Despite the fact that described range of functionalities would be enough in most cases,REST-Assured has a lot more to offer. In this post I would like to bring some more advanced examples of the framework usage.

I recommend you also my other posts about REST-Assured and building microservice’s test automation frameworks:

REST-Assured – framework overviewBuilding microservices testing framework
Object Mapping Sending request’s body as string is easy and straightforward, but it can be inconvenient in the case of more complex operations on request / response properties. Proven solution for this is a good-known serialization of request/response body to objects. REST-Assured supports object mapping to (and from) JSON and XML. For JSON you need either to have Jackson or Gson in your classpath and for XML you need JAXB. Here is an example of request object serialization using J…