Before setting up a Selenium grid you need to make sure you have Java installed and configured in your computer’s environment path.
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).
Next, we need to setup some node machines.
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:
seleniumProtocol
, Node will be registered with both Remote Control (Legacy) and Webdriver Protocol (as seen in the screenshot above).That's all you would be needing to do for an up and running Selenium Grid.
An example configuration for a hub:
java -jar selenium-server-standalone-<version>.jar -role hub -hubConfig hubConfig.json
{
"_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"
}
An example configuration for a node
java -jar selenium-server-standalone-<version>.jar -role node -nodeConfig nodeConfig.json
{
"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"
}
],
"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": {}
}
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.
C# code to create a remote webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Edge();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Node configuration in Json
{
"browserName":"MicrosoftEdge",
"platform": "WINDOWS",
"maxIstances": 1,
"seleniumProtocol": "WebDriver"
}
C# code to create a remote webdriver
// 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);
Node configuration in Json
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
C# code to create a remote webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Firefox();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Node configuration in Json
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
C# code to create a remote webdriver This is for OperaChromium
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities
capabiliteiten = new DesiredCapabilities();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Chosing browser
capabiliteiten.SetCapability(CapabilityType.BrowserName, "operablink");
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Node configuration in Json
{
"browserName": "operablink",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Platform type can be one of the following:
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
C# code to create a remote webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Edge();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Node configuration in Json
{
"browserName":"MicrosoftEdge",
"platform": "WINDOWS",
"maxIstances": 1,
"seleniumProtocol": "WebDriver"
}
C# code to create a remote webdriver
// 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);
Node configuration in Json
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
C# code to create a remote webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Firefox();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Node configuration in Json
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
C# code to create a remote webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities
capabiliteiten = new DesiredCapabilities();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Chosing browser
capabiliteiten.SetCapability(CapabilityType.BrowserName, "operablink");
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Node configuration in Json
{
"browserName": "operablink",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Platform type can be one of the following:
PlatformType.Android;
PlatformType.Any;
PlatformType.Linux;
PlatformType.Mac;
PlatformType.Unix;
PlatformType.Vista;
PlatformType.Windows;
PlatformType.WinNT;
PlatformType.XP;