“在Cucumber中运行Feature时,无法加载此类文件 - watir(LoadError)”

时间:2017-10-29 13:11:33

标签: automation rubygems cucumber bundler watir

我目前正在设置一些Cucumber测试,我的Hook文件包含以下内容:

require 'watir'

Before do
  @browser = Watir::Browser.new :chrome
end

After do
  @browser.close
end

当我运行我的功能文件时,我得到以下内容:

cannot load such file -- watir (LoadError)
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/marklane/RubymineProjects/test_puppies/features/support/hooks.rb:2:in `<top (required)>'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `each'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:40:in `run!'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
/Users/marklane/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
/Users/marklane/.rbenv/versions/1.9.3-p194/bin/cucumber:23:in `load'
/Users/marklane/.rbenv/versions/1.9.3-p194/bin/cucumber:23:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'

我的Gem文件锁是:

GEM
  remote: https://rubygems.org/
  specs:
    backports (3.10.3)
    builder (3.2.3)
    childprocess (0.8.0)
      ffi (~> 1.0, >= 1.0.11)
    concurrent-ruby (1.0.5)
    cucumber (3.0.1)
      builder (>= 2.1.2)
      cucumber-core (~> 3.0.0)
      cucumber-expressions (~> 4.0.3)
      cucumber-wire (~> 0.0.1)
      diff-lcs (~> 1.3)
      gherkin (~> 4.0)
      multi_json (>= 1.7.5, < 2.0)
      multi_test (>= 0.1.2)
    cucumber-core (3.0.0)
      backports (>= 3.8.0)
      cucumber-tag_expressions (>= 1.0.1)
      gherkin (>= 4.1.3)
    cucumber-expressions (4.0.4)
    cucumber-tag_expressions (1.0.1)
    cucumber-wire (0.0.1)
    data_magic (1.2)
      faker (>= 1.1.2)
      yml_reader (>= 0.6)
    diff-lcs (1.3)
    faker (1.8.4)
      i18n (~> 0.5)
    ffi (1.9.18)
    gherkin (4.1.3)
    i18n (0.9.0)
      concurrent-ruby (~> 1.0)
    multi_json (1.12.2)
    multi_test (0.1.2)
    page-object (2.2.4)
      page_navigation (>= 0.10)
      selenium-webdriver (~> 3.0)
      watir (~> 6.8)
    page_navigation (0.10)
      data_magic (>= 0.22)
    rake (12.2.1)
    rspec (3.7.0)
      rspec-core (~> 3.7.0)
      rspec-expectations (~> 3.7.0)
      rspec-mocks (~> 3.7.0)
    rspec-core (3.7.0)
      rspec-support (~> 3.7.0)
    rspec-expectations (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-mocks (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-support (3.7.0)
    rubyzip (1.2.1)
    selenium-webdriver (3.6.0)
      childprocess (~> 0.5)
      rubyzip (~> 1.0)
    watir (6.8.4)
      selenium-webdriver (~> 3.4, >= 3.4.1)
    yml_reader (0.7)

PLATFORMS
  ruby

DEPENDENCIES
  cucumber
  data_magic
  page-object (~> 2.0)
  rake
  rspec
  watir

我不确定为什么在安装Watir时会发生此错误。当我需要Watir并使用ruby文件运行脚本时,它可以正常工作。只要使用功能它就会发生错误。

当任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

这不是您问题的直接答案,但适用于您在运行黄瓜时尝试启动浏览器的位置。除非你想要为每个场景启动浏览器的开销,否则我建议在support / env.rb中启动浏览器然后在before hook中你可以做一些事情,比如清除cookie以获得相当于每个场景的新浏览器

否则,如果您在每个方案开始时打开浏览器,并在结束时关闭它,那么由于每个方案启动浏览器会话所需的时间,您的功能执行起来会慢得多。