|
Red Squirrel Reflections
Dave Hoover explores the psychology of software development
|
|
Thu, 07 Sep 2006After showing some hacked up examples of Watir and Rails integration at RailsConf and last Friday's Ajax on Rails addon, I decided that I was way overdue to venture into the exciting world of Rails Plugins. And just a few hours later, Watir on Rails was born. Here's a quickstart... gem install [safari]watir ./script/plugin install svn://rubyforge.org/var/svn/watir-on-rails ./script/generator watir SuccessfulLogin ./script/server -e test rake test:watir One of my goals for this first release was to make Watir on Rails have a similar feel to Rails Integration Tests, which provide a handy open_session method you can use to decorate your session object with a site-specific language. Well, if you know anything about Watir, it should not come as a surprise that Watir on Rails provides an open_browser method that does something similar. You can use open_browser to simply open a browser and use the excellent Watir API, or you can provide an optional block and write Watir on Rails tests methods like this...
def test_login
browser = open_browser
browser.login_with :username => "dave", :password => "test"
assert_match /Welcome Dave/, browser.div(:id, "banner").text
end
def open_browser
super do |browser|
def browser.login_with(args)
goto("http://localhost:3000/login")
text_field(:name, "user[name]").set(args[:username])
password(:name, "user[password]").set(args[:password])
button(:name, "login").click
end
end
end
|