Revision as of 19:15, 25 September 2006 editSunSw0rd (talk | contribs)Extended confirmed users796 editsm Added RubyGems link← Previous edit | Revision as of 19:55, 25 September 2006 edit undoSunSw0rd (talk | contribs)Extended confirmed users796 edits Added "Examples" section, removed stub indicatorNext edit → | ||
Line 5: | Line 5: | ||
WATIR makes use of the fact that Ruby has built in OLE capabilities. As such it is possible to drive the Microsoft Internet Explorer browser programmatically. Watir is a toolkit for automated tests to be developed and run against a web browser. | WATIR makes use of the fact that Ruby has built in OLE capabilities. As such it is possible to drive the Microsoft Internet Explorer browser programmatically. Watir is a toolkit for automated tests to be developed and run against a web browser. | ||
==Examples== | |||
The google example: | |||
# Here we see a very simple WATIR script to drive to google and validate a page | |||
require 'watir' # use watir gem | |||
test_site = 'http://www.google.com' # set a variable | |||
ie = Watir::IE.new # open the IE browser | |||
ie.goto(test_site) # load url, go to site | |||
ie.text_field(:name, "q").set("pickaxe") # 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.contains_text("Programming Ruby") | |||
puts "Test Passed. Found the test string: 'Programming Ruby'." | |||
else | |||
puts "Test Failed! Could not find: 'Programming Ruby'" | |||
end | |||
The previous commands can be executed in the ] (irb), or in a Ruby IDE such as FreeRIDE that is installed when Ruby is installed with the once click installer. | |||
Handling popups: | |||
# To handle general popups, use WinClicker. | |||
ie.button(:name, "btnG").click_no_wait # ensure popup won't block Watir | |||
hwnd = ie.enabled_popup(5) # get a handle if one exists | |||
if (hwnd) # yes there is a popup | |||
w = WinClicker.new | |||
w.makeWindowActive(hwnd) | |||
w.clickWindowsButton_hwnd(hwnd, "Yes") # click the "Yes" button | |||
end | |||
This example extends upon the google example by ensuring the google search button click will not wait for the popup. This approach will handle most annoying popups, however it may be necessary to download and install the current development Watir gem rather than using the standard Watir release. | |||
==External Links== | ==External Links== | ||
Line 19: | Line 48: | ||
] | ] | ||
{{computer-stub}} |
Revision as of 19:55, 25 September 2006
'WATIR', pronounced "Water", is an acronym standing for "Web Application Testing in Ruby". Watir is an automated test tool which uses the Ruby scripting language to drive the Internet Explorer web browser, and is available as a Ruby Gem.
Ruby is an object oriented programming language started more than a decade ago in Japan (by Yukihiro Matsumoto). It is a very “pure” OO language. It is also an interpreted language, and has influences from multiple earlier OO languages. Ruby gems are packaged libraries.
WATIR makes use of the fact that Ruby has built in OLE capabilities. As such it is possible to drive the Microsoft Internet Explorer browser programmatically. Watir is a toolkit for automated tests to be developed and run against a web browser.
Examples
The google example:
# Here we see a very simple WATIR script to drive to google and validate a page require 'watir' # use watir gem test_site = 'http://www.google.com' # set a variable ie = Watir::IE.new # open the IE browser ie.goto(test_site) # load url, go to site ie.text_field(:name, "q").set("pickaxe") # 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.contains_text("Programming Ruby") puts "Test Passed. Found the test string: 'Programming Ruby'." else puts "Test Failed! Could not find: 'Programming Ruby'" end
The previous commands can be executed in the Interactive Ruby Shell (irb), or in a Ruby IDE such as FreeRIDE that is installed when Ruby is installed with the once click installer.
Handling popups:
# To handle general popups, use WinClicker. ie.button(:name, "btnG").click_no_wait # ensure popup won't block Watir hwnd = ie.enabled_popup(5) # get a handle if one exists if (hwnd) # yes there is a popup w = WinClicker.new w.makeWindowActive(hwnd) w.clickWindowsButton_hwnd(hwnd, "Yes") # click the "Yes" button end
This example extends upon the google example by ensuring the google search button click will not wait for the popup. This approach will handle most annoying popups, however it may be necessary to download and install the current development Watir gem rather than using the standard Watir release.
External Links
- Rubyforge Homepage for the tool
- Watir User Guide
- Current Watir Development Versions
- The Ruby Homepage
- Ruby Gems User Guide