Monday, April 24, 2006

Web Automated Testing in Ruby (WATIR)

I came across a very cool library in Ruby that allows Web UI testing using OLE automation. One of the problems with running automated tests of Web applications like a end user is the effort it takes to use libraries like Http Unit to setup test cases and execute them as part of your build process. WATIR (pronounced Water) is a ruby library that allows you test you web applications using OLE automation in your windows machine.

This is how it works:

You write unit test cases using WATIR and it actually invokes IE and actually does what a end user would do by entering form data, clicking on links, clicking buttons etc. You can then look at the resulting HTML DOM object and check if the web application did what it is supposed to. This is especially useful for testing multi-page wizard like applications where a lot of data entry is involved.

Here is a Step-by-step on how to install WATIR:

Install Ruby for Windows: http://rubyforge.org/projects/rubyinstaller/ (Look for download link)
Install WATIR: http://rubyforge.org/frs/?group_id=104 (Look for watir 1.4.1.exe)

It is pretty straight forward to create WATIR scripts. But, who wants to write these scripts by hand. You are right, I wouldn't. Instead you can use WATIR webrecorder, which records all your browser actions as WATIR scripts. All you need to do is record your testing once and then refactor it into a test script.

You can also pass -b switch to the WATIR script and it will not open the IE window and will execute the whole test in a headless mode that is ideal for test suites.

There is also another competing tool called Selenium that uses Javascript to drive tests and works across many browsers. I have not used it. But I have heard more people switch from Selenium to WATIR than the other way around.

3 comments:

  1. Excellent post!!! Selenium automation testing tool makes your software validation process lot simpler. Keep on updating your blog with such awesome information. Selenium Training in Chennai | Selenium Course in Chennai | Best Selenium training institute in Chennai

    ReplyDelete
  2. Your blog is awesome..You have clearly explained about it ...Its very useful for me to know about new things..Keep on blogging..
    Selenium training in chennai

    ReplyDelete
  3. I find this article interesting. But I actually have not understood some things. I am a beginner in testing. Do you know this software testing company http://www.deviqa.com/our-services/web-application-testing? I heard it is one of the best in this sphere.

    ReplyDelete