Use Watir with RSpec with ease.
- No need to use the
@browser
or$browser
variables when executing browser methods. - No need to open the browser in your each test manually.
- Easily test for asynchronous events by using
#within
matchers. - Easily test that something stays the same within some period by using
#during
matchers. - Get nice html reports with links to html, screenshots and other files generated during test.
Add these lines to your application's Gemfile:
group :test do
gem "watir-rspec"
end
Or install it manually as:
gem install watir-rspec
And execute the following command to add watir-rspec
configuration into your spec_helper
:
watir-rspec install
Check out the documentation and the straight-forward fully working examples below.
require "spec_helper"
describe "Google" do
before { goto "http://google.com" }
it "has search box" do
expect(text_field(name: "q")).to be_present
end
it "allows to search" do
text_field(name: "q").set "watir"
button(id: "gbqfb").click
results = div(id: "ires")
expect(results).to be_present.within(2)
expect(results.lis(class: "g").map(&:text)).to be_any { |text| text =~ /watir/ }
expect(results).to be_present.during(1)
end
end
You can use Watir::RSpec.file_path
to have links automatically in the html report
to the files created during tests.
uploaded_file_path = Watir::RSpec.file_path("uploaded.txt")
File.open(uploaded_file_path, "w") {|file| file.write "Generated File Input"}
file_field(name: "upload-file").set uploaded_file_path
You need to use rspec-rails and watir-rails gems together with watir-rspec
to achieve maximum satisfaction.
Copyright (c) Jarmo Pertman (jarmo.p@gmail.com). See LICENSE for details.