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
- Download Selenium Server
- 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.
- Enter:
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.
Enter Zalenium.
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:
Hi Joe,
Could you review VisGrid-Selenium Grid UI?
http://www.codoid.com/products/view/2/30
Hi Akram – thanks for the suggestion. i added to my future post blog ideas list
HI Joe,
Nicely explained Thank you :)
Thanks Isha – let me know if there are any other Selenium topics you want me to cover. Cheer~Joe
Hi,
Could you please let me know how selenium grid works. I mean i’m not providing any type of credentials anywhere(in grid or hub)
Is this security issue in selenium>?
I don’t think there is any build in security Selenium Grid features. I have not tries this but does this work for you: http://stackoverflow.com/questions/29427771/can-selenium-grid-and-node-urls-be-used-with-security
Hi Joe,
Is it possible to setup hub and node in the same machine.
Expecting early response from you.
Thanks&Regards,
SivaKrishna.M
Hi Joe,
I see a lot of ‘Session time-out’ issues when running my tests against the hub.
Anything that I might be missing out on, in the set up?
Cheers,
Jason
Thanks!! its working.
Yes. You just start up the host and node on same machine and it will work.
Hi Jason – does using the nodeTimeout parameter help? For example:
Hi joe,
how to kill this “java -jar selenium-server-standalone-2.53.1.jar” after 30 seconds automatically in console
Why after 30 seconds? You could kill it using taskkill /f /im but not sure how to time it every 30 seconds
Hi Joe,
Could you please help me in TestNG setup with Hybrid Framework( Keyword+DataDriven combination Framework)?
Thanks
Ramesh
Thank u very much..nicely explained with commands..
I am trying to run on Grid. I am getting error recently .
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.44.0’, revision: ’76d78cf323ce037c5f92db6c1bba601c2ac43ad8′, time: ‘2014-10-23 13:11:40’
System info: host: ‘VDAASW708030’, ip: ‘30.138.168.129’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_45’
Driver info: driver.version: Driver
Hi Joe,
can you explain the below code, as i saw this in one of the youtube videos that i was referring for grid concepts.
java -Dwebdriver.chrome.driver=”E:/Selenium_Needables/chromedriver_win32/chromedriver.exe” -jar selenium-server-standalone-3.9.0.jar -role node -hub http://192.168.1.128:4444/grid/register
Hi Joe,
While i m registering the hub on my local machine its getting an error that Port 4444 is busy,pleas choose a free port for the hub.
Can you please explain how to choose different port for registering the hub.I am unable to do this.
Thanks
Seshmi the default port number can be changed by passing the –port parameter followed by the port number you want to use. For example when you start the hub again just add the -port at the end like this: java –jar selenium-server-standalone-2.43.1.jar –role hub -port 4455 <--you can choose what ever port number you want to use here. make sense?
--you>Hi Joe,
How can we run the multiple nodes at a time? Example I want to execute my script in different machines (lets say 20 Machines).
Please help us on this.
hi , i created hub and node successfully and executed selenium tests in node by providing ip address.
But my challenge is i want to execute tests in node in headless mode.
Can anyone help how to do that.
Note: i am able to execute tests in headless in my local.
Yes you just need to install the node on your 20 machines and point back to you Hub IP and it will connect to all available nodes