(Watir-)Webdriver 在带有 Firefox 10 的 Fedora 14 上找不到稳定的 Firefox 连接
我试图让 watir 在rackspace linux 盒子(fedora 14)上运行,但是当我尝试启动 watir 时出现此错误,
Selenium::WebDriver::Error::WebDriverError: unable to obtain stable firefox connection in 60 seconds
我从 firefox 3.6.24 开始并升级到 firefox 10.0.2。当我升级时,我收到一条警告:firefox 的 fedora 14 已停产,不再受支持。
我通过 rubygems 安装了 watir,这是我的版本。
watir-webdriver (0.5.3)
selenium-webdriver (2.19.0)
我还安装了 GNOME,认为 Firefox 和 Selenium 需要窗口系统才能正确运行。我缺少什么?我想做的就是在远程 Linux 服务器上自动执行浏览器操作。一切都可以使用 Mac OSX Lion 在本地运行。
编辑 1
好的,这变得很奇怪。当我从命令行运行以下脚本时,它可以在服务器上运行。
#! /usr/bin/env ruby
require 'watir-webdriver'
require 'headless'
@headless = Headless.new
@headless.start
browser = Watir::Browser.new :ff
browser.goto("http://www.google.com")
但是当我在rails环境中运行代码时,它根本不起作用。我确实安装了无头宝石。在我的代码中,事物被分成模块,但我验证了以下代码表现出完全相同的行为。
在routes.rb中我有一个资源
resources :stories
然后在stories_controller中我有这个代码
def create
@headless = Headless.new
@headless.start
browser = Watir::Browser.new :ff
browser.goto("http://google.com")
count = browser.as.count
respond_to do |format|
format.json {render :json => {:count => count}.to_json}
end
end
我向server_ip/stories发送一个post请求并得到一个错误响应。在 Production.log 中,我发现以下错误:
Selenium::WebDriver::Error::WebDriverError (unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)):
我在 Apache/2.2.17 (Unix) 上使用 Rails 3.0.3,并通过 Passenger (3.0.11) gem 安装了 Phusion Passenger。
当我从命令行运行脚本(有效)时,我观察到 Xvfb 已启动,并且两个 Firefox 进程已启动,其中一个进程立即失效。第二个进程继续运行,我认为它正在正确执行脚本。
当我观察从 Rails 环境运行的相同代码时,我看到相同的事件链,但出现了未失效的 Firefox 进程,然后立即停止执行。然后我看到一系列 PhusionHelper 进程启动。
知道为什么真正的 Firefox 进程在通过 apache 运行时会在 Rails 中停止 --> phusion--> Rails 但不在 ruby 解释器内?我什至验证了以下工作
rails console
h = Headless.new
h.start
b = Watir::Browser.new :ff
所以我不相信这只是一个 Rails 环境问题。
编辑2
尝试了完全相同的代码,但在chrome中使用ChromeDriver和watir-webdriver,我得到了与以前完全相同的结果,除了在rails内我收到此错误:
Selenium::WebDriver::Error::UnknownError (Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: /opt/google/chrome/google-chrome):
编辑3
我将问题缩小到Phusion Passenger。据我了解,webdriver 通过流套接字上的服务器/客户端架构连接到浏览器。连接发生在 selenium_webdriver 中的 socket_poller.rb 中:
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])
begin
sock.connect_nonblock sockaddr
...... 并且在这里得到拯救
rescue *NOT_CONNECTED_ERRORS
sock.close if sock
$stderr.puts [@host, @port].inspect if $DEBUG
false
end
结果 phusion_passenger 不允许您在套接字上查找或倒回,并提供了一个不响应这些方法的包装器。您可以在这里阅读更多内容 http://rubydoc.info/github/FooBarWidget/ Passenger/master/PhusionPassenger/Utils/UnseekableSocket 我不确定这是否是确切的问题,但我认为它一定与此有关。
这就解释了为什么在 Phusion Passenger 框架内运行此服务会失败,但在其他地方却可以运行。我能够通过在 Passenger/Rails 框架之外创建一个简单的服务器并从那里执行脚本来解决这个问题。
我欢迎更多关于其确切原因的见解。
I'm trying to get watir running on a rackspace linux box (fedora 14) but when I try to launch watir I get this error
Selenium::WebDriver::Error::WebDriverError: unable to obtain stable firefox connection in 60 seconds
I started with firefox 3.6.24 and upgraded to firefox 10.0.2. When I upgraded I got a warning that fedora 14 is EOL for firefox and no longer supported.
I installed watir via rubygems and here are my versions.
watir-webdriver (0.5.3)
selenium-webdriver (2.19.0)
I also installed GNOME thinking that firefox and selenium need a windowing system to operate correctly. What am I missing? All I'm trying to do is automate browser actions on a remote linux server. Everything's working locally using Mac OSX Lion.
EDIT 1
Ok so this is getting pretty strange. The following script works on the server when I run it from the command line.
#! /usr/bin/env ruby
require 'watir-webdriver'
require 'headless'
@headless = Headless.new
@headless.start
browser = Watir::Browser.new :ff
browser.goto("http://www.google.com")
But when I run the code in the rails environment it doesn't work at all. I do have the headless gem installed. Things are separated into modules in my code, but I verified that the following code exhibits the exact same behavior.
In routes.rb I have a resource
resources :stories
Then in the stories_controller I have this code
def create
@headless = Headless.new
@headless.start
browser = Watir::Browser.new :ff
browser.goto("http://google.com")
count = browser.as.count
respond_to do |format|
format.json {render :json => {:count => count}.to_json}
end
end
I send a post request to server_ip/stories and get an error response. In production.log I find the following error
Selenium::WebDriver::Error::WebDriverError (unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)):
I'm using Rails 3.0.3 on Apache/2.2.17 (Unix) connected with Phusion Passenger installed through the Passenger (3.0.11) gem.
When I run just the script (which works) from the command line, I observe that Xvfb is launched and two firefox processes are started, one of which immediately becomes defunct. The second process keeps running, which I assume is correctly executing the script.
When I observe the same code running from the rails environment, I see the same chain of events but the firefox process that's not defunct appears and then immediately stops execution. Then I see a chain of PhusionHelper processes start.
Any idea why the real firefox process would stop in rails when running through apache --> phusion --> rails but not within the ruby interpreter? I even verified the following works
rails console
h = Headless.new
h.start
b = Watir::Browser.new :ff
So I'm not convinced it's simply a rails environment problem.
EDIT 2
Tried the exact same code but in chrome using the ChromeDriver and watir-webdriver and I get the exact same results as before except within rails I get this error:
Selenium::WebDriver::Error::UnknownError (Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: /opt/google/chrome/google-chrome):
EDIT 3
I narrowed the problem down to Phusion Passenger. From what I understand, webdriver connects to browsers through a server/client architecture over a stream socket. The connection happens in socket_poller.rb in selenium_webdriver here:
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])
begin
sock.connect_nonblock sockaddr
...... AND get's rescued here
rescue *NOT_CONNECTED_ERRORS
sock.close if sock
$stderr.puts [@host, @port].inspect if $DEBUG
false
end
Turns out phusion_passenger does not allow you to seek or rewind on sockets and provides a wrapper that does not respond to those methods. You can read more here http://rubydoc.info/github/FooBarWidget/passenger/master/PhusionPassenger/Utils/UnseekableSocket I'm not sure if this is the exact problem, but I think it must be related to this.
So that explains why running this service inside the Phusion Passenger framework fails, but works elsewhere. I was able to solve this issue by creating a simple server outside the Passenger/Rails framework and executing the script from there.
I welcome any more insights into the exact cause of this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,当 Firefox 无法启动时会出现此错误。这主要是因为您的机架空间盒是无头的,而 Firefox 需要可用的显示器才能运行。安装 Xvfb 并再次尝试使用
headless
gem - http://rubygems.org/gems/无头Generally, this error occurs when Firefox can't start. It's mostly because your rackspace box is headless, while Firefox requires available display to run. Install Xvfb and try once again using
headless
gem - http://rubygems.org/gems/headless我遇到了一个非常类似的问题。
就我而言,我有一个简单的环境,没有 Phusion。
即使我安装了图形界面,我也使用无头模式。
该脚本以 root 身份正常运行,但以其他用户身份运行时崩溃。
我通过手动运行 Firefox 一次(作为请求的用户)并删除每次更新检查来解决这个问题。
华泰
I run into a very similar issue.
In my case, I have a simple environment, without Phusion.
I'm using headless mode, even if I have graphics interface installed.
The script was running properly as root, an it was crashing when running as a different user.
I solved it by running manually Firefox once (as the requested user) and removing a every check for updates.
HTH