1

スクリプトに渡された引数に基づいてブラウザーの URL を開こうとしています。したがって、次のルビーコードを書きました。

require 'selenium-webdriver'
require 'test/unit'

class TestTitle < Test::Unit::TestCase
  def setup
    $driver = Selenium::WebDriver.for :firefox
    if ARGV[0] == 'google'
      $driver.get 'http://www.google.com'
    elsif ARGV[0] == 'twitter'
      $driver.get 'http://www.twitter.com'
    end
  end

  def test_title
    puts $driver.title
  end

  def teardown
    $driver.quit
  end
end

引数: を渡すとruby test.rb 'google'、次のエラーが発生します。

c:/Ruby193/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: google (ArgumentError)
        from c:/Ruby193/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
        from c:/Ruby193/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
        from c:/Ruby193/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
        from c:/Ruby193/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
        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'

私が間違っていることを理解するのを手伝ってください。

4

1 に答える 1

3

test-unit (1.9.1 以降) は、その GlobOptions モジュールでコマンド ライン オプションを取得しているようです。ARGV[0] を使用してブラウザー名を渡していますが、ファイル名を渡していると見なされます。回避策として、ARGV[0] の値を取得し、テスト ケースを実行する前にクリアします。

browser = ARGV[0]

ARGV[0] = nil

于 2013-12-10T03:16:52.033 に答える