Skip to content

chip/watir-on-rails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Use this plugin to run Watir tests in Rails.

Watir (Web Application Testing in Ruby) supports Internet Explorer, with Safari
and Firefox ports in development.  Watir boasts a dead simple setup and an
intuitive API for driving browsers programatically.  Visit
http://wtr.rubyforge.org/ for more information.


Dependencies
============

If you're running Windows, you'll need to
  gem install watir

If you're fortunate enough to be on OS X, you can
  gem install safariwatir


Installation
============

You have probably already done this, but just in case...
  script/plugin install svn://rubyforge.org/var/svn/watir-on-rails

For version compatible with Rails 2.3.2 (provided by Chip Castle <chip@chipcastle.com>):
  script/plugin install git://github.com/chip/watir-on-rails.git 

Generating Tests
================

You can use the generator to create skeleton Watir tests in test/watir
  script/generate watir Login


Running Tests
=============

Watir tests can be executed by running
  rake test:watir
You'll need to have a test server running.


Decorating Watir with a DSL
===========================

Similar to Rails Integration Tests, WatirOnRails provides developers with the
means to add singleton methods to the browser instance, allowing for the
development of a site-specific language.  The WatirOnRails open_browser method
is mixed into the TestCases generated by Watir.  This method will return an
instance of a Watir browser.  Similar to Rails IntegrationTest's open_session,
it takes an optional block, yielding the browser instance.  A simple
WatirOnRails test method might look like this...

  def test_login
    browser = open_browser
    browser.goto("/login")
    browser.text_field(:name, "user[name]").set("dave")
    browser.password(:name, "user[password]").set("test")
    browser.button(:index, 1).click
    assert_select "div#banner", /Welcome Dave/
  end

...while a slightly more advanced WatirOnRails test method using a site-
specific language might look like this...

  def test_login	
    browser = open_browser
    browser.login_with :username => "dave", :password => "test"
    assert_select "div#banner", /Welcome Dave/
  end

  def open_browser
    super do |browser|
      def browser.login_with(args)
        goto("/login")
        text_field(:name, "user[name]").set(args[:username])
        password(:name, "user[password]").set(args[:password])
        button(:name, "login").click
      end      
    end
  end


SEND FEEDBACK!
==============

Dave Hoover
dave.hoover@gmail.com
http://redsquirrel.com/dave/

About

This plugin was upgraded to be Rails 2.3.2 compatible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages