Simple test case
class MyTest < Watir::TestCase
def my_test
goto('
http://www.google.com')
text_field(:name, 'q').set 'ruby'
button(:name, 'btnG').click
assert(text.include? 'pickaxe')
end
end
Putting it all together
test1.rb:
goto('
http://www.google.com')
text_field(:name, 'q').set 'ruby'
button(:name, 'btnG').click
assert(text.include? 'pickaxe')
test2.rb:
goto('
http://www.google.com')
text_field(:name, 'q').set 'watir'
button(:name, 'btnG').click
assert(text.include? 'Holy Grail')
From the command line:
> watir -t test*.rb
This would automatically run the tests, creating a testcase wrapper for each test and then executing the combined suite.
Reusing browsers between tests
The "automatic" test suites will reuse a browser between tests, blanking the window, and recreate it if necessary. This is really the best way to use Watir.
* Possibly provide option to close and reopen between tests, but this is hard to make reliable!