我有要求从Ruby on Rails框架运行Watir测试代码。我的红宝石在rails hello world上效果很好,我的Watir测试也是如此(当我从irb运行并以独立的ruby脚本运行时),但我的要求是从rails控制器中调用watir代码,不能加载Watir错误。从Ruby on Rails控制器Watir
这个要求是非常紧急的,我无法弄清楚错误是什么。
注:Rails应用程序是在NetBeans IDE 6.9运行和使用本机Ruby解释器系统(而不是默认的JRuby)
我有以下版本: 红宝石:1.9.3 的Watir: 3.0.0 的Rails: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在你的宝石名单中?是否有某种env.rb for rails(我不熟悉Rails)? –
我没有使用RVM,它是一款Ruby应用程序。是的,Watir在宝石名单上。 – jasdmystery