【发布时间】:2012-07-10 19:30:04
【问题描述】:
我正在使用 watir-webdriver 运行自动化测试。 我无法通过测试单元传递命令行参数 ARGV,我得到一个 ArgumentError。
require 'rubygems'
require 'watir-webdriver'
require 'test/unit'
ARGV.each do |arg|
if arg.downcase.include? 'chrome'
$browser = 'chrome'
elsif arg.downcase.include? 'firefox'
$browser = 'firefox'
elsif arg.downcase.include? 'ff'
$browser = 'firefox'
elsif arg.downcase.include? 'ie'
$browser = 'ie'
end
end
class TEST_SITE < Test::Unit::TestCase
def setup
if $browser == 'chrome'
$b = Watir::Browser.new :chrome
elsif $browser == 'firefox'
$b = Watir::Browser.new :ff
elsif $browser == 'ie'
$b = Watir::Browser.new :ie
end
end
end
是否有其他选项或以某种方式覆盖测试单元类?
【问题讨论】:
-
您的代码对我有用。我使用'ruby filename.rb ff'等来调用它。
-
我通过命令行'ruby filename.rb chrome'调用它。 @JustinKo,您是否也包含了所需的文件?
-
我将您上面的确切代码复制到一个文件中,然后从命令提示符运行它。您可以添加您看到的完整异常吗?
-
我收到以下错误:C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: ff (ArgumentError )
-
啊。抱歉,我使用的是 Ruby 1.8.7,它没有这个问题。当我使用 Ruby 1.9.3 时,我现在看到了您的问题。
标签: ruby watir-webdriver testunit