Fork me on GitHub

Tuesday, November 25, 2008

Running Selenium RC as Windows Service

The story starts at a time when I was really tired to running FitNesse every time I start my office laptop. I wanted a way to run it perpetually and in my quest during a sleepless night found that FitNesse can indeed be run as a windows service. And after a long battle (actually a very short one) I am successfully running it now :) (For those who need that info check out FitNesse as service).

After this I got a crazy thought which is normal as far as I am concerned. Sometimes I use Selenium and Selenium RC also uses a jetty web server. Why can't I try to run selenium as a service so that I don't need to start it every time I log on (I remember this only after I see a test throwing exception :))? Well the steps are pretty simple. Same as how you make FitNesse run as a service so if you need, check out those instructions and translate the appropriate locations to Selenium.

One thing which needs to get noted is if the Selenium service is running in a account you have given or local system account without permission to interact with desktop then the tests will run and provide results but you will not be able to see them running. So if you need to see the test run visually in a browser then run in local account with permission for the service to interact with desktop. But the catch is if you run with access to desktop you will see all the messages which selenium will normally give in command line i.e. it will not run in background.

One more thing, I think most would have explored this but for people who are looking for a way to test application in Google Chrome you must be able to use Selenium RC with custom launcher. For more info checkout Selenium website.

Running of Selenium as service is an experiment I have done at night 1 PM because I was sleepless, so I hope people get the big red label warning I am trying to put here. I haven't clearly thought about the advantage or disadvantage of this method which I may do at a later post. Till then happy hacking and get some sleep :).

7 comments:

email said...

You say you do have it working? I am still fighting with the syntax on calling instsrv using the selenium rc jar. Can you post the command you are executing? Are you doing this on Windows 2003 Server?

Thanks,

Sai said...

Sure can do. Here it goes...
If you have the resource kit as I told you installed you will be having the instsrv in the path else you need to add in the system path.

Then run this command in the command line
> instsrv.exe Selenium "[path to srvany]\srvany.exe" -a [Domain]\[username] -p [password]

srvany will also be in resource kit. If you have any problems let me know...

Roger said...

But in your example, what is 'Selenium' in the example:

instsrv.exe Selenium ...

For Selenium RC, are you using a batch file? Otherwise, wouldn't it have to look like this:

instsrv.exe java -jar [path_to_selenium]\selenium-server.jar -interactive -multiWindow [path_to_srvany]\srvany.exe -a MyMachine\MyUser -p MyPass

?

Thanks,

Sai said...

Selenium is the service name. You can give any name there of your choice. All it does is to create a windows service for you which you can control in services.msc and an entry in registry. What you configure in the registry is important as thats what will link your selenium with the service...

Roger said...

Ok, then I am still missing a step. In your example:

> instsrv.exe Selenium "[path to srvany]\srvany.exe" -a [Domain]\[username] -p [password]

-instsrv.exe installs the service and gives it the name 'Selenium'
-svrany.exe creates a service for you

Right? I don't see in your example where you tell srvany.exe the location of Selenium RC.
I am using selenium-server-1.0-beta-1 which is a jar file (selenium-server.jar). Are you?

Thanks,

Sai said...

All those configuration of connecting the selenium to the service happens in the registry. You don't need to tell srvany or instsrv any of those things.

Please refer the sixth point in the Running FitNesse as Service page which talks about working with registry. Let me know if you need any help...

Nick said...

In case it's of any help to anyone, I wrote a quick step by step guide to getting SeleniumRC running as a Windows service:

Installing SeleniumRC as a Windows service