0

我需要让我的 webdriver 测试命中多个服务器。我的解决方案是传入命令行参数,但是在运行下面的代码时使用

ruby webdriver/e2e/*.rb -s=localhost

或者

ruby 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'

测试.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

更新

我变了

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

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

但它没有解决它

4

2 回答 2

0

不幸的是,我找不到文档,所以我无法证明我的理论,但我认为空头-s选项已经保留给其他东西。

尝试将简短参数更改为其他内容,然后重试。

于 2014-01-06T16:42:20.030 回答
0

我不认为测试可以接受参数。我最终使用 rake 来设置环境参数。

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
于 2014-01-24T17:15:13.387 回答