【发布时间】:2016-07-20 09:56:18
【问题描述】:
我需要从 Ruby on Rails 框架运行 Watir 测试代码。我的 ruby on rails hello world 运行良好,我的 Watir 测试也是如此(当我从 irb 运行并作为单独的 ruby 脚本运行时),但我的要求是从 rails 控制器中调用 watir 代码,这给出了一个无法加载 Watir 错误。
这个要求很紧急,搞不清是什么错误。
注意:rails 应用程序在 netbeans 6.9 IDE 上运行,并使用系统中的原生 ruby 解释器(不是默认的 jruby)
我有以下版本: 红宝石:1.9.3 女仆:3.0.0 导轨:3.2.8
LoadError (cannot load such file -- Watir):
app/controllers/watir_controller.rb:4:in `<class:WatirController>'
app/controllers/watir_controller.rb:1:in `<top (required)>'
这是我调用 watir 脚本的控制器类:
class WatirController < ApplicationController
## the Watir controller
require 'rubygems'
require 'watir'
# set a variable
test_site = "http://www.google.com"
# open the IE browser
ie = Watir::IE.new
# print some comments
puts "Beginning of test: Google search."
puts " Step 1: go to the test site: " + test_site
ie.goto test_site
puts " Step 2: enter 'pickaxe' in the search text field."
ie.text_field(:name, "q").set "pickaxe" # "q" is the name of the search field
#puts " Step 3: click the 'Google Search' button."
ie.button(:name, "btnG").click # "btnG" is the name of the Search button
puts " Expected Result:"
puts " A Google page with results should be shown. 'Programming Ruby' should be high on the list."
puts " Actual Result:"
if ie.text.include? "Programming Ruby"
puts " Test Passed. Found the test string: 'Programming Ruby'. Actual Results match Expected Results."
else
puts " Test Failed! Could not find: 'Programming Ruby'."
end
puts "End of test: Google search."
end
【问题讨论】:
-
而导致错误的代码是...?
-
另外,您使用的是 RVM 吗? Watir 在您的宝石清单中吗? Rails 是否有某种 env.rb(我对 Rails 不太熟悉)?
-
我没有使用 RVM,它是一个 ruby on rails 应用程序。是的,Watir 在宝石清单上。
-
找到了解决方案..必须在 Gemfile 中包含“watir”gem,这似乎是 rails 3 的要求。
标签: ruby-on-rails watir watir-webdriver