Tuesday, March 31, 2009

Start Automation Testing with WATIR

WATIR
I would like to share my knowledge on WATIR(Web Application Testing In Ruby language).It is pronounced water
What is WATIR?
WATIR is an open source automated testing tool in ruby language. This tool helps us in automated testing for any web application. It allows us to write Test cases .So that we can avoid the drawbacks of manual testing like time complexity , human resource, document management ,simplicity ,flexibility etc .We can easily write Test Cases by learning few commands of Ruby Language. Ruby also a object oriented programming language like JAVA.I feel this is one of very efficient and interesting Automated Testing tool. Also Watir is too much magic and is too confusing for people to understand.
WATIR Installation
->Download ruby advanced version (Ruby 1.8.*.*) and install it by just clicking setup file
->Go to command command prompt and type gem install watir .This step will completes your installation process !!!.
How it works ?
->Go to command prompt and type irb .irb is interactive ruby shell for ruby.
We can run the ruby command here .
require 'watir' # use watir gem
test_site = 'http://www.google.com' # set a variable
ie = Watir::IE.new # open the IE browser,here ie is the variable
ie.goto(test_site) # load url, go to site
ie.text_field(:name, "q").set("some Text") # load text "pickaxe" into search field named"q"
ie.button(:name, "btnG").click #btnG" is the name of the Search button, click it
if ie.text.include?("Programming Ruby")
puts "Test Passed. Found the test string: 'Programming Ruby'."
else
puts "Test Failed! Could not find: 'Programming Ruby'"
end

I reffered this example from http://wtr.rubyforge.org/.Save this code in a file with .rb extension . And to execute this file go to the parent directory via command prompt and type ruby file.rb
For more detail please refer
wtr.rubyforge.org/watir_user_guide.html
I will end with a list of most common beginner problems:
-> Capitalizing Watir in the require statement: require ‘watir’ NOT require ‘Watir’.

-> Not putting an “end” for the class statement in the test case file.
-> Leaving out the “class” statement in the test case file.
-> Not specifying that your test class inherits from Watir::TestCase.
-> Not starting the test case definition with def “test_”
-> Capitalizing of test names instead of keeping them lower case, “test_01_test_to_see_if this_works”.
Drawbacks
Watir is Ruby library that works only with Internet Explorer on Windows at present.Still trust me Watir is one of the most useful and very interesting framework.
If you have any doubt regarding WATIR please contact me on
nitil84@gmail.com.