Thursday, October 28, 2010

Executing Tests in multiple environments using Selenium Grid

                      Our Business Team came up with a requirement of having support for multiple Browsers like Google Chrome, Internet Explorer 6, Internet Explorer 7 and Internet Explorer 8. Till yesterday I was happily executing my Selenium tests in firefox and now I have to find a way in which I can run my test cases in different browsers. First thought I got is to install all the browsers on my laptopn and test. But unfortunately I realized that I cannot install all the Internet Explorer versions on single machine. So I have started exploring different options and came across Selenium Grid. It is an extension of Selenium Core. The idea is simple there will be a Master and many slaves. Master will give the commands and slaves will be executing these commands.

Process of setting up Selenium Grid.

These steps have to done both on Master and Slave machines. 
  1. Download and install the Java JRE. Verify the installation by issuing a command "java -version" on command prompt.
  2. Download and extract Apache Ant and put the path in PATH environment variable. Verify the installation by issuing a command "ant -version" on command prompt.
  3. Download and extract Selenium Grid.
You are done with the setup. :)

Making a machine master
  1. In Command prompt from the folder where you have extracted "Selenium Grid" run "ant launch-hub"
  2. To Verify just got to http://localhost:4444/console from your favourite browser
  3. There will be 3 tables on the Web Page. First shows Environments defined in file named "grid_configuration.yml" located at the root directory of the extracted location of selenium grid. the second column shows what remote controls are available and the third column shows what remote controls are currently running tests.
  4. For our purpose let us add some new environments for Internet Explorer 6, Internet Explorer 7, Internet Explorer 8. Copy paste the following lines at the end of "grid_configuration.yml"
       - name:    "*iexplore6"
         browser: "*iexplore"
       - name:    "*iexplore7"
         browser: "*iexplore"
       - name:    "*iexplore8"
         browser: "*iexplore"
You are done with Master Setup. :)

Making a machine which is having Internet Explorer 6 installed as slave

 In Command prompt from the folder where you have extracted "Selenium Grid" run
ant -Denvironment=*iexplore6 launch-remote-control -DhubURL=http://192.168.0.111:4444 -Dhost=192.168.0.112
where 192.168.0.111 is the ipaddress of Master and 192.168.0.112 is the ipaddress of slave. One can use hostname instead of IPAddresses if they are added in DNS.

Making a machine which is having Internet Explorer 7 installed as slave

 In Command prompt from the folder where you have extracted "Selenium Grid" run

ant -Denvironment=*iexplore7 launch-remote-control -DhubURL=http://192.168.0.111:4444 -Dhost=192.168.0.113
where 192.168.0.111 is the ipaddress of Master and 192.168.0.113 is the ipaddress of slave. One can use hostname instead of IPAddresses if they are added in DNS.

Making a machine which is having Internet Explorer 8 installed as slave
    
 In Command prompt from the folder where you have extracted "Selenium Grid" run
ant -Denvironment=*iexplore8 launch-remote-control -DhubURL=http://192.168.0.111:4444 -Dhost=192.168.0.114
where 192.168.0.111 is the ipaddress of Master and 192.168.0.114 is the ipaddress of slave. One can use hostname instead of IPAddresses if they are added in DNS.

Verify the setup at http://localhost:4444/console. You should see something like

You are done with Slaves Setup. :)

Important: You have to use *iexplore6 or *iexplore7 or *iexplore8 in your Test Cases instead of *iexplore.
I am using ROBOT Framework to run my selenium tests. So I can run tests using
pybot.bat -l Run1.html -o Run1out.xml -r Run1Report.html "C:\Users\yagnanarayana dande\Desktop\TestsIE6.html"
Remember Pybot cannot run in parallel. So start different pybots per environment like

pybot.bat -l Run1.html -o Run1out.xml -r Run1Report.html "C:\Users\yagnanarayana dande\Desktop\TestsIE6.html"
pybot.bat -l Run1.html -o Run1out.xml -r Run1Report.html "C:\Users\yagnanarayana dande\Desktop\TestsIE7.html"
pybot.bat -l Run1.html -o Run1out.xml -r Run1Report.html "C:\Users\yagnanarayana dande\Desktop\TestsIE8.html"

To remove any slave from your grid due to reasons like machine died during execution the use
 http://192.168.0.111:4444/registration-manager/unregister?host=192.168.0.113&port=5555&environment=*iexplore7

No comments:

Post a Comment