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