Ryan Bates did a great job covering Webrat in Railscast #156, and I’d recommend anyone who hasn’t used Webrat check it out. It’s a clear demonstration of how you can start using Webrat in a few minutes today with Rails built-in integration testing framework. Webrat works with RSpec, Cucumber, Shoulda, etc. too, but they aren’t required.
Unfortunately, during the screencast some Webrat bugs prevented running the tests in Selenium mode. Webrat has worked with Selenium for some time, but there have been some lingering rough edges around getting it up and running that I’ve been meaning to resolve. Today I’m happy to report those issues are now fixed, and getting started using Selenium with Webrat should now be drop-dead simple.
Give it a try by checking out the full Episode #156 source code, then make the following changes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# config/environments/test.rb
config.gem "webrat", :version => ">=0.4.4" # was 0.4.3
# test/test_helper.rb
class ActiveSupport::TestCase
# ...
self.use_transactional_fixtures = false # was true
# ...
# Add these lines:
setup do |session|
session.host! "localhost:3001"
end
end
Webrat.configure do |config|
config.mode = :selenium # was :rails
end |
Running the test again should pop open a Firefox window for the running tests and print output like this:
$ rake test:integration
(in /Users/bhelmkamp/p/railscasts-episodes/episode-156/authenticator)
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
Started
==> Waiting for Selenium RC server on port 4444... Ready!
==> Waiting for rails application server on port 3001... Ready!
..
Finished in 11.679288 seconds.
2 tests, 2 assertions, 0 failures, 0 errors
Success!
Note: I just pushed Webrat 0.4.4, so it might not be available on all the gem sever mirrors yet. If not, you can install it with the following commands:
git clone git://github.com/brynary/webrat.git
cd webrat
rake install_gem