In this post, I will describe how to use Selenium Grid. You will learn how to install selenium grid and how to configure it.

Prerequisites

Nice to have: Before starting to read this post it is better to read previous selenium tutorials.

First of all, you can access the Selenium Grid page from the below address.

https://github.com/SeleniumHQ/selenium/wiki/Grid2[1]

Selenium Grid allows you to:

  • Scale by distributing tests on several machines ( parallel execution )
  • Manage multiple environments from a central point, making it easy to run the tests against a vast combination of browsers / OS.
  • Minimize the maintenance time for the grid by allowing you to implement custom hooks to leverage virtual infrastructure for instance. [1]

Now, please go to http://www.seleniumhq.org/download/ and download Selenium Standalone Server.¬†Selenium team constantly updating the versions. You may see a different version, pls do not panic, just download it. ūüėČ

Then, copy the .jar file to C:\Selenium\grid\ folder.

What are Hub and Nodes?

Basically, we have a Hub which is a server that we connect from our tests and we have Nodes, they can be on different machines and they register with the hub. Simply, we have a hub and several nodes, nodes are registered our hub and hub knows that which browsers are available. Hub sends requests to the nodes based on desired capabilities and executes the tests.

How to Start and Configure Hub and Nodes

The best way to start hub and node with .bat files for Windows also it is easier and tidier to configure them with .json files.

First, let’s start the hub by command window.

Hub Start Command: java -jar selenium-server-standalone-3.0.1.jar -role hub

and you can see the hub panel on your browser as follows.

Let’s start the node

We can start the node with the command window as below command.

Node Start Command: java -jar selenium-server-standalone-3.0.1.jar -role node -hub http://localhost:4444/grid/register

and when you open the grid console you can see that the node registered with the hub.

selenium grid

When we wanted to use selenium grid in our tests we need to tell our grid where the required browser executable is located. Thus, we should start to the node as below command before writing our tests. We added the blue part.

Node Start Command with Chrome Driver Location: java -jar -Dwebdriver.chrome.driver=C:\Selenium\drivers\chrome\chromedriver.exe selenium-server-standalone-3.0.1.jar -role node -hub http://localhost:4444/grid/register 

I wrote a very simple test which clicks the Facebook login button. Before running below test, start the hub and the node with the above command then run the test.

Selenium Grid Nodes and Hub Configurations by JSON

It is also described at https://github.com/SeleniumHQ/selenium/wiki/Grid2 page as shown below.

Hub Config: https://github.com/SeleniumHQ/selenium/blob/master/java/server/src/org/openqa/grid/common/defaults/DefaultHub.json

Node Config: https://github.com/SeleniumHQ/selenium/blob/master/java/server/src/org/openqa/grid/common/defaults/DefaultNodeWebDriver.json

I will use the same config which is located at the above link. By using these configurations I created “starthub.bat” and “startnode.bat” files.

starthub.bat

startnode.bat

Start the HUB

Start the Node

Run the test again! When you run the test you will see that it will pass.

Selenium Webdriver Tutorial Series

Thanks for reading.

All the best!
-Onur