Testing

Using Selenium RC With Multiple Users

Thursday, March 13th, 2008

So you may be testing with selenium already, you may even be using selenium RC to automate your testing and integrate it with your other unit tests, and you may already be doing so in a shared development environment, but if you aren’t using selenium RC with multiple users, you may not know that you can start the RC server on any port you wish, allowing multiple clients to connect at the same time.

To start the selenium RC server, you would typically run this command:

Which will start it on the default port of 4444. If you want to start it on another port, simply add -port <portnumber> to the command like this:

This command would start the server on port 1234.

Great, now I can start the server on multiple ports, so what?

So here is the good news for those of us in shared development environments. Say you have a windows virtual machine running selenium with your test browser installed. Things get complicated when multiple clients are testing at the same time. Tests can fail unexpectedly, developers begin fighting for time on the test server, and all hell breaks loose. By running multiple servers on different ports, we can avoid the third world war. Everyone can connect at the same time to their personal server, and we have peace and harmony in our testing environment.

Wow, setting up a different port everytime must suck.

Not really. There are many ways that you can automate the process so that it’s completely transparent to your development team. A lot will depend on your environment, but in our case, we created a .bat file that starts the servers in our virtual machine and placed it in the start-up folder.

With this in place, we now have 4 selenium RC servers running at all times. If one or more crashes for any reason, running the batch file again will start any that are missing. The selenium RC server will not start if its port is in use, so only the ones missing will run, and you’ll have them all up and running again.

Ok, what about the client side? I don’t want to have to edit another file in my development environment.

On the client side, we are using phpunit with Testing_Selenium. Of course all of our selenium test classes extend a parent class, so it was easy enough for us to create some dynamic logic there to decide which port to use.