Selenium Grid
Selenium Grid
#selenium-
grid
Table of Contents
About 1
Remarks 2
Examples 2
Remarks 4
Downloads 4
h11 4
Drivers 4
Browsers 4
Examples 4
Installation or Setup 4
Things to Notice 7
Json configuration 8
Configuration 9
Microsoft Edge 9
Chrome 9
Firefox 10
Opera 10
Configuration 11
Microsoft Edge 11
Chrome 12
Firefox 12
Opera 12
Credits 14
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: selenium-grid
It is an unofficial and free selenium-grid ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official selenium-grid.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to [email protected]
https://riptutorial.com/ 1
Chapter 1: Getting started with selenium-grid
Remarks
This section provides an overview of what selenium-grid is, and why a developer might want to
use it.
It should also mention any large subjects within selenium-grid, and link out to the related topics.
Since the Documentation for selenium-grid is new, you may need to create initial versions of those
related topics.
Examples
What is Selenium Grid?
Selenium-Grid is a configuration of Hub & Node which allows you to run your tests on different
machines against different browser combinations in parallel. That is, running multiple tests at the
same time against different machines running different browsers on different operating systems. In
other words Selenium Grid supports running the tests in Distributed Environment.
When to use it
• To run your tests against multiple browsers, multiple versions of browser, and
browsers running on different operating systems. This will ensure that the application
you are testing is fully compatible with a wide range of browser-O.S combinations.
• To reduce the time it takes for the test suite to complete a test pass. Lets say you setup
your Grid to run 8 tests at a time, your execution would finish 8 times faster as compared to
your normal run.
Selenium-Grid is used to speed up the execution of a test by using multiple machines to run tests
in parallel.
The Hub
• The Hub is the main engine/central point of the entire configuration, point where all the
nodes are connected.
• Hub should run only on a single machine.
• There should only be 1 hub running where all the tests are loaded.
• Tests will be run on the machines where hub is running, but you can see the browsers on the
node machines.
The Nodes
• Nodes are the instances (machines) which will execute the tests that are loaded on the hub.
https://riptutorial.com/ 2
• There are no limitations on Node machines, a user can setup n number of Nodes.
• Nodes can be launched on different machines with different OS and browser combinations.
• Machines running the nodes can be of different/same configurations as of Hub Machine.
https://riptutorial.com/ 3
Chapter 2: Selenium Grid Configuration
Remarks
Downloads
This chapter contains useful downloads like the webdrivers and link to browsers
Drivers
Place all the drivers in your path variable
• Chrome driver
• FireFox driver
• Microsoft Edge driver
• Opera driver
Browsers
• Chrome
• FireFox
• Microsoft Edge
• Opera
Examples
Installation or Setup
Before setting up a Selenium grid you need to make sure you have Java installed and configured
in your computer’s environment path.
https://riptutorial.com/ 4
Basically what happened is selenium webserver started and is now listening on a port - in this
case default 4444 (FYI - This port number can be changed by passing the -port parameter
followed by the port number on which you want to run the server).
https://riptutorial.com/ 5
Configure the Nodes
• Just like we downloaded Selenium Server for Hub, we also need to download it on all our
Node machines.
• Once you have the Selenium-server jar file on the node machine, navigate to the directory
where jar is downloaded and open up cmd prompt.
• Type: java –jar selenium-server-standalone-2.53.0.jar –role node –hub
http://hubIP:4444/grid/register
○ hubIP :- in case the hub and nodes are running on a different machine
○ localhost :- in case the hub and nodes are running on same machine
As you can see the node is now registered to the hub, by default node starts on -port 5555 but
you can change the same by using -port parameter followed by port number.
If everything works as expected you should now see the IP address of the node you just started
and registered in the hub console view:
https://riptutorial.com/ 6
Things to Notice
• If we don't specify the seleniumProtocol, Node will be registered with both Remote Control
(Legacy) and Webdriver Protocol (as seen in the screenshot above).
• If the browsers type and number of instances aren't mentioned, Node will launch 5 instance
https://riptutorial.com/ 7
of Firefox, 5 Instance of Chrome and 1 Instance of IE driver.
That's all you would be needing to do for an up and running Selenium Grid.
Json configuration
{
"_comment" : "Configuration for Hub - hubConfig.json",
"host": ip,
"maxSessions": 5,
"port": 4444,
"cleanupCycle": 5000,
"timeout": 300000,
"newSessionWaitTimeout": -1,
"servlets": [],
"prioritizer": null,
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"nodePolling": 180000,
"platform": "WINDOWS"
}
{
"capabilities":
[
{
"browserName": "opera",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.opera.driver": "C:/Selenium/drivers/operadriver.exe",
"binary":"C:/Program Files/Opera/44.0.2510.1159/opera.exe"
},
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.chrome.driver": "C:/Selenium/drivers/chromedriver.exe",
"binary":"C:/Program Files/Google/Chrome/Application/chrome.exe"
},
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.gecko.driver": "C:/Selenium/drivers/geckodriver.exe",
"binary":"C:/Program Files/Mozilla Firefox/firefox.exe"
}
],
https://riptutorial.com/ 8
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
Configuration
In the following paragraphs there wil be an example per browser for the configuration in Json and
setup in C#.
This example expects you to have all the drivers in your path variable and browsers installed.
Microsoft Edge
{
"browserName":"MicrosoftEdge",
"platform": "WINDOWS",
"maxIstances": 1,
"seleniumProtocol": "WebDriver"
}
Chrome
https://riptutorial.com/ 9
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Chrome();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Firefox
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Opera
https://riptutorial.com/ 10
Node configuration in Json
{
"browserName": "operablink",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
• PlatformType.Android;
• PlatformType.Any;
• PlatformType.Linux;
• PlatformType.Mac;
• PlatformType.Unix;
• PlatformType.Vista;
• PlatformType.Windows;
• PlatformType.WinNT;
• PlatformType.XP;
Configuration
In the following paragraphs there wil be an example per browser for the configuration in Json and
setup in C#.
This example expects you to have all the browsers installed and the drivers in your path variable
Microsoft Edge
{
"browserName":"MicrosoftEdge",
"platform": "WINDOWS",
"maxIstances": 1,
"seleniumProtocol": "WebDriver"
}
https://riptutorial.com/ 11
Chrome
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Firefox
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Opera
https://riptutorial.com/ 12
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Chosing browser
capabiliteiten.SetCapability(CapabilityType.BrowserName, "operablink");
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
{
"browserName": "operablink",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
PlatformType.Android;
PlatformType.Any;
PlatformType.Linux;
PlatformType.Mac;
PlatformType.Unix;
PlatformType.Vista;
PlatformType.Windows;
PlatformType.WinNT;
PlatformType.XP;
https://riptutorial.com/ 13
Credits
S.
Chapters Contributors
No
Selenium Grid
2 Paras, Thomas
Configuration
https://riptutorial.com/ 14