【问题标题】:Error message when calling watir-webdriver test with Arguments使用参数调用 watir-webdriver 测试时出现错误消息
【发布时间】: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

有什么想法吗?

【问题讨论】:

    标签: watir-webdriver testunit


    【解决方案1】:

    您可以使用set 命令从命令行设置 Windows ENV 变量。

    C:\> SET BROWSER=chrome
    C:\> ruby watir1_environment.rb
    

    您可以在http://ss64.com/nt/set.html 找到有关set 的更多信息。

    或者,您可以访问ARGV 变量,而不是使用ENV['BROWSER'],它是在命令行中传递的参数数组。只需将您的案例陈述更改为:

    case ARGV[0]
    

    这仅需要关键字,而不需要 -BROWSER=

    C:\> ruby watir1_environment.rb chrome
    

    【讨论】:

      【解决方案2】:

      我在没有破折号的情况下传递变量,它工作正常。

      ruby watir1_environment.rb BROWSER=chrome
      

      我还将Fig_Newton gem 用于我经常使用的变量。

      【讨论】:

        猜你喜欢
        • 2012-12-31
        • 2012-07-22
        • 1970-01-01
        • 1970-01-01
        • 2011-07-21
        • 1970-01-01
        • 1970-01-01
        • 2013-06-26
        • 1970-01-01
        相关资源
        最近更新 更多