String hubUrl = "http://localhost:4444/wd/hub"
DesiredCapabilities capability = DesiredCapabilities.firefox(); //or which browser you want
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capability);
A quick configuration for a hub and node setup in selenium grid. For more information see: Grid 2 docs
To set up a grid hub you need the flowing:
To Create a Hub you need to run the selenium server.
java -jar selenium-server-standalone-<Version>.jar -role hub
java -jar selenium-server-standalone-<Version>.jar -role hub -hubConfig hubConfig.json
On clicking console
-> View config
for to view the Configuration for the hub details.
To set up a grid hub you need the flowing:
Now To create Nodes for the Hub
java -jar selenium-server-standalone-<VERSION NUMBER>.jar -role node
java -jar selenium-server-standalone-<Version>.jar -role node -nodeConfig nodeConfig.json
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": {}
}
java -jar <jar-file-full-name>.jar -<your parameters if any>
Parameters | Details |
---|---|
role | Is what tells the selenium which it was hub or node |
port | This is to specify which port the hub or node should be listening. |
hub | This parameter is used in node to specify the hub url |
browserName | Its been used in node to specify the browser name like firefox, chrome, internet explorer |
maxInstances | Its where the instance of the browser is being specified eg. 5 means there will be 5 instance of the browser which user specified will be present. |
nodeConfig | A Json configuration file for the node. You can specify the role, port etc. in here |
hubConfig | A Json configuration file for the node. You can specify the role, port, max instances etc. in here |