Monday, October 08, 2007

Watir Is Insanely Great

I just started using Watir to do GUI testing of web apps and am blown-away. Watir is so easy to use. I wrote my first script from the examples. It opens google image search and shows pictures of kittens.

require "watir"
ie = #create an object to drive the browser
ie.goto ""
ie.url == "", "Images").flash #flash the item text "Images", "Images").click #click on the link to the images search page
ie.text.include? "The most comprehensive image search on the web" #test to make sure it worked
searchTerm = "kittens" #set a variable to hold our search term
ie.text_field(:name, "q").set(searchTerm) # q is the name of the search field
ie.button(:name, "btnG").click # "btnG" is the name of the google button
if ie.contains_text(searchTerm)
puts "Test Passed. Found the test string: #{searchTerm}. Actual Results match Expected Results."
puts "Test Failed! Could not find: #{searchTerm}"

No comments: