2

watir-rspec 是否适用于 watir 或 watir-webdriver?

我目前正在使用 watir 和 rspec。

我正在尝试设置 watir-rspec,以便我可以使用 html-formatter 并截取屏幕截图并将它们嵌入到我的 html 日志文件中。

我已经阅读了 github 上的自述文件,它声明“将这些行添加到您的 spec_helper.rb 文件中”

我只是不确定它指的是哪里和哪个 spec_helper.rb 文件。

它声明要添加的代码如下:


        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
4

1 回答 1

4

由于 watir-classic 和 watir-webdriver 共享相同的 API,因此 watir-rspec 应该与两者兼容。

spec_helper.rb通常是您为 rspec 套件编写任何配置的地方。然后,您的每个规范文件都需要此文件。

例如,您可以spec_helper.rb在 watirspec 中看到 used,这是 watir-classic 和 watir-webdriver 的大部分规范 - 请参阅https://github.com/watir/watirspec

一些可能有助于您理解的教程spec_helper.rb

于 2013-06-04T03:15:36.807 回答