logo

Configuring & Running the Selenium Grid from CentOS

We've recently started using Selenium to perform browser-based regression testing - this has almost totally removed the administrative overhead associated with manual testing. I have a desire to completely automate the testing process, including the distribution of tests to other machines running different browser versions.

Selenium Grid is a platform for automating the distribution of testing tasks across multiple servers - each one of these would be responsible for running the test(s) against a different set of browsers.

I'm going to install the Grid Hub system upon a standard CentOS 6 installation, and then connect it to multiple remote instances, running across a variety of Windows operating systems.

Deploying the Selenium Grid Hub as a Daemon

The Selenium Grid system runs as a Java library, therefore a pre-requisite is that we have this installed:

yum -y install java-1.7.0-openjdk

Now we want to create directories and get the Selenium Grid libraries onto the instance:

mkdir -p /etc/selenium/logs
curl -L http://selenium.googlecode.com/files/selenium-server-standalone-2.29.0.jar >>/etc/selenium/selenium-server-standalone-2.29.0.jar
curl -L https://bitbucket.org/ptylr/public-stuff/raw/47ac473bd8e7f3dd2eb035c7de3e75bc7997d0d5/init.d/selenium >>/etc/init.d/selenium
chmod +x /etc/init.d/selenium
chkconfig selenium on

If you want to test this, you can start the service:

service selenium start

Output will be made to /etc/selenium-grid/logs/selenium-grid.log. Visit http://[server_address]:4444/ to view the Grid landing page.

Update: I have noticed that version 2.29.0 of the Selenium Standalone Server has some issues that cause HTTP500 status codes to be returned when visiting the hub console URL, so I suggest updating to version 2.30.0 - simply change the version in the instructions above, then when you have downloaded the init.d script, open with Vim and update the binary to version 2.30.0.

Adding Nodes to the Selenium Grid

Now that we've configured the Selenium Grid, we'll want to add nodes to it. This is very simple, and uses the same selenium-server-standalone Java file as with the Grid Hub.

Selenium nodes rely on an installation of the browsers that you wish to test against. We will tell each node which browsers it has available during start-up. By default without instructing each node of the browsers that it has available, it will make a series of Internet Explorer, FireFox and Chrome browsers available - obviously unless those browsers are installed, errors will occur.

You will need to install Java onto each node, if you are using CentOS, then you can use the same command as the first step within the Grid Hub deployment section (above):

yum -y install java-1.7.0-openjdk

Use the same Selenium Standalone Server binary as within the Grid Hub deployment section (above), and make a call to it at the command prompt:

java -jar selenium-server-standalone-2.30.0.jar -role node -hub http://[grid_hub_server_address]:4444/grid/register -browser "browserName=firefox,version_binary=C:Program Files (x86)Mozilla Firefoxfirefox.exe ,maxInstances=3, platform=WINDOWS"

This launches a node, which will self-register with the Grid. It will enable three testing instances of Firefox, and is to be launched upon a Windows platform. You will see this node having been added to the http://[grid_hub_server_address]:4444/grid/console page.