Before setting up a Selenium grid you need to make sure you have Java installed and configured in your computer’s environment path. If you don’t, here are some step by step instructions to get your machine configured:
Here’s the deal:
Why use a Selenium Grid
Using a Selenium grid allows you to save time by spreading your test across multiple machines.
This means you can run your test in parallel, which reduces the amount of total time to run your full automation test suite.
It’s also great if you need to run against multiple browser versions like IE 9 and IE 10 by allowing the hub to automatically manage that for you.
Selenium Grid: What is a Hub?
The hub is the main command center for managing which machines your selenium test will run on. This is where you can see a list of all the available nodes currently running in your grid environment.
When you run a Selenium test and pass it some remote web driver desired capabilities parameters, it goes to the hub and finds an available node that matches the criteria. Once it finds a machine that matches, say, a browser version you want to run against, the hub reroutes your script to the desired node.
So, now let’s get your hub up and running…
Configure the Hub
- Start the command prompt and navigate to the location in which you placed the Selenium server jar file.
- Enter:(FYI: your version number may be different than mine)
java –jar selenium-server-standalone-2.43.1.jar –role hub
- Your screen should now look something like this:
Basically, what happened is that a jetty web server started and is now listening on a port – in this case, port 4444 (FYI –This port number can be changed by passing the –port parameter followed by the port number you want to use).
- Now open a browser and navigate to http://localhost:4444/grid/console
- If everything is working, the website should come up and you should see something like this:
Next, we need to set up some node machines.
Selenium Grid what is a Node
A node is a machine that you register with your hub. By registering with the hub, the hub now knows about the node and any configuration information you used when you registered the node.
Setup selenium grid nodes
- Just like with the hub machine, we need to also the Download Selenium Server on all our node machines.
- Once you have the Selenium-server jar file on the node machine, open up a cmd prompt and navigate to it.
java –jar selenium-server-standalone-2.43.1.jar –role node –hub http://hubIP:4444/grid/register
- If everything works, you should now see the IP address of the node you just started and registered in the hub console view:
Cool! That’s all you need to do get a Selenium Grid up and running. I also spoke Justin Ison a senior software engineer at Microsoft that gave some tips on how to create a mobile testing grid that you should check out.
That’s not all…Here are a few helper tools folks managing Selenium grids recommend.
Selenium Grid Extras
I’ve also started using selenium grid extras developed by Dima Kovalenko which is a project that combines a lot of little scripts that improve the stability of a Selenium grid into a single management tool called Selenium-Grid-Extras. It has a lot of cool features built into in like recording a video as the test is running and saving that video.
But the overall idea behind it is to kind of take away some of the complexities that come with managing the Grid.
The best part?
Selenium Grid Extra Features
Here are some of the other features you get by using Selenium Grid Extras vs Selenium Grid alone:
- Ability to control individual grid nodes, the following is an incomplete list of OS level tasks:
- Killing any browser instance by name
- Stopping any Process by PID
- Moving mouse to a specific location
- Get Memory usage and disk statistics
- Automatically upgrade WebDriver binaries
- Restart node after a set number of test executions
- Central storage of configurations for all nodes on the HUB server
- Screenshots at the OS level
- And much more.
Selenium Grid Docker – Zalenium
You might be asking is there any way you can create or use a Selenium Grid Docker setup? If so you are in luck.
It can be frustrating and time-consuming to keep everything up to date and running smoothly once you get you Selenium Grid up and running.
Zalenium is a flexible and scalable container based Selenium Grid with video recording, live preview, basic auth & dashboard.
It gets harder if you decide to scale up to handle more and more automated tests.If this is you check out my post on What is Zalenium? Docker based Selenium Grid
Running Selenium Grid in Jenkins
If you’re looking on getting your Selenium Grid deployment on a Jenkins cluster to check out this Selenium Jenkins plugin.
Moving from Selenium Grid to Cloud-Based Grid Provider
Many folks have found that to get the coverage they need against all the devices and operating systems they have to use a cloud-based grid provider. There are many option Sauce Labs being my favorite.
But if you are looking to do this check out my interview with Anshul Sharma for potential pitfalls you can avoid: