2
votes

Is watir-rspec meant to work with watir or watir-webdriver?

I am currently using watir and rspec.

I am trying to setup watir-rspec so I can use the html-formatter and take screenshots and embed them in my html log file.

I have read the readme on github and it states to "add these lines to your spec_helper.rb file"

I am just unsure of where and which spec_helper.rb file it is referring to.

the code it states to add is below:


        RSpec.configure do |config|
          # Add Watir::RSpec::HtmlFormatter to get links to the screenshots, html and
          # all other files created during the failing examples.
          config.add_formatter('documentation')
          config.add_formatter(Watir::RSpec::HtmlFormatter)

          # Open up the browser for each example.
          config.before :all do
            @browser = Watir::Browser.new
          end

          # Close that browser after each example.
          config.after :all do
            @browser.close if @browser
          end

          # Include RSpec::Helper into each of your example group for making it possible to
          # write in your examples instead of:
          #   @browser.goto "localhost"
          #   @browser.text_field(:name => "first_name").set "Bob"
          #
          # like this:
          #   goto "localhost"
          #   text_field(:name => "first_name").set "Bob"
          #
          # This needs that you've used @browser as an instance variable name in
          # before :all block.
          config.include Watir::RSpec::Helper
        end
1

1 Answers

4
votes

Since watir-classic and watir-webdriver share the same API, watir-rspec should be compatible with both.

The spec_helper.rb is typically where you write any configuration for your rspec suite. This file is then required by each of your spec files.

As an example, you can see spec_helper.rb used in watirspec, which is the majority of the specs for watir-classic and watir-webdriver - see https://github.com/watir/watirspec.

Some tutorials that might help you understand the spec_helper.rb: