Ruby on Rails フレームワークから Watir テスト コードを実行する必要があります。私の ruby on rails hello world は完璧に動作し、Watir テストも同様です (irb から実行する場合と、個別の ruby スクリプトとして実行する場合)。 Watir エラーを読み込めません。
この要件は非常に緊急であり、エラーの内容がわかりません。
注: Rails アプリケーションは netbeans 6.9 IDE で実行され、システムでネイティブの Ruby インタープリターを使用します (デフォルトの jruby ではありません)。
私は次のバージョンを持っています: ruby: 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