如何从头开始设置watir-rspec

时间:2013-11-19 12:50:56

标签: ruby rspec automated-tests watir

我正在努力为我的网络项目设置watir-rspec框架进行ui测试。 (https://github.com/watir/watir-rspec

以下是我采取的步骤:

  • 已安装的Ruby 2.0.0
  • 已安装watir-rspec gem
  • 我的项目的ui-test /目录
  • 上安装了watir-rspec
  • 将example_spec.rb文件制作成ui-test / spec文件夹,并将文档中的示例复制到文件中。
  • 尝试从cmd:rspec spec / example_spec.rb
  • 运行它

以下是我遇到的错误:

C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-rspec-1.1.0/lib/watir/rspec/helper.rb:4:in `<module:Helper>': uninitialized constant Watir::RSpec::Helper::Forwardable (NameError)
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-rspec-1.1.0/lib/watir/rspec/helper.rb:3:in `<class:RSpec>'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-rspec-1.1.0/lib/watir/rspec/helper.rb:2:in `<module:Watir>'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-rspec-1.1.0/lib/watir/rspec/helper.rb:1:in `<top (required)>'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-rspec-1.1.0/lib/watir/rspec.rb:47:in `<top (required)>'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `require'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `rescue in require'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:35:in `require'
  from C:/wamp/www/smart/tests/ui-test/spec/spec_helper.rb:3:in `<top (required)>'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
  from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
  from C:/wamp/www/smart/tests/ui-test/spec/example_spec.rb:1:in `<top (required)>'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
  from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

我错过了哪些步骤?我甚至试图正确地运行测试吗?

显然我对这件事情有点新鲜 - 任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

您看到的异常似乎是watir / rspec执行extend Forwardable,并假设已经需要Forwardable。添加require 'forwardable'将解决此问题。

一旦修复了,我得到了未初始化的常量Watir :: Browser异常。似乎watir / rspec不会自动为您提供watir。您需要手动执行此操作,因此添加require 'watir'行。

总之,按照您所做的步骤,我发现我必须对spec_helper.rb进行2次更改。在文件的顶部(即require watir/rspec行之前)添加以下行:

require 'forwardable'
require 'watir'