Google にアクセスする単純な watir (web-driver) スクリプトがあります。しかし、オプション パーサーを使用して cmd に引数を設定し、ブラウザーを選択したいと考えています。以下は私のスクリプトです:
require 'optparse'
require 'commandline/optionparser'
include CommandLine
require 'watir-webdriver'
describe 'Test google website' do
before :all do
options = {}
opts = OptionParser.new do |opts|
opts.on("--browser N",
"Browser to execute test scripts") do |n|
options[:browser] = n
$b = n.to_s
end
end
opts.parse! ARGV
p options
end
describe 'The test website should be displayed' do
it 'should go to google' do
$ie = Watir::Browser.new($b)
#go to test website
$ie.goto("www.google.com")
end
end
end
rspec ietest.rb --browser firefox -f doc を実行すると、無効なオプションが表示されます.ietestはファイルの名前です。スクリプト コードを変更せずに、Web ドライバーを介してブラウザーを設定するその他の直感的な方法を歓迎します。