NoMethodError: private method `browser_name' called for {:browserName=>:firefox, :version=>nil}:Hash

NoMethodError: private method `browser_name' called for {:browserName=>:firefox, :version=>nil}:Hash

我正在尝试学习 selenium Grid,我遵循了一个教程,但是当我尝试 运行 我的功能时,我遇到了这个错误:

NoMethodError: 私有方法“browser_name”调用 {:browserName=>:firefox, :version=>nil}:Hash

这是 env.rb 文件:

   require 'watir-webdriver'
require 'cucumber'

def browser_path
  (ENV['BPATH'])
end

def browser_name
  (ENV['BROWSER'] ||= 'firefox').downcase.to_sym
end

def environment
  (ENV['ENV'] ||= 'grid').downcase.to_sym
end

def browser_version
  (ENV['VER'])
end

Before do
  def assert_it message, &block
    begin
      if (block.call)
        puts "Assertion PASSED for #{message}"

      else
        puts "Assertion FAILED for #{message}"
        fail('Test Failure on assertion')
      end
    rescue => e
      puts "Assertion FAILED for #{message} with exception '#{e}'"
      fail('Test Failure on assertion')
    end
  end
  if browser_path != nil
    Selenium::WebDriver::Firefox.path= "#{browser_path}"
  end
  if environment == :grid
    @browser = Watir::Browser.new(:remote, :url=>"http://10.196.60.38:4444/wd/hub", :desired_capabilities=> {browserName: browser_name,version: browser_version})
    @browser.window.maximize
  else
    @browser = Watir::Browser.new browser_name
    @browser.window.maximize
  end

end

After do
  @browser.close
end

谢谢,感谢您的帮助。

watir-webdriver 已弃用,不适用于最新版本的 Firefox。请更新到最新版本 watir.

还有最新版本的 watir,你应该可以做到:

Watir::Browser.new(browser_name, url: "http://10.196.60.38:4444/wd/hub", version: browser_version