Net :: ReadTimeout:Net :: ReadTimeout和Selenium :: WebDriver :: Error :: UnknownError:未知错误:Chrome无法在Rails 5.1.beta系统测试中启动 [英] Net::ReadTimeout: Net::ReadTimeout and Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start on Rails 5.1.beta System Test
问题描述
对于将水豚烘焙到新版本的Rails(5.1)中非常热情,请参阅 http://weblog.rubyonrails.org/2017/2/23/Rails-5-1-beta1/
Enthusiastic about the baking of Capybara into the new version of Rails (5.1) cf http://weblog.rubyonrails.org/2017/2/23/Rails-5-1-beta1/
但是我遇到了一个问题.这是我的步骤.任何线索欢迎.
I have run into a problem though. Here are my steps. Any clue welcome.
全新安装:
- Linux Ubuntu Desktop 16.10(Hyper-V上的VM),已安装Chrome并运行良好;
- Ruby 2.4;
- Rails 5.1.beta.
1.-创建一个简单的应用程序:
1.- Create a simple app:
~$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
~$ rails -v
Rails 5.1.0.beta1
~$ mkdir railsapps
~$ cd railsapps
~/railsapps$ rails new smoketestapp
~/railsapps$ cd smoketestapp
~/railsapps/smoketestapp$ rails generate scaffold post title:string body:text
~/railsapps/smoketestapp$ rails db:migrate
2.-运行测试
~/railsapps/smoketestapp$ cat test/system/posts_test.rb
require "application_system_test_case"
class PostsTest < ApplicationSystemTestCase
test "visiting the index" do
visit posts_url
assert_selector "h1", text: "Post"
end
end
~/railsapps/smoketestapp$ rake test TEST=test/system/posts_test.rb
Run options: --seed 55778
# Running:
...
Error:
PostsTest#test_visiting_the_index:
Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.
...
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
~/railsapps/smoketestapp$
3.-好的,让我们按照错误消息(安装chromedriver
)中的建议进行操作:
3.- OK, let's proceed as suggested in the error messsage (install chromedriver
) :
~/railsapps/smoketestapp$ ls /usr/bin/google-chrome
lrwxrwxrwx 1 root root 31 Mar 18 15:31 /usr/bin/google-chrome -> /etc/alternatives/google-chrome*
~/railsapps/smoketestapp$ echo $PATH
...:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:...
~/railsapps/smoketestapp$ wget https://chromedriver.storage.googleapis.com/2.28/chromedriver_linux64.zip
~/railsapps/smoketestapp$ unzip chromedriver_linux64.zip
~/railsapps/smoketestapp$ sudo cp chromedriver /usr/local/bin
~/railsapps/smoketestapp$ ls /usr/local/bin
total 7504
drwxr-xr-x 2 root root 4096 Mar 19 19:05 ./
drwxr-xr-x 10 root root 4096 Okt 12 22:42 ../
-rwxr-xr-x 1 root root 7673176 Mar 19 19:05 chromedriver*
~/railsapps/smoketestapp$
4.- OK.重试测试...
4.- OK. Retry test ...
~/railsapps/smoketestapp$ rake test TEST=test/system/posts_test.rb
Run options: --seed 51574
# Running:
...
Error:
PostsTest#test_visiting_the_index:
Net::ReadTimeout: Net::ReadTimeout test/system/posts _test.rb:5:in `block in '
...
bin/rails test test/system/posts_test.rb:4
...
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
~/railsapps/smoketestapp$
不好!
在应用程序目录中运行rails -v
时,给出了'Net :: ReadTimeout:Net :: ReadTimeout'错误消息的根本原因,给出了 Selenium :: WebDriver :: Error :: UnknownError:未知错误:Chrome无法启动:
A clue on the root cause of 'Net::ReadTimeout: Net::ReadTimeout' error message is given when running rails -v
in the app dir, giving Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start:
~/railsapps/smoketestapp$ rails -v
Run options: --seed 39896
# Running:
.......E
Error:
PostsTest#test_visiting_the_index:
Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.28.455506 (18f6627e265f442aeec9b6661a49fe819aeeea1f),platform=Linux 4.8.0-41-generic x86_64)
test/system/posts_test.rb:5:in `block in <class:PostsTest>'
Error:
PostsTest#test_visiting_the_index:
Net::ReadTimeout: Net::ReadTimeout
bin/rails test test/system/posts_test.rb:4
...
~/railsapps/smoketestapp$
这是直接从Ruby调用Selenium WebDriver时得到的:
This is what I get when invoking the Selenium WebDriver directly from Ruby:
~/railsapps/smoketestapp$ irb
2.4.0 :001 > require "selenium-webdriver"
=> true
2.4.0 :002 > driver = Selenium::WebDriver.for(:chrome)
Net::ReadTimeout: Net::ReadTimeout
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/protocol.rb:176:in `rbuf_fill'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/protocol.rb:154:in `readuntil'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/protocol.rb:164:in `readline'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http/response.rb:40:in `read_status_line'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http/response.rb:29:in `read_new'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1446:in `block in transport_request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `catch'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `transport_request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1416:in `request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1409:in `block in request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:877:in `start'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1407:in `request'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:124:in `response_for'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:78:in `request'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:669:in `raw_execute'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:108:in `create_session'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:71:in `initialize'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/chrome/bridge.rb:52:in `initialize'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:61:in `new'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:61:in `for'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver.rb:87:in `for'
from (irb):2
from ~/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'
2.4.0 :003 > exit
~/railsapps/smoketestapp$
任何帮助表示感谢,谢谢
Any help appreciated, thank-you
外翻
更新:
发现问题,查看Selenium驱动程序的日志文件.为此,我在IRB中输入了以下内容:
Found the problem, looking into the log file for Selenium driver. To do that, I typed the following in IRB:
require "selenium-webdriver"
Selenium::WebDriver::Chrome.driver_path="/usr/local/bin/chromedriver"
Selenium::WebDriver.for :chrome, :service_log_path => "/tmp/cd.log"
driver = Selenium::WebDriver.for(:chrome)
在日志文件中钉上钉子:chrome无法启动:
Tailing the log file nailed it: chrome would not start:
~/railsapps/smoketestapp$ tail /tmp/cd.log
...
[0.247][INFO]: Launching chrome: /opt/google/chrome/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-hang-monitor --disable-prompt-on-repost --disable-web-resources --enable-logging --full-memory-crash-report --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.Pdre6o/internal --logging-level=1 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12264 --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.mHJaEd data:,
[0.250][WARNING]: PAC support disabled because there is no system implementation
[20.281][INFO]: RESPONSE InitSession unknown error: Chrome failed to start: exited abnormally
~/railsapps/smoketestapp$
最后,我发现通过PuTTY远程调用chrome是行不通的(这就是我一直在做的事情),尽管直接在VM(在终端服务器中)进行了操作.
在腻子上:
~$ google-chrome
[3938:3938:0320/213941.129923:ERROR:browser_main_loop.cc(279)] Gtk: cannot open display:
直接在其运行的VM上运行.
Whereas, directly on the VM it worked.
不幸的是,当我遇到另一个错误时,我的幸福是短暂的,但这是另一个故事:
Unfortunately, my happiness was short-lived, as I ran into yet another error, but that's another story:
irb(main):001:0> require "selenium-webdriver"
=> true
irb(main):002:0> Selenium::WebDriver::Chrome.driver_path="/usr/local/bin/chromedriver"
=> "/usr/local/bin/chromedriver"
irb(main):003:0> driver = Selenium::WebDriver.for(:chrome)
=> #<Selenium::WebDriver::Driver:0x59d7c889a916c6b8 browser=:chrome>
irb(main):004:0> driver.navigate.to("http://www.google.com")
Selenium::WebDriver::Error::UnknownError: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"10797.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=57.0.2987.110)
(Driver info: chromedriver=2.4.226074,platform=Linux 4.8.0-41-generic x86_64)
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:107:in `request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:669:in `raw_execute'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:647:in `execute'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:120:in `get'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/navigation.rb:32:in `to'
from (irb):4
from ~/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'
irb(main):005:0> exit
推荐答案
最终,我想用Capybara运行系统测试,这些测试将在我的设置中起作用(开发机器= VM,OS = Linux Ubuntu,可通过PuTTY远程访问).
Ultimately, I wanted to run system tests with Capybara that would work in my settings (development machine = VM with OS = Linux Ubuntu, accessed remotely through PuTTY).
我找到了使之工作的方法.
I found a way to make it work.
为此,我放弃了PhantomJS和poltergeist的Chrome及其Selenium驱动程序.
For that, I ditched Chrome and its Selenium driver, for PhantomJS and poltergeist.
PhantomJS是一款无头浏览器(=无GUI).效果很好.这是我的步骤(Rails 5.1):
PhantomJS is a headless browser (= no GUI). It works great. Here are my steps (Rails 5.1):
-
将gem'poltergeist'添加到您的Gemfile中,并注释掉gem'selenium-webdriver'(chrome需要使用后者,我们将不再使用):
Add gem 'poltergeist' to your Gemfile, and comment out gem 'selenium-webdriver' (the later is needed by chrome, which we will not use):
#gem 'selenium-webdriver'
gem 'poltergeist'
运行bundle update
添加poltergeist驱动程序配置(在文件application_system_test_case.rb
中),注释掉chrome驱动程序配置:
Add poltergeist driver config (in file application_system_test_case.rb
), commenting out the chrome driver config:
$ cat test/application_system_test_case.rb
require "test_helper"
require "capybara/poltergeist"
Capybara.javascript_driver = :poltergeist
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
driven_by :poltergeist
end
下载"PhamtomJS"无头浏览器,并将其放置在PATH的目录中:
download the 'PhamtomJS' headless browser, and place it on a directory in your PATH:
$ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
$ tar -xjvf phantomjs-1.9.8-linux-x86_64.tar.bz2
$ sudo cp phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/local/bin
$ sudo chmod +x /usr/local/bin/phantomjs
您已经准备就绪,可以进行系统测试了.例如:
You are all set, and ready to run a system test. For example:
$ rake test TEST=test/system/posts_test.rb
Run options: --seed 38196
# Running:
Puma starting in single mode...
* Version 3.8.2 (ruby 2.4.0-p0), codename: Sassy Salamander
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:44265
Use Ctrl-C to stop
You're running an old version of PhantomJS, update to >= 2.1.1 for a better experience.
.
Finished in 1.366478s, 0.7318 runs/s, 0.7318 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
$
这篇关于Net :: ReadTimeout:Net :: ReadTimeout和Selenium :: WebDriver :: Error :: UnknownError:未知错误:Chrome无法在Rails 5.1.beta系统测试中启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!