我有一个简单的 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 驱动程序设置浏览器的直观方法,而无需更改脚本代码。