Friday, 19 December 2008

How to run Selenium-RC in a virtual machine

A tale of VMWare vs VirtualPC
One issue that I have with selenium and running tests through IE is the little popup dialog saying "The web page you are viewing is trying to close the window. do you want to close this window?"
Our tests use openWindow and then close them frequently.
I wrote a little AutoIt script to sit in the background and poll for that dialog and close it when it appears.
But sometimes the AutoIt script makes it difficult for me to use the PC at the same time as the scripts run, so I decided to use VirtualPC to run the Selenium-RC server. And that would surely solve my problems? But oh no, then my problems really began...

The once commercial (and I bought it) VirtualPC now has free status - download it and use it for Free.
So I used it to:
  • Create a new Windows machine.
  • Install the browsers,
  • Install Java,
  • Installed selenium,
  • Copy across my AutoIt script,
  • Got the IP address of the VirtualPC using "ipconfig -all" .
I then amended my test setup on my host machine to use the IP address of the VirtualPC  as an argument in the DefaultSelenium constructor.
And finally started selenium-RC from a command prompt in VirtualPC (I tend to open a command window with the Microsoft Power Toy "Open Command Window Here")
java -jar selenium-server.jar
As ever I title the command window so I can find the server easily in the TaskBar.
Start up my test and voila... Hmm.... Selenium test won't connect to the server on the Virtual PC.
Issue with Selenium? Issue with VirtualPC setup? I'll check... ping the virtual PC... no response.
Oh, OK - I'll switch off the Firewall and enable pings from the advanced settings.
Still no response.
Hmmm... I can connect to the internet from the virtualPC. I can ping my host PC from the virtual PC. I don't know why this won't work.
Time to check with Google - and I see other people have experienced the same problem but none of the proffered solutions worked for me - time to get radical.
So I used the VMWare converter to turn the VirtualPC image into a VMWare image for the free VMWare player.
VMWare worked out of the box. I suspect that this happened because VMWare installs a 'virtual ethernet card' in your machine but I had to use Shared Network Connection in VirtualPC. So obviously not everyone will experience this problem.
Virtual PC has a lot going for it:
  • free,
  • you can create your own machine images,
  • Microsoft give away some Compatibility images for compatibility testing.
Sadly for this one thing, on this one environment, it failed to meet my needs.
So if you want to run Selenium-RC Server in a virtual machine you have multiple options, VMWare player and VirtualPC as the most obvious. I didn't need to go as far as using VirtualBox, but if I ever need a free solution for Mac I will try that.

<Engage Soul voice>: "But whatever you choose to use kids. Never forget... Testing and Virtualization - It's good."
Related Links:


  1. [...] Note - when using VirtualPC - I have had to turn on the "Shared networking" from the Networking Setting in certain networking situations. This can cause problems if you want to use the VM for automated testing (but we covered that in an earlier post) [...]

  2. [...] mentioned this script in a previous post - but I forgot to upload it. Hence this [...]

  3. VirtualBox has the same problem if you want to setup networking as NAT. It has a 'fake' NAT so the guest is not accessible from the host.

    I haven't tested yet with the Bridge setup (that makes the guest accessible in the LAN) as I'm on a LAN that does not allow new computers.

    Thanks Dira.