Selenium RC for web application test automation

Selenium is a very popular - open source - web application test automation - tool.

Selenium is very powerful mainly because of the programming language support it has for - ruby, python, perl, java, etc. That brings a lot of these languages' features like adding logic and handling database connections to the test tool.

Today's web applications are multi-tiered and automating tests for them is a challenge. Selenium makes life easy by providing cross-platform execution and cross-browser compatibility.

So, how do we create and run Selenium tests ? Check out the following.

You need:

  1. Knoweldge in HTML will be extremely useful.
  2. Latest Java Runtime Environment (JRE). Get it from Oracle/Sun and install it. Test if it's installed correctly by running: java -version from the command line.
  3. Firefox browser. Download it from Mozilla and install
  4. Firebug Addon for Firefox browser. This Addon is very useful when locating elements and their attributes. Get it from getfirebug.com. Install the Addon. You should see 'Firebug' in the Firefox Tools menu option.
  5. Firexpath Addon for Firefox browser. This works with Firebug and is available as another tab 'xpath' in the firebug window. Sometimes, on dynamic web applications, attributes (id, name, etc) of the elements of a web page are dynamically generated too. This means everytime the page is generated, the attribute will change. Then, we have to uniquely identify the element in reference to a label or text surrounding it. So, get it from here
  6. Selenium RC. Selenium RC is the core engine that is used to execute the tests. Download it from seleniumhq.org/download/
  7. Selenium IDE. Selenium IDE is a Firefox Plug-in (Addon) used to record / create tests from the UI. Download it from seleniumhq.org/download/. After installation, you should see 'Selenium IDE' in the Firefox Tools menu option.
  8. Download psycopg2 if you need your scripts to talk to Postgresql via python. Download the psycopg2 windows installer for python version 2.6 from here: http://www.stickpeople.com/projects/python/win-psycopg/psycopg2-2.2.2.wi...

Steps to setup Selenium RC on Windows:

  1. Extract the downloaded Selenium RC package (Eg. selenium-remote-control-1.0.3.zip) into your local folder. You should see many folder as shown below
    1. C:\selenium-remote-control>dir
       Volume in drive C has no label.
       Volume Serial Number is 8496-7482

       Directory of C:\selenium-remote-control

      08/02/2010  11:35 AM    <DIR>          .
      08/02/2010  11:35 AM    <DIR>          ..
      08/02/2010  11:34 AM               224 README.txt
      08/02/2010  11:34 AM    <DIR>          selenium-dotnet-client-driver-1.0.1
      08/02/2010  11:34 AM    <DIR>          selenium-java-client-driver-1.0.1
      08/02/2010  11:34 AM    <DIR>          selenium-perl-client-driver-1.0.1
      08/02/2010  11:34 AM    <DIR>          selenium-php-client-driver-1.0.1
      08/03/2010  02:54 PM    <DIR>          selenium-python-client-driver-1.0.1
      08/02/2010  11:34 AM    <DIR>          selenium-ruby-client-driver-1.0.1
      08/02/2010  11:35 AM    <DIR>          selenium-server-1.0.3

  2.  You can now start the Selenium RC server
    1. C:\selenium-remote-control>java -jar C:\selenium-remote-control\selenium-server-1.0.3\selenium-server.jar
    2. The above is run with bare minimum options. If you need (it's a good practice), redirect the following output to a file by using the '-log <filename>' option.
      16:06:12.999 INFO - Java: Sun Microsystems Inc. 17.0-b16
      16:06:12.999 INFO - OS: Windows XP 5.1 x86
      16:06:13.049 INFO - v2.0 [a2], with Core v2.0 [a2]
      16:06:13.429 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
      16:06:13.439 INFO - Version Jetty/5.1.x
      16:06:13.439 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
      16:06:13.450 INFO - Started HttpContext[/selenium-server,/selenium-server]
      16:06:13.450 INFO - Started HttpContext[/,/]
      16:06:13.640 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@194ca6c
      16:06:13.640 INFO - Started HttpContext[/wd,/wd]
      16:06:13.670 INFO - Started SocketListener on 0.0.0.0:4444
      16:06:13.680 INFO - Started org.openqa.jetty.jetty.Server@c40c80
  3. Now start your firefox browser
  4. Launch Tools -> Selenium IDE. Notice a small window opens up. Selenium IDE starts in recording mode by default.
  5. Type in www.google.com in your browser, enter a search term and hit search button.
  6. Notice that all these actions and the values entered are recorded in the Selenium IDE window
  7. You can now save the script and click the Green button to replay the script

Note that by default Selenium stores your tests in plain HTML tables.

At this point you actually don't need Selenium RC to run the test you recorded using Selenium IDE. If it is a static page and does not involve any dynamic web content generation, this should suffice. But in the real world testing of web applications, this is not so. You need to use programming capabilities to use dynamic input data from a data source (could be a csv file, config file or even database).

So using a programming language becomes a necessity to make our test automation meaningful and worthwhile. You can use python, php, ruby, perl or java with Selenium RC to do this. I've used python and it's pretty good and easy to learn too.

I will write on using python with Selenium in another blog post.

Hope this was helpful. Here are some references that will be useful to learn how Selenium works.

 


User login

Who's new

  • amitbhagwat
  • TenLekerand
  • ClainaNaigh
  • RaviGunasekaran
  • gopasruhafoni

Who's online

There are currently 0 users and 2 guests online.