Thursday, August 30, 2018

Launch Selenium Grid Hub As Well As Nodes Using Json Config File

| Thursday, August 30, 2018
What is JSON?
"JavaScript Object Notation" is amount shape of JSON together with it is best agency to shop data inwards an organized, easy-to-access together with slow to read together with empathize manner. Here nosotros tin lavatory exercise it to store selenium grid config parameters.

What is usage of JSON inwards selenium grid?
Well.. Answer is :  When nosotros start selenium grid hub together with nodes manually from ascendance prompt, We require to laid many dissimilar parameters for grid hub together with nodes similar port, browserName, maxInstances, platform, maxSession etc.. from ascendance prompt. You volition honor all config parameter's illustration links on Selenium Grid tutorial page. Instead of feeding all config parameters guide from ascendance prompt, We tin lavatory store selenium grid hub together with nodes config parameters inwards .json file together with and thence tin lavatory exercise that file to root hub together with nodes alongside required configuration.

Let's larn it practically how to exercise .json files for selenium grid hub together with node together with and thence how to run them.

Scenario : Consider illustration of "maxSession" every bit described on Usage of maxSession. We wants to run two testify cases on two dissimilar browsers(Firefox together with Chrome) but max two sessions at a fourth dimension using selenium grid.

Creating .json file for selenium grid hub
Follow the steps given bellow to create GridHub.json file.
  • Create novel notepade(.txt) file.
  • Copy-paste bellow given code inwards it.
{         "host": null,         "port": 4444,         "newSessionWaitTimeout": -1,         "servlets" : [],         "prioritizer": null,         "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",         "throwOnCapabilityNotPresent": true,         "nodePolling": 5000,                  "cleanUpCycle": 5000,         "timeout": 300000,         "maxSession": five }
  • Save file alongside name GridHub.json inwards D: drive.
Creating .json file for selenium grid node

Follow the steps given bellow to exercise GridNode.json file.
  • Create novel notepade(.txt) file.
  • Copy-paste bellow given code inwards it.
{   "capabilities":       [                 {           "browserName": "firefox",           "maxInstances": 2,    "acceptSslCerts": true,      "javascriptEnabled": true,    "platform": "WINDOWS",           "seleniumProtocol": "WebDriver"         },         {           "browserName": "chrome",           "maxInstances": 2,    "platform": "WINDOWS",           "seleniumProtocol": "WebDriver"         }               ],   "configuration":   {     "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",     "maxSession": 2,     "port": 5555,     "host": ip,     "register": true,     "registerCycle": 5000,     "hubPort": 4444,     "hubHost": ip   } }
  • Save file alongside name GridNode.json in D: drive.
Note : You tin lavatory alter config parameters similar hubPort, maxSession, browserName, maxInstances etc.. inwards higher upwards given files every bit per your requirements.

Start hub together with node using JSON files
I hope, selenium server standalone jounce file and chromedriver exe file is already available inwards your D: drive. If they are non at that spot together with thence download both files together with pose inwards D: drive.

- Start grid hub
  • Open ascendance prompt.
  • Navigate to D: motility together with run bellow given command.
java -jar selenium-server-standalone-2.52.0.jar -role hub -hubConfig GridHub.json

Here, -hubConfig GridHub.json volition charge hub config parameters to root selenium grid hub.
It volition root selenium grid hub.

- Start grid node
  • Open ascendance prompt.
  • Navigate to D: drive together with run bellow given command.
java -jar selenium-server-standalone-2.52.0.jar -role node -Dwebdriver.chrome.driver="D:/chromedriver.exe" -nodeConfig GridNode.json

Here, -nodeConfig GridNode.json will charge node config parameters to root selenium grid hub.
It volition root selenium grid node.

Now if yous access http://localhost:4444/grid/console URL inwards browser, It volition demo yous grid configuration alongside two firefox together with two chrome browsers every bit bellow.

Now yous are laid to run selenium webdriver testify on selenium grid.

Create WebDriver testify together with run using grid
Create fillingForm.java, Calc.java together with testng.xml files inwards your eclipse every bit given inwards maxSession Example together with run testify from testng.xml file. It volition root running on grid.

This agency yous tin lavatory exercise JSON file to launch selenoum grid hub together with node configuration.

Related Posts