Starting Selenium RC As A Service For Jenkins
Getting unit tests up and running with MXUnit on Jenkins was fairly easy due to the great documentation on the MXUnit blog.
Getting my CFSelenium tests working in Jenkins however was a different story.
Initially all my Selenium tests were failing with this cryptic error:
The Response of the Selenium RC is invalid: Timed out after 30000ms at C:\cfselenium\selenium.cfc:57...
My tests ran fine locally. Running locally CFSelenium will spool up the Selenium RC server but apparently this doesn’t automatically fire in Jenkins. The solution turned out to be configuring the Selenium RC server to run as a Windows service.
This is documented a few different ways on the web. Many people use various Java ‘wrappers’ like WinRun4J and JSLWin.
I did find a few posts about using a native Windows tool called srvany.exe which is bundled in the Window 2003 Resource Kit.
I of course am using Window 2008 server.
While there appears to be no kit for 2008, and running the 2003 installer throws up a ‘incompatible’ warning, I installed it anyway. :)
Download: Window 2003 Resource Kit
The only thing we need out of the kit is srvany.exe.
First we run a script which creates our service using the srvany.exe wrapper. I called it “SeleniumRC”. Adjust your paths accordingly.
:::bat sc create SeleniumRC binPath= "C:\Windows Resource Kits\Tools\srvany.exe" DisplayName= "SeleniumRC"
This creates your service. Before you start it however you need to setup a registry entry to point to correct executables.
Save this bit of code to a selenium.reg file, adjust your paths and run it (or add these bits to the registry manually).
Please note: Tinkering with your registry can really muck up your system. You’ve been warned!
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SeleniumRC\Parameters] "Application"="java.exe" "AppDirectory"="C:\\cfselenium\\Selenium-RC" "AppParameters"="-Xrs -jar selenium-server-standalone-2.24.1.jar"
I then started the service but running my Jenkins test still failed and it appeared the RC server still wasn’t starting up.
After a bit more searching I found a few posts which suggested creating a user and modifying the service to run as that user.
Once I did that things chugged along and my tests completed successfully!
I don’t think running the service all the time has any negative impact on the server. If you do run into issues there is a nice blog entry on the MXUnit wiki about how to start and stop services during your build.