WebDriver创建被阻止

时间:2014-01-09 17:20:59

标签: ruby selenium

我见过很多在Selenium和Ruby中进行测试的例子。 这里是我正在尝试的代码:

  require 'selenium-webdriver'

  browser = Selenium::WebDriver.for :firefox
  browser.get "http://google.com"

  ...

但程序在此行被阻止:browser = Selenium::WebDriver.for :firefox

我用netbeans和irb =>启动它同样的问题。

通过调试,我看到我在这里被阻止了:

  # firefox.rb
  unless defined? SocketError
    class SocketError < IOError; end
  end

但我不明白为什么。

我已经安装了gem安装的selenium驱动程序。 还有其他事情要做? 有谁知道该程序被阻止的原因?

1 个答案:

答案 0 :(得分:0)

我找到了问题!

使用调试模式,我看到Selenium正在检查所有接口是否都是空闲的(文件port_prober.rb):

def self.free?(port)
  Platform.interfaces.each do |host|
    begin
      TCPServer.new(host, port).close
    rescue *IGNORED_ERRORS => ex
      $stderr.puts "port prober could not bind to #{host}:#{port} (#{ex.message})" if $DEBUG
      # ignored - some machines appear unable to bind to some of their interfaces
    end
  end
  true
rescue SocketError, Errno::EADDRINUSE
  false
end

如果检查失败,则重试检查,如果引发异常,则停止检查。 在我的计算机上,我在一个界面上遇到问题,并引发了 SocketError 。但在这种情况下,不会引发错误,只会出现“非自由”标志。所以检查永远不会停止。

我做了更正

def self.free?(port)
  Platform.interfaces.each do |host|
    begin
      TCPServer.new(host, port).close
    rescue *IGNORED_ERRORS => ex
      $stderr.puts "port prober could not bind to #{host}:#{port} (#{ex.message})" if $DEBUG
      # ignored - some machines appear unable to bind to some of their interfaces
    rescue SocketError, Errno::EADDRINUSE
      $stderr.puts "port prober could not bind to #{host}:#{port} (#{ex.message})" if $DEBUG
      # ignored - some machines appear unable to bind to some of their interfaces
    end
  end
  true
end

出现socketError时出错。 我不知道为什么Selenium没有这样做。 我将它发布在Selenium bug tracker上。

感谢您的帮助。

埃里克