Unintelligible

Tuesday, July 28, 2009

Installing Selenium-RC as a Windows service

Installing Selenium as a Windows service is reasonably straightforward - based on the instructions for Fitnesse, which unfortunately seem to have been deleted from the Fitnesse wiki, but which have been reproduced here.

There are two parts to doing this - the first, registering the service using srvany.exe (which wraps any executable as a service), and the second, adding the keys to the registry to tell srvany.exe how to launch Selenium-RC. srvany.exe is a part of the Windows Resource Kit, if you don’t have it already you will need to download it from Microsoft.

The following will register the Selenium service - on the command line (all in one line):

"C:\Program Files\Windows Resource Kits\Tools\instsrv.exe" SeleniumRC
"C:\Program Files\Windows Resource Kits\Tools\srvany.exe" -a [myuser] -p [mypass]

This is assuming the Windows Resource Kit has been installed to its default location, “C:\Program Files\Windows Resource Kits”. Also, note that the user supplied needs to have the Log On As Service permissions assigned.

Now, add the following keys to the registry - this text can simply be copied-and-pasted to a .reg file, then double-clicked to add the entries to the registry:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SeleniumRC\Parameters]
"Application"="java.exe"
"AppDirectory"="C:\\Program Files\\selenium-server-1.0.1"
"AppParameters"="-Xrs -jar selenium-server.jar"

You should now be able to start the service - if you get an error about the service failing to start due to a logon issue, make sure that the user you are using to run the service has been granted Log On As A Service permission (editing the service logon credentials in the Services MMC snap-in and saving the changes will cause this to happen automatically.)

posted by Nick at 10:08 pm - filed in testing, windows  

14 Comments »

  1. Thanks for this!

    Have you tried starting the SeleniumRC service on a port other than the default (4444)? I’m trying to pass in the parameter -port 8888 without any luck. I tried adding it to the registry key:

    AppParameters”=”-Xrs -jar selenium-server.jar -port 8888″

    But it doesn’t seem to get picked up. (How can I view console output?)

    Neither does it when I add it to the service properties Start parameters. Then the system tells me the service was started and stopped because it may not have had any work to do.

    Comment by Dave Dumaresq — October 20, 2009 @ 5:50 pm

  2. Hi,

    I must admit I haven’t tried starting it on anything other than the default port - but I would have thought it should work.

    The first thing to try would be to start the service from the command line using the arguments you’re setting in the registry; so, in your case:

    cd “C:\\Program Files\\selenium-server-1.0.1″
    java -Xrs -jar selenium-server.jar -port 8888

    If that doesn’t start correctly, it should give you an error message with the cause.

    HTH -

    Comment by Nick — October 20, 2009 @ 6:55 pm

  3. Thanks for this post. It saved me a lot of time.

    Comment by Raj — January 13, 2010 @ 12:12 am

  4. Thanks for the post!

    I ran into the same problem (the parameters) and solved it by using a BAT-file containing the whole command line:

    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SeleniumRC\Parameters]
    “Application”=”C:\\Path\To\My\BAT\File”

    Comment by Kostia — January 22, 2010 @ 12:08 am

  5. I was able to run Selenium-server-1.0.3 as Windows service with JavaService-2.0.10 (http://forge.ow2.org/projects/javaservice/) as follows:

    1. Copy “JavaService.exe” to selenium-server-1.0.3\ directory as “selenium.exe”
    2. Run the following batch in the same directory (edit paths and SEL_PARAMS if needed):
    ========
    @echo off
    set JAVA_HOME=c:\java\jre6
    set JVMDIR=%JAVA_HOME%\bin\client
    set JSBINDIR=%CD%
    set JSEXE=%JSBINDIR%\selenium.exe
    set SVC_NAME=Selenium4445

    set SEL_PARAMS=”-port 4445 -log %JSBINDIR%\logs\%SVC_NAME%.log -ensureCleanSession -trustAllSSLCertificates”
    set SEL_JAR=%JSBINDIR%\selenium-server.jar
    set SEL_START=org.openqa.selenium.server.SeleniumServer

    echo . About to remove the previously installed service if any:
    pause
    %JSEXE% -uninstall %SVC_NAME%

    echo . Using following version of JavaService executable:
    %JSEXE% -version
    echo .

    echo Installing service… Press Control-C to abort
    pause
    echo .

    %JSEXE% -install %SVC_NAME% %JVMDIR%\jvm.dll -Djava.class.path=%SEL_JAR% -start “%SEL_START%” -params “%SEL_PARAMS%”
    echo .
    pause

    %JSEXE% -queryconfig %SVC_NAME%
    ========

    Voila!

    PS: Draw your attention to how double quotes are used. Each substring in SEL_PARAMS should be passed to SeleniumServer.class as a separate parameter and should not be combined to the single string. Otherwise nothing will work.
    See the corresponding registry key below:
    ========
    REGEDIT4

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Selenium4445\Parameters]
    “JavaService Version”=”2,0,10,0″
    “JVM Library”=”c:\\java\\jre6\\bin\\client\\jvm.dll”
    “JVM Option Count”=dword:00000001
    “JVM Option Number 0″=”-Djava.class.path=C:\\Java\\selenium\\selenium-server-1.0.3\\selenium-server.jar”
    “Start Class”=”org.openqa.selenium.server.SeleniumServer”
    “Start Method”=”main”
    “Shutdown Timeout”=dword:00007530
    “Overwrite Files Flag”=dword:00000000
    “Startup Sleep”=dword:00000000
    “Start Param Count”=dword:00000006
    “Start Param Number 0″=”-port”
    “Start Param Number 1″=”4445″
    “Start Param Number 2″=”-log”
    “Start Param Number 3″=”C:\\Java\\selenium\\selenium-server-1.0.3\\logs\\Selenium4445.log”
    “Start Param Number 4″=”-ensureCleanSession”
    “Start Param Number 5″=”-trustAllSSLCertificates”
    ========

    Comment by NuclearFisher — May 26, 2010 @ 5:54 pm

  6. Hi,

    I followed this instructions to run RC as service.

    I was able to create registory entery by name SeleniumRC. I don’t know what is -Xrs -jar selenium-server.jar is used for so I changed it to java -jar selenium-server.jar command.

    I hope its okay.

    After this I am not sure how to start SeleniumRC as service.

    Can some one help?

    Comment by manisha — July 14, 2010 @ 2:03 pm

  7. [...] found a great resource that details how to do this. To summarize the article, follow these simple [...]

    Pingback by Integrating Selenium Tests into CruiseControl.Net via NUnit « Everything Web — July 26, 2010 @ 3:10 am

  8. @manisha: change java -jar selenium-server.jar back to -Xrs -jar selenium-server.jar and it should work fine.

    You don’t need to specify ‘java’ in the AppParameters because it’s already specified as the Application

    Comment by Nick — July 26, 2010 @ 8:36 pm

  9. [...] Selenium RC is by default just a standalone application that runs selenium tests. To be able to use it under a Continous Integration framework we need to be able to run it as a Windows service. Here is summary of how this is done on a Windows 2003 server inspired by this article. [...]

    Pingback by Automating smoke tests with Selenium, CruiseControl and NUnit — October 24, 2010 @ 12:00 pm

  10. Hi,

    Followed the instructions as above but, whilst the service appears to run, my web application does not seem to find it. My page with a list of tests to fire just hangs and says Waiting for server.

    I’ve tried running it from command line. It says something else is using port 4444 but, when I stop the service and run it via command line it works.

    Are there any permissions that I need to change so that my web app can see the server. (I’ve added Selenium user to my c:\program files\selenium-server-1.0.3)

    Comment by Daz — November 5, 2010 @ 5:37 pm

  11. I would like to know can I do the similar thing on Linux? I am now writing some testing suite using Selenium. But it really bothers a lot every time when I execute the testing suite, a Firefox browser will pop up. Is there any solution for that?

    Comment by dazhang — July 27, 2011 @ 8:30 pm

  12. Has anyone figured out a way to capture the console log of Selenium when launched as a Service (wrapped)?

    Comment by Steven Staton — September 28, 2011 @ 8:34 pm

  13. We just put up a step-by-step tutorial showing how to use our commercial app (AlwaysUp) to easily run Selenium RC server as a Windows Service:

    http://www.coretechnologies.com/products/AlwaysUp/Apps/RunSeleniumServerAsAService.html

    Comment by CoreTech — November 22, 2011 @ 8:00 am

  14. Was able to get selenium to run as a service using http://nssm.cc

    Comment by Alexander — November 1, 2012 @ 9:53 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment