我见过很多在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正在检查所有接口是否都是免费的(文件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
如果检查失败,则重试,如果引发异常,则停止检查。在我的计算机上,我的一个接口出现问题,并引发了套接字错误。但在这种情况下,不会引发任何错误,只会引发"不自由"标志。所以检查永远不会停止。
我已更正
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
当有套接字错误时,我引发错误。我不知道为什么硒不这样做。我会把它发布在硒虫跟踪器上。
感谢您的帮助。
埃里克