What is JSON?
"JavaScript Object Notation" is amount shape of JSON as well as it is best agency to shop data inwards an organized, easy-to-access as well as slowly to read as well as sympathize manner. Here nosotros tin utilization it to store selenium grid config parameters.
What is usage of JSON inwards selenium grid?
Well.. Answer is : When nosotros start selenium grid hub as well as nodes manually from ascendence prompt, We ask to laid many unlike parameters for grid hub as well as nodes similar port, browserName, maxInstances, platform, maxSession etc.. from ascendence prompt. You volition detect all config parameter's instance links on Selenium Grid tutorial page. Instead of feeding all config parameters straight from ascendence prompt, We tin store selenium grid hub as well as nodes config parameters inwards .json file as well as and hence tin utilization that file to commencement hub as well as nodes alongside required configuration.
Let's acquire it practically how to practise .json files for selenium grid hub as well as node as well as and hence how to run them.
Scenario : Consider instance of "maxSession" every bit described on Usage of maxSession. We wants to run ii evidence cases on ii unlike browsers(Firefox as well as Chrome) but max ii 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": v } - Save file alongside name GridHub.json inwards D: drive.
Creating .json file for selenium grid node
Follow the steps given bellow to practise 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 alter config parameters similar hubPort, maxSession, browserName, maxInstances etc.. inwards higher upwards given files every bit per your requirements.
Start hub as well as 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 as well as hence download both files as well as set inwards D: drive.
- Start grid hub
- Open ascendence prompt.
- Navigate to D: displace as well as 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 commencement selenium grid hub.
It volition commencement selenium grid hub.
- Start grid node
- Open ascendence prompt.
- Navigate to D: drive as well as 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 commencement selenium grid hub.
It volition commencement selenium grid node.
Now if you lot access http://localhost:4444/grid/console URL inwards browser, It volition demonstrate you lot grid configuration alongside ii firefox as well as ii chrome browsers every bit bellow.
Now you lot are gear upwards to run selenium webdriver evidence on selenium grid.
Create WebDriver evidence as well as run using grid
Create fillingForm.java, Calc.java as well as testng.xml files inwards your eclipse every bit given inwards maxSession Example as well as run evidence from testng.xml file. It volition commencement running on grid.
This agency you lot tin utilization JSON file to launch selenoum grid hub as well as node configuration.
