Tuesday, October 30, 2012

Running Selenium Grid as a Service

If you have started running you Selenium suite in parallel or in a distributed environment you're probably using the Selenium Grid2. Now you don't want the console window open with the hub and node running on your build server so you'll want to wrap it and run it as a service.

To do this I've used the Java Service Wrapper around the selenium-server-standalone-2.25.0.jar, the documentation is pretty solid. I used the 4th method listed on the site, Method 4 - WrapperJarApp Integration.

If you follow the instructions you should end up with a directory structure like this:
----HubService
|   ----bin
|   |       InstallSeleniumHub.bat
|   |       SeleniumHub.bat
|   |       UninstallSeleniumHub.bat
|   |       wrapper.exe
|   |       
|   ----conf
|   |       wrapper.conf
|   |       
|   ----lib
|   |       selenium-server-standalone-2.25.0.jar
|   |       wrapper.dll
|   |       wrapper.jar
|   |       
|   ----logs
|           wrapper.log
|              
----NodeService
   ----bin
   |       InstallSeleniumNode.bat
   |       SeleniumNode.bat
   |       UninstallSeleniumNode.bat
   |       wrapper.exe
   |       
   ----conf
   |       wrapper.conf
   |       
   ----lib
   |       selenium-server-standalone-2.25.0.jar
   |       wrapper.dll
   |       wrapper.jar
   |       
   ----logs
           wrapper.log
The only real work is inside the wrapper.conf partially shown below:

HubService - partial wrapper.conf:

#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
#  Locate the java binary on the system PATH:
wrapper.java.command=java
#  Specify a specific java binary:
#set.JAVA_HOME=/java/path
#wrapper.java.command=%JAVA_HOME%/bin/java

# Tell the Wrapper to log the full generated Java command line.
#wrapper.java.command.loglevel=INFO

# Java Main class.  This class must implement the WrapperListener interface
#  or guarantee that the WrapperManager class is initialized.  Helper
#  classes are provided to do this for you.  See the Integration section
#  of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperJarApp

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/selenium-server-standalone-2.25.0.jar

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib

# Java Bits.  On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE

# Java Additional Parameters
#wrapper.java.additional.1=

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

# Application parameters.  Add parameters as needed starting from 1
wrapper.app.parameter.1=../lib/selenium-server-standalone-2.25.0.jar
wrapper.app.parameter.2=-role
wrapper.app.parameter.3=hub
Here are the full conf files, remember to rename to wrapper.conf:
Hub wrapper.com
Node wrapper.com

Now you should first run the SeleniumHub.bat to test the wrapper in a console window. If that is successful you can then run InstallSeleniumHub.bat and InstallSeleniumNode.bat to register the services.

The service will still not be running until you start it as follows:
Start -> Run -> services.msc


This should be all you need to do.

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Note: Only a member of this blog may post a comment.