Can’t get enough UI testing' Try some Watir!

by Michael McClenaghan 2005-07-04

This is pretty freaking sweet.  I've been looking for a nice app that our QA guy at work could use to help with testing.  Maybe this is it'  It's a nice side-benefit that it can jive with NUnit as well. 

Integrating Ruby and Watir with NUnit:

Watir is an open source functional testing library for automated tests to be developed and run against a web browser. Cool'

Here's an example that visits Google, searches for "Programming Ruby" and confirms that it found what it was looking for. The stuff after the # are comments.

require'watir'# the watir controller
includeWatir
test_site='http://www.google.com'
ie=IE.new
ie.goto(test_site)
ie.text_field(:name,
"q").set("pickaxe")# q is the name of the search field
ie.button(:name,"btnG").click# "btnG" is the name of the Search button
ifie.contains_text("Programming Ruby")
  puts"Test Passed. Found the test string: 'Programming Ruby'. Actual Results match Expected Results."
else
  puts"Test Failed! Could not find: 'Programming Ruby'"
end

If you want get Ruby and Watir and start playing:

  • Download Ruby for Windows
  • Download Watir and run install.rb
  • Go into C:\watir_bonus\examples and run googleSuite_test.rb
  • Then, look at articleExample.rb and make some changes to test your own site.
  • Enjoy. Feel free to integrate into your NUnit tests if you like using our code above. If you expand it, let us know.
[Via ComputerZen.com - Scott Hanselman's Weblog]
blog comments powered by Disqus