Friday, 17 June 2016

Selenium as a Windows Service

I have been playing with selenium grid from past few days and it becomes very tedious to me to setup the grid by firing commands in command prompt [I am mostly windows 7 user]. So I thought of running selenium grid as service and for that I have used NSSM - the Non-Sucking Service Manager.

To set up grid as service, obviously you need-
  1. Selenium-server-standalone-2.53.0.jar file (should work with other version but I have used this)

Selenium Grid Hub setup:-

    You need to have following files in folder ready to use before you start with this setup. My folder setup is like-

    To set up hub, we use following command in the command prompt.

java -jar selenium-server-standalone-2.53.0.jar -role hub


Check whether grid hub is up and running as shown in below image-


Now if you accidentally close your command prompt running, your hub will go down which used happen a lot to me as I was not very keen user of command prompt. By setting up this as service, anyone can get rid of orphan looking command prompt. Now close the command prompt and start with actaul setup of service.

Set up same selenium grid hub as service

NSSM



Detail use of every tab in NSSM is mentioned here. Verify that proper entries are made in the registry for same.


You can monitor SeleniumHub service running now in Services.


Here is your selenium grid hub working as service.


On Grid adding chrome-driver node -



java -jar selenium-server-standalone-2.53.0.jar -role node -hub http://192.168.0.174:4444/grid/register/ -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1 -Dwebdriver.chrome.driver=C:\Grid\chromedriver.exe  

Execute above command in command prompt. You need to use your hub IP instead of 192.168.0.174 which is IP of my hub. 


Observe your selenium grid console now, you can see one chrome node is added over there.


Set up same chrome node as service:-

Close the previously running chrome node in command prompt. I’m passing below command as parameter while creating new service as ‘ChromeNode’ -
-jar selenium-server-standalone-2.53.0.jar -role node -hub http://192.168.0.174:4444/grid/register/ -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1 -Dwebdriver.chrome.driver=C:\Grid\chromedriver.exe




 You need to use your hub IP instead of 192.168.0.174 which is IP of my hub. 




Verify that proper entries are made in the registry for same.


You can monitor ChromeNode service running now in Services.



Here is your whole selenium grid setup running as service.



This is all for now in selenium testing tools
Cheers!!

2 comments:

  1. Selenium is used in many IT companies due to its numerous advantages compared to other automation testing tools in the market. There is massive demand for automation testers to validate software and mobile applications across the world. Taking Selenium Course in Chennai
    will assist aspirants to enter automation testing industry!!!

    ReplyDelete
  2. Nice blog,please clarify my question.
    Selenium scripts will work if user logged off from node machine?

    ReplyDelete

Copyrights held by Amol Chavan. Powered by Blogger.