2014-01-06 28 views
0

我需要讓我的webdriver測試命中多個服務器。我的解決方案是在一個命令行參數來傳遞,但是當運行下面使用optparse在ruby測試中爲webdriver設置目標服務器

紅寶石的webdriver/E2E/*。RB -s =本地主機

紅寶石的webdriver代碼/e2e/*.rb --server = localhost

但我得到以下錯誤。我收到以下錯誤

C:/Ruby193/lib/ruby/1.9.1/test/unit.rb:49:in `process_args': invalid argument: -s=localhost (OptionParser::InvalidArgument) 
    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' 

test.rb

require 'test/unit' 
require 'optparse' 

class SuperTestClass < Test::Unit::TestCase 
    def setup 
     @server = "https://localhost/" 
     optparse = OptionParser.new do|opts|    
      opts.on('-s', '--server server', 'Server to run tests against') do|server| 
       @server = server 
      end 
     end 

     ... 
    end 
    ... 
end 

UPDATE

我改變

opts.on('-s', '--server server', 'Server to run tests against') do|server| 

opts.on('-serv', '--server server', 'Server to run tests against') do|server| 

,但它並沒有解決它

回答

0

我不認爲測試可以帶參數。我最終使用rake來設置env參數。

task :selenium,[:env,:type] do |t, args| 
    args.with_defaults :env => 'local',:type => 'all' 

    case args.env 
     when 'local' 
      ENV['URL'] = 'localhost' 
      ... 
    end 

    puts 
    puts '****Running '+args.type+' tests on: '+ ENV['URL'] 
    puts 

    Rake::Task[args.type].execute 
end 
0

可惜我不能找到文檔,所以我不能證明我的說法,但我認爲短期-s選項已被預約別的東西。

嘗試將短參數更改爲其他值,然後重試。