【发布时间】:2014-05-05 11:44:19
【问题描述】:
我正在尝试修复我的测试,以便可以使用环境变量从命令行调用它们,例如浏览器。
我在命令提示符下调用它: ruby watir1_environment.rb -BROWSER=chrome
并得到以下错误信息:
C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:49:in `process_args': invalid option: -BROWSER=chrome (OptionParser::InvalidOption)
from C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
from C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
from C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:21:in `run'
from C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
from C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
from C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'
这是代码:
require "rubygems"
require "test/unit"
require "watir-webdriver"
class TestingEnvironments < Test::Unit::TestCase
def setup
case ENV['BROWSER']
when 'ff', 'Firefox'
@b = Selenium::WebDriver.for :firefox
browser_name = 'Firefox'
when 'chrome'
@b = Selenium::WebDriver.for :chrome
browser_name = 'Chrome'
when 'debug'
debug_profile = Selenium::WebDriver::Firefox::Profile.new
debug_profile.add_extension "firebug-1.9.1-fx.xpi"
@b = Selenium::WebDriver.for :firefox, :profile => debug_profile
browser_name = 'Firefox (Firebug)'
when 'mobile'
mobile_profile = Selenium::WebDriver::Firefox::Profile.new
mobile_profile['general.useragent.override'] = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
AppleWebKit/420+ (KHTML, like Gecko) Version/3.0
Mobile/1A535b Safari/419.3"
@b = Selenium::WebDriver.for :firefox, :profile => mobile_profile
browser_name = 'Mobile'
when 'headless'
headless_profile = Headless.new
headless_profile.start
@b = Selenium::WebDriver.for :firefox
browser_name = 'Firefox'
else
@b = Selenium::WebDriver.for :firefox
browser_name = 'Firefox'
end
end
def test
{Test Code}
end
有什么想法吗?
【问题讨论】: