How to use Selenium Grid

1 comment, 625 points
How to use Selenium Grid
How to use Selenium Grid

How to use Selenium Grid

In one of my previous position we were running our tests multi browser using SOUCELABS services. The problem that we had it was with the connection , it was ridiculously slow and I started to investigate how to use selenium grid propertly. Well it wasn’t entirely souce labs fault we had a lot of proxy servers and network filters due to the security policy from the company.

But this was affecting our test execution time very bad so we were thinking to build our grid infrastructure in house.

It was a painful process , to build business cases to convince the business what benefits will bring that on and after to deal with the infrastructure team to get everything as a package not just machines that can run selenium grid.

Overview of the infrastructure:

We started with one hub and 40 nodes all machines were linux machines.

The hub configuration was , I7 CPU , 32 gb ram , SSD and gigabit ethernet, and each node was I7 , 16gb ram, SSD , and gigabit ethernet.

After we started to give it a try we figured out that we need to fix some issues to have it more reliable, so we decided to have some extra tools in top of the grid:

A Selenium Grid Extras Primer

Some of the benefits that can bring with are :

Explicitly kill web browser after each test

As you all know from different reasons during the execution there might be leftovers with browser instances that are hanging around, so Extras Primer will help us to to kill any remaining or crashed instances of the browser used.

Restart Grid Nodes from time to time

Selenium grid is a quite powerful tool but it still has some memory leaks , we found that restarting the Java process from time to time is the fastest and most reliable.

Restart the operating system after several runs

We found out that after 15-25 sessions of test executions is good to restart the machines and gave us a huge stability.


Having in place all these setup and cleanups we were able to run somewhere at 45000 test sessions in one month, with only 2.5% failure rate due to node instability.

Grid setup:
 java -jar selenium-server-standalone.jar -role hub
12:04:25.542 INFO - Launching Selenium Grid hub
Register a node:
java -jar selenium-server-standalone.jar -role node -hub http://localhost:4444/grid/register
12:05:32.776 INFO - Launching a Selenium Grid node

Be aware that will only demonstrate a single node , if you want to setup multiple machines , you’ll need to place the selenium standalone server across each machine.

You can view the gird console up and running navigating to http://localhost:4444/grid/console.

selenium grid
selenium grid
Capybara cucumber code setup

require 'capybara/cucumber'
require 'selenium/webdriver'

capabilities =
capabilities['browserName'] = "chrome"
capabilities['version'] = ""
capabilities['platform'] = “Linux”
capabilities['video'] = "True"

Capybara.register_driver :selenium do |app|
  client =
  client.timeout = 1200 #seconds, http_client: client,
    :browser => :remote,
    :url => "http://localhost:4444/wd/hub",
    :desired_capabilities => capabilities)

Capybara.default_driver = :selenium
Capybara.run_server = false

#Maximize window. 

You can see a full list of the available Selenium Capabilities options here.

Bellow you can find out the configuration for each browser:

Happy Testing!

Like it? Share with your friends!

1 comment, 625 points
Test engineer

One Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.