Friday, 7 January 2011

Selenium Grid Part 4 – How to get Multiple Browsers and Operating Systems working

One of the cool features of Selenium Grid other than being able to distribute your tests over multiple computers is its support for multiple environments. An environment is a combination of the operating system and the browser. For instance I have four virtual machines one running Ubuntu and two running Windows XP. I needed two windows machines as it is easier to set up two machines than get two version of IE running on the same machine. These are the environments I set up:
  • Firefox 3.5 on Linux
  • Firefox 3.6 on Linux
  • Firefox 3.5 on Windows XP
  • Firefox 3.6 on Windows XP
  • IE6 on Windows XP
  • IE7 on Windows XP

The environments are fully flexible so you can set up pretty much anything you want in the way of environments. The only limit in combinations is the different browsers and operating systems which Selenium has support for.

So where to start? Firstly have a look at my other blog posts on getting Selenium Grid set up and running (links at the bottom of the page).

The Grid Hub will need to know about the environments you want to have. This is configure in the grid_configuration.yml file. This the config I am using:
grid_configuration.yml
hub:
   port: 4444
   remoteControlPollingIntervalInSeconds: 180
   sessionMaxIdleTimeInSeconds: 300
   environments:
       - name:    "Firefox35 on Linux"
         browser: "*firefox"
       - name:    "Firefox36 on Linux"
         browser: "*firefox"
       - name:    "IE6 on WindowsXP"
         browser: "*iehta"
       - name:    "IE7 on WindowsXP"
         browser: "*iehta"
       - name:    "Firefox35 on WindowsXP"
         browser: "*firefox"
       - name:    "Firefox36 on WindowsXP"
         browser: "*firefox"

For the different version of Firefox I didn't install them per se as you can only really have one Firefox installed at a time. On Linux I downloaded the .tar.bz2 files from Mozilla and just extracted them. On Windows I used the Portable Apps versions of Firefox as would allow me to install independent of Firefox that don't mess with the registry and stomp on each other.

For each different browser you want to have available on an Operating System you need to have a separate remote control running (though there is bug open for this). To tell the remote control where to find the different Firefoxes I added the relelvant path to the Firefox executable to the path before launching the remote control. You can see some examples below; the main gotcha is ensuring that the port numbers don't clash and that you change the IP address to the current host (I am researching how I could make this automatic if you have any ideas please let me know).
Firefox 3.5 on Linux:
cd Desktop/selenium-grid-1.0.8/
export PATH="$PATH:/home/user/Desktop/firefox35/"
ant -Dport=5555 -Dhost=172.24.128.70 -DhubURL=http://172.24.128.68:4444/ -Denvironment="Firefox35 on Linux" -DseleniumArgs="-multiWindow"  launch-remote-control

Firefox 3.5 on Windows:
cd c:\selenium-grid-1.0.8
path %path%;C:\Firefox35\App\Firefox
C:\apache-ant-1.8.2\bin\ant.bat -Dport=5555 -Dhost=172.24.128.76 -DhubURL=http://172.24.128.68:4444/ -Denvironment="Firefox35 on WindowsXP" -DseleniumArgs="-multiWindow"  launch-remote-control

IE6 on Windows:
cd c:\selenium-grid-1.0.8
C:\apache-ant-1.8.2\bin\ant.bat -Dport=5554 -Dhost=172.24.128.76 -DhubURL=http://172.24.128.68:4444/ -Denvironment="IE6 on WindowsXP" -DseleniumArgs="-multiWindow"  launch-remote-control

From those you should be able to figure out how to do most other broswers.

Once you have started them up you should be able to see them all connected to the hub when you have a look at its console (http://:4444/console). So now you need to run your tests against all the different environments you know have. Will I basically outlined the process in Part 3 so you can copy most of the code from there. The change I made was to SWrunner.py to add more browsers to it. You can see it below:
SWrunner.py
#!/usr/bin/python
'''
Created on 17 July 2010
@author: Dave

This is the test runner to run all the tests

Idea from: http://viewvc.svn.mozilla.org/vc/projects/sumo/tests/frontend/python_tests/suite_sumo.py?view=markup
Idea from: http://saucelabs.com/blog/index.php/2009/09/running-your-selenium-tests-in-parallel-python/
'''

import SWfunctions
from SWconfig import connectionParameters
from SWtestList import testList
import sys
from subprocess import Popen


args = sys.argv

type = None

if len(args) < 2:
    type = 'smoke'
else:
    type = args[1]

tests = []    

if type == 'smoke':
    tests = testList.smoke_list
elif type == 'full':
    tests = testList.full_list

browsers = []
#browsers.append('*firefox')
#browsers.append('Firefox40\ on\ Linux')
browsers.append('Firefox35\ on\ Linux')
browsers.append('Firefox36\ on\ Linux')
browsers.append('IE6\ on\ WindowsXP')
browsers.append('IE7\ on\ WindowsXP')
browsers.append('Firefox35\ on\ WindowsXP')
browsers.append('Firefox36\ on\ WindowsXP')
#browsers.append('Firefox40\ on\ WindowsXP')

processes = []

for browser in browsers:
    vars = connectionParameters
    for test in tests:
        processes.append(Popen('python %s %s %s %s %s %s' % (test, vars.server, vars.port, browser, vars.baseurl, vars.page_load_timeout), shell = True))
        
for process in processes:
    process.wait()

So basically that is what you need to do to Selenium Grid working with multiple environments. Any questions, comments, suggestions, etc there is the comments section at the bottom of this post.

The Series:

Upcoming ideas for the series:
  • Putting the test suite in SVN and running from there

6 comments:

Karit said...

If you have issues running Firefox on a 64 bit Linux you will need to install some 32bit libraries. E.g. on Ubuntu run:
sudo apt-get install ia32-libs

safetytrick said...

You posted about getting firefox 4 to work on google groups, I'm having trouble getting a similar setup to work with firefox 4 because of my user-extensions.js (not the content of the file, the file itself isn't being loaded) Were you able to get FF4 to work with user-extensions?

Karit said...

Sorry I am yet to get Firefox and haven't spent too much time on it, as currently it is not on the required list of browsers at work.

GoogleDan said...

I'm confused :) I start a RC on my Windows machine and it registers itself with the hub on my Mac. But when I try to run my test targeting that environment, nothing happens.

But if I start another RC on the Mac, same environment (Firefox on Windows), same port, host set to IP of the PC, then the test runs fine. It only seems to run if I have both of these RCs running. Here's what my Hub looks like:

localhost 5558 Firefox on Windows
172.18.33.119 5558 Firefox on Windows

Am I supposed to have a RC running on BOTH machines?

Karit said...

Shouldn't need the RC running on both. What do the log files say is happening? Have you tried bypassing the Hub and sending the commands directly to the RC (just change IP and Ports etc) and see if that works?

Preeti said...

It is very wonderfull center