Capybara/Poltergeist 无法连接到服务器(连接被拒绝 + GET '/identify')
Capybara/Poltergeist failed to reach server (Connection refused + GET '/identify')
更新
test.log
显示服务器正在响应我们的测试并呈现页面。
- 闹鬼失败
Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1:50712/computers' failed to reach server, check DNS and/or server status - Timed out with no open resource requests
。
Poltergeist 无法连接到服务器。
我尝试了许多变体,包括:
- 更长的超时时间(最多 300 秒)。
- 正在将 Capybara.app_host 设置为 www.example.com、localhost 或 127.0.0.1。
- 删除 phantomjs_options.
- 正在从
static_controller.rb
中删除 force_ssl if: :ssl_configured?
。
- 渲染
users/sign_in
没有布局以消除外部 javascript。
- 将测试更改为调用
new_user_session_path
、new_user_session_url
和 /users/sign_in
。
- 运行
RAILS_ENV=test rake assets:precompile
在 运行 测试之前(手动)。
当我运行rails s -e test
时,我可以打开URL127.0.0.1:3000/users/sign_in
.
这是我遇到的错误:
✗ RAILS_ENV="test" ruby -I test test/integration/computers_test.rb -n /polt/
Started with run options -n /polt/ --seed 10197
http://www.example.com/
*** Capybara current_driver: poltergeist=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
{"id":"2706e68d-1997-4272-8a5c-ce4f0e1c8416","name":"set_js_errors","args":[false]}
2017-05-12T15:28:10 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2017-05-12T15:28:11 [DEBUG] Set "http" proxy to: "" : 1080
2017-05-12T15:28:11 [DEBUG] Phantom - execute: Configuration
2017-05-12T15:28:11 [DEBUG] 0 objectName : ""
2017-05-12T15:28:11 [DEBUG] 1 cookiesFile : ""
2017-05-12T15:28:11 [DEBUG] 2 diskCacheEnabled : "false"
2017-05-12T15:28:11 [DEBUG] 3 maxDiskCacheSize : "-1"
2017-05-12T15:28:11 [DEBUG] 4 diskCachePath : ""
2017-05-12T15:28:11 [DEBUG] 5 ignoreSslErrors : "true"
2017-05-12T15:28:11 [DEBUG] 6 localUrlAccessEnabled : "true"
2017-05-12T15:28:11 [DEBUG] 7 localToRemoteUrlAccessEnabled : "false"
2017-05-12T15:28:11 [DEBUG] 8 outputEncoding : "UTF-8"
2017-05-12T15:28:11 [DEBUG] 9 proxyType : "http"
2017-05-12T15:28:11 [DEBUG] 10 proxy : ":1080"
2017-05-12T15:28:11 [DEBUG] 11 proxyAuth : ":"
2017-05-12T15:28:11 [DEBUG] 12 scriptEncoding : "UTF-8"
2017-05-12T15:28:11 [DEBUG] 13 webSecurityEnabled : "true"
2017-05-12T15:28:11 [DEBUG] 14 offlineStoragePath : ""
2017-05-12T15:28:11 [DEBUG] 15 localStoragePath : ""
2017-05-12T15:28:11 [DEBUG] 16 localStorageDefaultQuota : "-1"
2017-05-12T15:28:11 [DEBUG] 17 offlineStorageDefaultQuota : "-1"
2017-05-12T15:28:11 [DEBUG] 18 printDebugMessages : "true"
2017-05-12T15:28:11 [DEBUG] 19 javascriptCanOpenWindows : "true"
2017-05-12T15:28:11 [DEBUG] 20 javascriptCanCloseWindows : "true"
2017-05-12T15:28:11 [DEBUG] 21 sslProtocol : "tlsv1"
2017-05-12T15:28:11 [DEBUG] 22 sslCiphers : "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:RC4-SHA:RC4-MD5"
2017-05-12T15:28:11 [DEBUG] 23 sslCertificatesPath : ""
2017-05-12T15:28:11 [DEBUG] 24 sslClientCertificateFile : ""
2017-05-12T15:28:11 [DEBUG] 25 sslClientKeyFile : ""
2017-05-12T15:28:11 [DEBUG] 26 sslClientKeyPassphrase : ""
2017-05-12T15:28:11 [DEBUG] 27 webdriver : ":"
2017-05-12T15:28:11 [DEBUG] 28 webdriverLogFile : ""
2017-05-12T15:28:11 [DEBUG] 29 webdriverLogLevel : "INFO"
2017-05-12T15:28:11 [DEBUG] 30 webdriverSeleniumGridHub : ""
2017-05-12T15:28:11 [DEBUG] Phantom - execute: Script & Arguments
2017-05-12T15:28:11 [DEBUG] script: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/main.js"
2017-05-12T15:28:11 [DEBUG] 0 arg: "53807"
2017-05-12T15:28:11 [DEBUG] 1 arg: "1024"
2017-05-12T15:28:11 [DEBUG] 2 arg: "768"
2017-05-12T15:28:11 [DEBUG] 3 arg: "127.0.0.1"
2017-05-12T15:28:11 [DEBUG] Phantom - execute: Starting normal mode
2017-05-12T15:28:11 [DEBUG] WebPage - setupFrame ""
2017-05-12T15:28:11 [DEBUG] FileSystem - _open: ":/modules/fs.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T15:28:11 [DEBUG] FileSystem - _open: ":/modules/system.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T15:28:11 [DEBUG] FileSystem - _open: ":/modules/webpage.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/web_page.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/node.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/connection.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/cmd.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/browser.js"
2017-05-12T15:28:11 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T15:28:11 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"2706e68d-1997-4272-8a5c-ce4f0e1c8416","response":true}
{"id":"04d6228c-1e9f-4f09-b93c-54bde8cf8396","name":"set_debug","args":[true]}
{"command_id":"04d6228c-1e9f-4f09-b93c-54bde8cf8396","response":true}
{"id":"937c83cc-33af-41d0-a6b3-3d01ec5b0d7d","name":"visit","args":["http://127.0.0.1/users/sign_in"]}
2017-05-12T15:28:11 [DEBUG] WebPage - updateLoadingProgress: 10
2017-05-12T15:28:11 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "http://127.0.0.1/users/sign_in"
2017-05-12T15:28:11 [DEBUG] WebPage - updateLoadingProgress: 100
2017-05-12T15:28:11 [DEBUG] WebPage - setupFrame ""
2017-05-12T15:28:11 [DEBUG] WebPage - setupFrame ""
2017-05-12T15:28:11 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2017-05-12T15:28:11 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
{"command_id":"937c83cc-33af-41d0-a6b3-3d01ec5b0d7d","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1/users/sign_in",null]}}
ERROR["test_basic_poltergeist_test", ComputersTest, 1.0828739999997197]
test_basic_poltergeist_test#ComputersTest (1.08s)
Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1/users/sign_in' failed to reach server, check DNS and/or server status
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:377:in `command'
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:36:in `visit'
poltergeist (1.15.0) lib/capybara/poltergeist/driver.rb:97:in `visit'
capybara (2.14.0) lib/capybara/session.rb:269:in `visit'
capybara (2.14.0) lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
test/integration/computers_test.rb:43:in `block in <class:ComputersTest>'
minitest (5.9.0) lib/minitest/test.rb:107:in `block (3 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:204:in `capture_exceptions'
minitest (5.9.0) lib/minitest/test.rb:104:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:255:in `time_it'
minitest (5.9.0) lib/minitest/test.rb:103:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest/test.rb:275:in `with_info_handler'
minitest (5.9.0) lib/minitest/test.rb:102:in `run'
minitest-reporters (1.1.14) lib/minitest/reporters.rb:48:in `run_with_hooks'
minitest (5.9.0) lib/minitest.rb:799:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:322:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:310:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest.rb:309:in `each'
minitest (5.9.0) lib/minitest.rb:309:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest.rb:335:in `with_info_handler'
minitest (5.9.0) lib/minitest.rb:308:in `run'
minitest (5.9.0) lib/minitest.rb:158:in `block in __run'
minitest (5.9.0) lib/minitest.rb:158:in `map'
minitest (5.9.0) lib/minitest.rb:158:in `__run'
minitest (5.9.0) lib/minitest.rb:135:in `run'
minitest (5.9.0) lib/minitest.rb:62:in `block in autorun'
1/1: [=========================================================================================================================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 1.08368s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
computers_test.rb
require "test_helper"
include Warden::Test::Helpers
class ComputersTest < ActionDispatch::IntegrationTest
setup do
@user = users(:one)
end
test "basic poltergeist test" do
Capybara.default_driver = Capybara.javascript_driver
visit '/users/sign_in'
puts page.html
end
end
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
class ActiveSupport::TestCase
fixtures :all
require 'minitest/reporters' # Better feedback when running tests.
Minitest::Reporters.use!
Capybara.default_driver = :rack_test
Capybara.javascript_driver = :poltergeist
include Warden::Test::Helpers # Help with logging in and out.
end
class ActionController::TestCase
include Devise::TestHelpers
end
class ActionDispatch::IntegrationTest
include Capybara::DSL
require 'capybara/poltergeist'
Capybara.register_driver(:poltergeist) do |app|
Capybara::Poltergeist::Driver.new(app, {
js_errors: false,
debug: true,
inspector: true,
timeout: 45,
stdout: true,
phantomjs_options: ['--load-images=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1', '--debug=true'],
url_whitelist: ['127.0.0.1', 'localhost', 'example.com']
})
end
end
Capybara.server_port = 3000
Capybara.app_host = Capybara.default_host = "http://127.0.0.1"
服务器在我 运行 测试时记录(此块发生两次):
[2017-05-12 16:05:49] ERROR ActionController::RoutingError: No route matches [GET] "/__identify__"
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/web-console-2.2.1/lib/web_console/middleware.rb:39:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/rack/logger.rb:38:in `call_app'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/rack/logger.rb:20:in `block in call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:68:in `tagged'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/rack/logger.rb:20:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/static.rb:120:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-cors-0.4.0/lib/rack/cors.rb:80:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/engine.rb:518:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/application.rb:165:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
/Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
之后的新日志:
- 切换到 Puma
- 为 Minitest 添加代码
- 在test_helper.rb中设置
Capybara.default_driver = :poltergeist
错误地停止运行宁rack_test。
- 正在从测试中删除
Capybara.default_driver = Capybara.javascript_driver
。
日志:
✗ RAILS_ENV="test" ruby -I test test/integration/computers_test.rb -n /polt/
Started with run options -n /polt/ --seed 62956
http://www.example.com/*** Capybara current_driver: poltergeist=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
* Min threads: 0, max threads: 4
* Environment: development
* Listening on tcp://127.0.0.1:50003
Use Ctrl-C to stop
{"id":"5d4ede2b-395f-4960-84d3-f963f8b470ac","name":"set_js_errors","args":[false]}
2017-05-12T18:03:43 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2017-05-12T18:03:44 [DEBUG] Set "http" proxy to: "" : 1080
2017-05-12T18:03:44 [DEBUG] Phantom - execute: Configuration
2017-05-12T18:03:44 [DEBUG] 0 objectName : ""
2017-05-12T18:03:44 [DEBUG] 1 cookiesFile : ""
2017-05-12T18:03:44 [DEBUG] 2 diskCacheEnabled : "false"
2017-05-12T18:03:44 [DEBUG] 3 maxDiskCacheSize : "-1"
2017-05-12T18:03:44 [DEBUG] 4 diskCachePath : ""
2017-05-12T18:03:44 [DEBUG] 5 ignoreSslErrors : "true"
2017-05-12T18:03:44 [DEBUG] 6 localUrlAccessEnabled : "true"
2017-05-12T18:03:44 [DEBUG] 7 localToRemoteUrlAccessEnabled : "false"
2017-05-12T18:03:44 [DEBUG] 8 outputEncoding : "UTF-8"
2017-05-12T18:03:44 [DEBUG] 9 proxyType : "http"
2017-05-12T18:03:44 [DEBUG] 10 proxy : ":1080"
2017-05-12T18:03:44 [DEBUG] 11 proxyAuth : ":"
2017-05-12T18:03:44 [DEBUG] 12 scriptEncoding : "UTF-8"
2017-05-12T18:03:44 [DEBUG] 13 webSecurityEnabled : "true"
2017-05-12T18:03:44 [DEBUG] 14 offlineStoragePath : ""
2017-05-12T18:03:44 [DEBUG] 15 localStoragePath : ""
2017-05-12T18:03:44 [DEBUG] 16 localStorageDefaultQuota : "-1"
2017-05-12T18:03:44 [DEBUG] 17 offlineStorageDefaultQuota : "-1"
2017-05-12T18:03:44 [DEBUG] 18 printDebugMessages : "true"
2017-05-12T18:03:44 [DEBUG] 19 javascriptCanOpenWindows : "true"
2017-05-12T18:03:44 [DEBUG] 20 javascriptCanCloseWindows : "true"
2017-05-12T18:03:44 [DEBUG] 21 sslProtocol : "tlsv1"
2017-05-12T18:03:44 [DEBUG] 22 sslCiphers : "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:RC4-SHA:RC4-MD5"
2017-05-12T18:03:44 [DEBUG] 23 sslCertificatesPath : ""
2017-05-12T18:03:44 [DEBUG] 24 sslClientCertificateFile : ""
2017-05-12T18:03:44 [DEBUG] 25 sslClientKeyFile : ""
2017-05-12T18:03:44 [DEBUG] 26 sslClientKeyPassphrase : ""
2017-05-12T18:03:44 [DEBUG] 27 webdriver : ":"
2017-05-12T18:03:44 [DEBUG] 28 webdriverLogFile : ""
2017-05-12T18:03:44 [DEBUG] 29 webdriverLogLevel : "INFO"
2017-05-12T18:03:44 [DEBUG] 30 webdriverSeleniumGridHub : ""
2017-05-12T18:03:44 [DEBUG] Phantom - execute: Script & Arguments
2017-05-12T18:03:44 [DEBUG] script: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/main.js"
2017-05-12T18:03:44 [DEBUG] 0 arg: "50007"
2017-05-12T18:03:44 [DEBUG] 1 arg: "1024"
2017-05-12T18:03:44 [DEBUG] 2 arg: "768"
2017-05-12T18:03:44 [DEBUG] 3 arg: "127.0.0.1"
2017-05-12T18:03:44 [DEBUG] Phantom - execute: Starting normal mode
2017-05-12T18:03:44 [DEBUG] WebPage - setupFrame ""
2017-05-12T18:03:44 [DEBUG] FileSystem - _open: ":/modules/fs.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T18:03:44 [DEBUG] FileSystem - _open: ":/modules/system.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T18:03:44 [DEBUG] FileSystem - _open: ":/modules/webpage.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/web_page.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/node.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/connection.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/cmd.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/browser.js"
2017-05-12T18:03:44 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T18:03:44 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"5d4ede2b-395f-4960-84d3-f963f8b470ac","response":true}
{"id":"916e1ab9-2d3e-4834-bed6-9fe1689ee267","name":"set_debug","args":[true]}
{"command_id":"916e1ab9-2d3e-4834-bed6-9fe1689ee267","response":true}
{"id":"1273bf4e-1a38-49fe-86ed-c598b7db0c46","name":"visit","args":["http://127.0.0.1:50003/computers"]}
2017-05-12T18:03:44 [DEBUG] WebPage - updateLoadingProgress: 10
{"command_id":"1273bf4e-1a38-49fe-86ed-c598b7db0c46","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1:50003/computers","Timed out with no open resource requests"]}}
{"id":"5436e5db-de6b-42cb-853c-98ef72f3e8cb","name":"reset","args":[]}
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2017-05-12T18:04:04 [DEBUG] WebPage - setupFrame ""
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "object")
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function() { var page_id = arguments[0]; var args = []; for(var i=1; i < arguments.length; i++){ if ((typeof(arguments[i]) == 'object') && (typeof(arguments[i]['ELEMENT']) == 'object')){ args.push(window.__poltergeist.get(arguments[i]['ELEMENT']['id']).element); } else { args.push(arguments[i]) } } var _result = (function (name, args) {\n return __poltergeist.externalCall(name, args);\n }).apply(this, args); return window.__poltergeist.wrapResults(_result, page_id); })(1,\"currentUrl\",[]); })()"
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript result QVariant(QVariantMap, QMap(("value", QVariant(QString, "about:blank"))))
2017-05-12T18:04:04 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T18:04:04 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T18:04:04 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(OperationCanceledError) ( "Operation canceled" ) URL: "http://127.0.0.1:50003/computers"
{"command_id":"5436e5db-de6b-42cb-853c-98ef72f3e8cb","response":true}
ERROR["test_basic_poltergeist_test", ComputersTest, 81.278547]
test_basic_poltergeist_test#ComputersTest (81.28s)
Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1:50003/computers' failed to reach server, check DNS and/or server status - Timed out with no open resource requests
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:377:in `command'
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:36:in `visit'
poltergeist (1.15.0) lib/capybara/poltergeist/driver.rb:97:in `visit'
capybara (2.14.0) lib/capybara/session.rb:269:in `visit'
capybara (2.14.0) lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
test/integration/computers_test.rb:43:in `block in <class:ComputersTest>'
minitest (5.9.0) lib/minitest/test.rb:107:in `block (3 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:204:in `capture_exceptions'
minitest (5.9.0) lib/minitest/test.rb:104:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:255:in `time_it'
minitest (5.9.0) lib/minitest/test.rb:103:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest/test.rb:275:in `with_info_handler'
minitest (5.9.0) lib/minitest/test.rb:102:in `run'
minitest-reporters (1.1.14) lib/minitest/reporters.rb:48:in `run_with_hooks'
minitest (5.9.0) lib/minitest.rb:799:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:322:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:310:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest.rb:309:in `each'
minitest (5.9.0) lib/minitest.rb:309:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest.rb:335:in `with_info_handler'
minitest (5.9.0) lib/minitest.rb:308:in `run'
minitest (5.9.0) lib/minitest.rb:158:in `block in __run'
minitest (5.9.0) lib/minitest.rb:158:in `map'
minitest (5.9.0) lib/minitest.rb:158:in `__run'
minitest (5.9.0) lib/minitest.rb:135:in `run'
minitest (5.9.0) lib/minitest.rb:62:in `block in autorun'
1/1: [=========================================================================================================================================================] 100% Time: 00:01:21, Time: 00:01:21
Finished in 81.31869s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
最新test.log
------------------------------------------
ComputersTest: test_basic_poltergeist_test
------------------------------------------
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = LIMIT 1[0m [["id", 980190962]]
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
[1m[36mUser Exists (0.4ms)[0m [1mSELECT 1 AS one FROM "users" WHERE ("users"."email" = 'jb@test.com' AND "users"."id" != 980190962) LIMIT 1[0m
[1m[35mSQL (0.2ms)[0m UPDATE "users" SET "role" = , "updated_at" = WHERE "users"."id" = [["role", "admin"], ["updated_at", "2017-05-12 22:56:37.823070"], ["id", 980190962]]
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT 1 [["id", 980190962]]
[1m[35mComputer Load (0.1ms)[0m SELECT "computers".* FROM "computers" WHERE "computers"."id" = LIMIT 1 [["id", 169251709]]
Started GET "/computers" for 127.0.0.1 at 2017-05-12 18:56:38 -0400
[1m[35m (0.1ms)[0m BEGIN
[1m[35mSQL (180058.1ms)[0m UPDATE "users" SET "last_sign_in_at" = , ... [...]
[1m[36m (0.3ms)[0m [1mROLLBACK[0m
[1m[36m (1.0ms)[0m [1mCOMMIT[0m
Processing by ComputersController#index as HTML
[1m[36mComputer Load (0.3ms)[0m [1mSELECT "computers".* FROM "computers" WHERE "computers"."company_id" = AND "computers"."company_id" = [0m [["company_id", 980190962], ["company_id", 980190962]]
[1m[35mComputer Load (0.2ms)[0m SELECT "computers".* FROM "computers" WHERE "computers"."company_id" = AND "computers"."company_id" = AND (project_id IS NULL OR project_id IN (980190962,298486374,198381282)) [["company_id", 980190962], ["company_id", 980190962]]
Rendered shared/_searchBox.html.erb (0.2ms)
Rendered computers/index.html.erb within layouts/application (7.4ms)
Rendered layouts/_google_analytics.js.erb (0.3ms)
Completed 200 OK in 99ms (Views: 49.8ms | ActiveRecord: 27.3ms)
运行测试时更新读数:
✗ RAILS_ENV="test" ruby -I test test/integration/computers_test.rb -n /polt/
Started with run options -n /polt/ --seed 20863
http://www.example.com/*** Capybara current_driver: poltergeist=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
* Min threads: 0, max threads: 4
* Environment: development
* Listening on tcp://127.0.0.1:50712
Use Ctrl-C to stop
{"id":"17f0e808-0a24-4d7a-90ce-d36fa5fd7092","name":"set_js_errors","args":[false]}
2017-05-12T18:56:38 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
...
2017-05-12T18:58:38 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(OperationCanceledError) ( "Operation canceled" ) URL: "http://127.0.0.1:50712/computers"
{"command_id":"75aada14-e9bf-4bba-b125-72de33da1fad","response":true}
{"id":"2bc940aa-359c-4148-9007-27e1553c3e86","name":"set_url_whitelist","args":["127.0.0.1","localhost","example.com"]}
{"command_id":"2bc940aa-359c-4148-9007-27e1553c3e86","response":true}
ERROR["test_basic_poltergeist_test", ComputersTest, 181.03450100000055]
test_basic_poltergeist_test#ComputersTest (181.03s)
Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1:50712/computers' failed to reach server, check DNS and/or server status - Timed out with no open resource requests
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:377:in `command'
...
1/1: [=========================================================================================================================================================] 100% Time: 00:03:01, Time: 00:03:01
Finished in 181.03610s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
它显示试图访问“http://127.0.0.1/users/sign_in”的事实告诉您某处存在配置错误,因为那里应该有一个端口号(水豚从未 运行 对其进行测试端口 80)。
首先,您设置了 Capybara.server_port = 3000
。您是否需要这样做而不是让 Capybara 分配一个随机的空闲端口?如果你确实需要修复它,3000 是一个糟糕的选择,因为这会阻止你在测试 运行.
时让你的开发实例 运行ning
其次,您设置了 Capybara.app_host
。你真的需要设置这个吗?当您要针对外部站点进行测试,或者如果您有特殊的 IP 要求时,通常会使用它。如果你真的需要设置 app_host
你可能还需要设置 Capybara.always_include_port = true
所以两个解决方案
取消设置 app_host
和 server_port
,让 Capybara 管理它们
将您的固定服务器端口更改为 3000 以外的端口并添加 Capybara.always_include_port = true
此外,您可能还想阅读 https://github.com/teamcapybara/capybara#using-capybara-with-minitest,因为在测试中设置 Capybara.default_driver = Capybara.javascript_driver
不会达到您想要的效果。
从 Rails 4.2 升级到 Rails 5.0 时,我的 issue/symptoms 与 OP 完全相同。我终于从注意到数据库时间太长中弄明白了——事务固定装置在它们应该被禁用的时候被启用了。我不确定是什么改变导致了这个默认翻转,但通过更明确地禁用事务固定装置,我能够解决这个问题。
更新
test.log
显示服务器正在响应我们的测试并呈现页面。- 闹鬼失败
Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1:50712/computers' failed to reach server, check DNS and/or server status - Timed out with no open resource requests
。
Poltergeist 无法连接到服务器。
我尝试了许多变体,包括:
- 更长的超时时间(最多 300 秒)。
- 正在将 Capybara.app_host 设置为 www.example.com、localhost 或 127.0.0.1。
- 删除 phantomjs_options.
- 正在从
static_controller.rb
中删除force_ssl if: :ssl_configured?
。 - 渲染
users/sign_in
没有布局以消除外部 javascript。 - 将测试更改为调用
new_user_session_path
、new_user_session_url
和/users/sign_in
。 - 运行
RAILS_ENV=test rake assets:precompile
在 运行 测试之前(手动)。
当我运行rails s -e test
时,我可以打开URL127.0.0.1:3000/users/sign_in
.
这是我遇到的错误:
✗ RAILS_ENV="test" ruby -I test test/integration/computers_test.rb -n /polt/
Started with run options -n /polt/ --seed 10197
http://www.example.com/
*** Capybara current_driver: poltergeist=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
{"id":"2706e68d-1997-4272-8a5c-ce4f0e1c8416","name":"set_js_errors","args":[false]}
2017-05-12T15:28:10 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2017-05-12T15:28:11 [DEBUG] Set "http" proxy to: "" : 1080
2017-05-12T15:28:11 [DEBUG] Phantom - execute: Configuration
2017-05-12T15:28:11 [DEBUG] 0 objectName : ""
2017-05-12T15:28:11 [DEBUG] 1 cookiesFile : ""
2017-05-12T15:28:11 [DEBUG] 2 diskCacheEnabled : "false"
2017-05-12T15:28:11 [DEBUG] 3 maxDiskCacheSize : "-1"
2017-05-12T15:28:11 [DEBUG] 4 diskCachePath : ""
2017-05-12T15:28:11 [DEBUG] 5 ignoreSslErrors : "true"
2017-05-12T15:28:11 [DEBUG] 6 localUrlAccessEnabled : "true"
2017-05-12T15:28:11 [DEBUG] 7 localToRemoteUrlAccessEnabled : "false"
2017-05-12T15:28:11 [DEBUG] 8 outputEncoding : "UTF-8"
2017-05-12T15:28:11 [DEBUG] 9 proxyType : "http"
2017-05-12T15:28:11 [DEBUG] 10 proxy : ":1080"
2017-05-12T15:28:11 [DEBUG] 11 proxyAuth : ":"
2017-05-12T15:28:11 [DEBUG] 12 scriptEncoding : "UTF-8"
2017-05-12T15:28:11 [DEBUG] 13 webSecurityEnabled : "true"
2017-05-12T15:28:11 [DEBUG] 14 offlineStoragePath : ""
2017-05-12T15:28:11 [DEBUG] 15 localStoragePath : ""
2017-05-12T15:28:11 [DEBUG] 16 localStorageDefaultQuota : "-1"
2017-05-12T15:28:11 [DEBUG] 17 offlineStorageDefaultQuota : "-1"
2017-05-12T15:28:11 [DEBUG] 18 printDebugMessages : "true"
2017-05-12T15:28:11 [DEBUG] 19 javascriptCanOpenWindows : "true"
2017-05-12T15:28:11 [DEBUG] 20 javascriptCanCloseWindows : "true"
2017-05-12T15:28:11 [DEBUG] 21 sslProtocol : "tlsv1"
2017-05-12T15:28:11 [DEBUG] 22 sslCiphers : "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:RC4-SHA:RC4-MD5"
2017-05-12T15:28:11 [DEBUG] 23 sslCertificatesPath : ""
2017-05-12T15:28:11 [DEBUG] 24 sslClientCertificateFile : ""
2017-05-12T15:28:11 [DEBUG] 25 sslClientKeyFile : ""
2017-05-12T15:28:11 [DEBUG] 26 sslClientKeyPassphrase : ""
2017-05-12T15:28:11 [DEBUG] 27 webdriver : ":"
2017-05-12T15:28:11 [DEBUG] 28 webdriverLogFile : ""
2017-05-12T15:28:11 [DEBUG] 29 webdriverLogLevel : "INFO"
2017-05-12T15:28:11 [DEBUG] 30 webdriverSeleniumGridHub : ""
2017-05-12T15:28:11 [DEBUG] Phantom - execute: Script & Arguments
2017-05-12T15:28:11 [DEBUG] script: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/main.js"
2017-05-12T15:28:11 [DEBUG] 0 arg: "53807"
2017-05-12T15:28:11 [DEBUG] 1 arg: "1024"
2017-05-12T15:28:11 [DEBUG] 2 arg: "768"
2017-05-12T15:28:11 [DEBUG] 3 arg: "127.0.0.1"
2017-05-12T15:28:11 [DEBUG] Phantom - execute: Starting normal mode
2017-05-12T15:28:11 [DEBUG] WebPage - setupFrame ""
2017-05-12T15:28:11 [DEBUG] FileSystem - _open: ":/modules/fs.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T15:28:11 [DEBUG] FileSystem - _open: ":/modules/system.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T15:28:11 [DEBUG] FileSystem - _open: ":/modules/webpage.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/web_page.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/node.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/connection.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/cmd.js"
2017-05-12T15:28:11 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/browser.js"
2017-05-12T15:28:11 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T15:28:11 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"2706e68d-1997-4272-8a5c-ce4f0e1c8416","response":true}
{"id":"04d6228c-1e9f-4f09-b93c-54bde8cf8396","name":"set_debug","args":[true]}
{"command_id":"04d6228c-1e9f-4f09-b93c-54bde8cf8396","response":true}
{"id":"937c83cc-33af-41d0-a6b3-3d01ec5b0d7d","name":"visit","args":["http://127.0.0.1/users/sign_in"]}
2017-05-12T15:28:11 [DEBUG] WebPage - updateLoadingProgress: 10
2017-05-12T15:28:11 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "http://127.0.0.1/users/sign_in"
2017-05-12T15:28:11 [DEBUG] WebPage - updateLoadingProgress: 100
2017-05-12T15:28:11 [DEBUG] WebPage - setupFrame ""
2017-05-12T15:28:11 [DEBUG] WebPage - setupFrame ""
2017-05-12T15:28:11 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2017-05-12T15:28:11 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
{"command_id":"937c83cc-33af-41d0-a6b3-3d01ec5b0d7d","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1/users/sign_in",null]}}
ERROR["test_basic_poltergeist_test", ComputersTest, 1.0828739999997197]
test_basic_poltergeist_test#ComputersTest (1.08s)
Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1/users/sign_in' failed to reach server, check DNS and/or server status
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:377:in `command'
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:36:in `visit'
poltergeist (1.15.0) lib/capybara/poltergeist/driver.rb:97:in `visit'
capybara (2.14.0) lib/capybara/session.rb:269:in `visit'
capybara (2.14.0) lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
test/integration/computers_test.rb:43:in `block in <class:ComputersTest>'
minitest (5.9.0) lib/minitest/test.rb:107:in `block (3 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:204:in `capture_exceptions'
minitest (5.9.0) lib/minitest/test.rb:104:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:255:in `time_it'
minitest (5.9.0) lib/minitest/test.rb:103:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest/test.rb:275:in `with_info_handler'
minitest (5.9.0) lib/minitest/test.rb:102:in `run'
minitest-reporters (1.1.14) lib/minitest/reporters.rb:48:in `run_with_hooks'
minitest (5.9.0) lib/minitest.rb:799:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:322:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:310:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest.rb:309:in `each'
minitest (5.9.0) lib/minitest.rb:309:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest.rb:335:in `with_info_handler'
minitest (5.9.0) lib/minitest.rb:308:in `run'
minitest (5.9.0) lib/minitest.rb:158:in `block in __run'
minitest (5.9.0) lib/minitest.rb:158:in `map'
minitest (5.9.0) lib/minitest.rb:158:in `__run'
minitest (5.9.0) lib/minitest.rb:135:in `run'
minitest (5.9.0) lib/minitest.rb:62:in `block in autorun'
1/1: [=========================================================================================================================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 1.08368s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
computers_test.rb
require "test_helper"
include Warden::Test::Helpers
class ComputersTest < ActionDispatch::IntegrationTest
setup do
@user = users(:one)
end
test "basic poltergeist test" do
Capybara.default_driver = Capybara.javascript_driver
visit '/users/sign_in'
puts page.html
end
end
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
class ActiveSupport::TestCase
fixtures :all
require 'minitest/reporters' # Better feedback when running tests.
Minitest::Reporters.use!
Capybara.default_driver = :rack_test
Capybara.javascript_driver = :poltergeist
include Warden::Test::Helpers # Help with logging in and out.
end
class ActionController::TestCase
include Devise::TestHelpers
end
class ActionDispatch::IntegrationTest
include Capybara::DSL
require 'capybara/poltergeist'
Capybara.register_driver(:poltergeist) do |app|
Capybara::Poltergeist::Driver.new(app, {
js_errors: false,
debug: true,
inspector: true,
timeout: 45,
stdout: true,
phantomjs_options: ['--load-images=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1', '--debug=true'],
url_whitelist: ['127.0.0.1', 'localhost', 'example.com']
})
end
end
Capybara.server_port = 3000
Capybara.app_host = Capybara.default_host = "http://127.0.0.1"
服务器在我 运行 测试时记录(此块发生两次):
[2017-05-12 16:05:49] ERROR ActionController::RoutingError: No route matches [GET] "/__identify__"
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/web-console-2.2.1/lib/web_console/middleware.rb:39:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/rack/logger.rb:38:in `call_app'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/rack/logger.rb:20:in `block in call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:68:in `tagged'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/rack/logger.rb:20:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.7/lib/action_dispatch/middleware/static.rb:120:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-cors-0.4.0/lib/rack/cors.rb:80:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/engine.rb:518:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7/lib/rails/application.rb:165:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/Users/me/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
/Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
之后的新日志:
- 切换到 Puma
- 为 Minitest 添加代码
- 在test_helper.rb中设置
Capybara.default_driver = :poltergeist
错误地停止运行宁rack_test。 - 正在从测试中删除
Capybara.default_driver = Capybara.javascript_driver
。
日志:
✗ RAILS_ENV="test" ruby -I test test/integration/computers_test.rb -n /polt/
Started with run options -n /polt/ --seed 62956
http://www.example.com/*** Capybara current_driver: poltergeist=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
* Min threads: 0, max threads: 4
* Environment: development
* Listening on tcp://127.0.0.1:50003
Use Ctrl-C to stop
{"id":"5d4ede2b-395f-4960-84d3-f963f8b470ac","name":"set_js_errors","args":[false]}
2017-05-12T18:03:43 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2017-05-12T18:03:44 [DEBUG] Set "http" proxy to: "" : 1080
2017-05-12T18:03:44 [DEBUG] Phantom - execute: Configuration
2017-05-12T18:03:44 [DEBUG] 0 objectName : ""
2017-05-12T18:03:44 [DEBUG] 1 cookiesFile : ""
2017-05-12T18:03:44 [DEBUG] 2 diskCacheEnabled : "false"
2017-05-12T18:03:44 [DEBUG] 3 maxDiskCacheSize : "-1"
2017-05-12T18:03:44 [DEBUG] 4 diskCachePath : ""
2017-05-12T18:03:44 [DEBUG] 5 ignoreSslErrors : "true"
2017-05-12T18:03:44 [DEBUG] 6 localUrlAccessEnabled : "true"
2017-05-12T18:03:44 [DEBUG] 7 localToRemoteUrlAccessEnabled : "false"
2017-05-12T18:03:44 [DEBUG] 8 outputEncoding : "UTF-8"
2017-05-12T18:03:44 [DEBUG] 9 proxyType : "http"
2017-05-12T18:03:44 [DEBUG] 10 proxy : ":1080"
2017-05-12T18:03:44 [DEBUG] 11 proxyAuth : ":"
2017-05-12T18:03:44 [DEBUG] 12 scriptEncoding : "UTF-8"
2017-05-12T18:03:44 [DEBUG] 13 webSecurityEnabled : "true"
2017-05-12T18:03:44 [DEBUG] 14 offlineStoragePath : ""
2017-05-12T18:03:44 [DEBUG] 15 localStoragePath : ""
2017-05-12T18:03:44 [DEBUG] 16 localStorageDefaultQuota : "-1"
2017-05-12T18:03:44 [DEBUG] 17 offlineStorageDefaultQuota : "-1"
2017-05-12T18:03:44 [DEBUG] 18 printDebugMessages : "true"
2017-05-12T18:03:44 [DEBUG] 19 javascriptCanOpenWindows : "true"
2017-05-12T18:03:44 [DEBUG] 20 javascriptCanCloseWindows : "true"
2017-05-12T18:03:44 [DEBUG] 21 sslProtocol : "tlsv1"
2017-05-12T18:03:44 [DEBUG] 22 sslCiphers : "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:RC4-SHA:RC4-MD5"
2017-05-12T18:03:44 [DEBUG] 23 sslCertificatesPath : ""
2017-05-12T18:03:44 [DEBUG] 24 sslClientCertificateFile : ""
2017-05-12T18:03:44 [DEBUG] 25 sslClientKeyFile : ""
2017-05-12T18:03:44 [DEBUG] 26 sslClientKeyPassphrase : ""
2017-05-12T18:03:44 [DEBUG] 27 webdriver : ":"
2017-05-12T18:03:44 [DEBUG] 28 webdriverLogFile : ""
2017-05-12T18:03:44 [DEBUG] 29 webdriverLogLevel : "INFO"
2017-05-12T18:03:44 [DEBUG] 30 webdriverSeleniumGridHub : ""
2017-05-12T18:03:44 [DEBUG] Phantom - execute: Script & Arguments
2017-05-12T18:03:44 [DEBUG] script: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/main.js"
2017-05-12T18:03:44 [DEBUG] 0 arg: "50007"
2017-05-12T18:03:44 [DEBUG] 1 arg: "1024"
2017-05-12T18:03:44 [DEBUG] 2 arg: "768"
2017-05-12T18:03:44 [DEBUG] 3 arg: "127.0.0.1"
2017-05-12T18:03:44 [DEBUG] Phantom - execute: Starting normal mode
2017-05-12T18:03:44 [DEBUG] WebPage - setupFrame ""
2017-05-12T18:03:44 [DEBUG] FileSystem - _open: ":/modules/fs.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T18:03:44 [DEBUG] FileSystem - _open: ":/modules/system.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T18:03:44 [DEBUG] FileSystem - _open: ":/modules/webpage.js" QMap(("mode", QVariant(QString, "r")))
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/web_page.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/node.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/connection.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/cmd.js"
2017-05-12T18:03:44 [DEBUG] Phantom - injectJs: "/Users/me/.rvm/gems/ruby-2.3.1/gems/poltergeist-1.15.0/lib/capybara/poltergeist/client/compiled/browser.js"
2017-05-12T18:03:44 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T18:03:44 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"5d4ede2b-395f-4960-84d3-f963f8b470ac","response":true}
{"id":"916e1ab9-2d3e-4834-bed6-9fe1689ee267","name":"set_debug","args":[true]}
{"command_id":"916e1ab9-2d3e-4834-bed6-9fe1689ee267","response":true}
{"id":"1273bf4e-1a38-49fe-86ed-c598b7db0c46","name":"visit","args":["http://127.0.0.1:50003/computers"]}
2017-05-12T18:03:44 [DEBUG] WebPage - updateLoadingProgress: 10
{"command_id":"1273bf4e-1a38-49fe-86ed-c598b7db0c46","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1:50003/computers","Timed out with no open resource requests"]}}
{"id":"5436e5db-de6b-42cb-853c-98ef72f3e8cb","name":"reset","args":[]}
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2017-05-12T18:04:04 [DEBUG] WebPage - setupFrame ""
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "object")
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function() { var page_id = arguments[0]; var args = []; for(var i=1; i < arguments.length; i++){ if ((typeof(arguments[i]) == 'object') && (typeof(arguments[i]['ELEMENT']) == 'object')){ args.push(window.__poltergeist.get(arguments[i]['ELEMENT']['id']).element); } else { args.push(arguments[i]) } } var _result = (function (name, args) {\n return __poltergeist.externalCall(name, args);\n }).apply(this, args); return window.__poltergeist.wrapResults(_result, page_id); })(1,\"currentUrl\",[]); })()"
2017-05-12T18:04:04 [DEBUG] WebPage - evaluateJavaScript result QVariant(QVariantMap, QMap(("value", QVariant(QString, "about:blank"))))
2017-05-12T18:04:04 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T18:04:04 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-05-12T18:04:04 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(OperationCanceledError) ( "Operation canceled" ) URL: "http://127.0.0.1:50003/computers"
{"command_id":"5436e5db-de6b-42cb-853c-98ef72f3e8cb","response":true}
ERROR["test_basic_poltergeist_test", ComputersTest, 81.278547]
test_basic_poltergeist_test#ComputersTest (81.28s)
Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1:50003/computers' failed to reach server, check DNS and/or server status - Timed out with no open resource requests
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:377:in `command'
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:36:in `visit'
poltergeist (1.15.0) lib/capybara/poltergeist/driver.rb:97:in `visit'
capybara (2.14.0) lib/capybara/session.rb:269:in `visit'
capybara (2.14.0) lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
test/integration/computers_test.rb:43:in `block in <class:ComputersTest>'
minitest (5.9.0) lib/minitest/test.rb:107:in `block (3 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:204:in `capture_exceptions'
minitest (5.9.0) lib/minitest/test.rb:104:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest/test.rb:255:in `time_it'
minitest (5.9.0) lib/minitest/test.rb:103:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest/test.rb:275:in `with_info_handler'
minitest (5.9.0) lib/minitest/test.rb:102:in `run'
minitest-reporters (1.1.14) lib/minitest/reporters.rb:48:in `run_with_hooks'
minitest (5.9.0) lib/minitest.rb:799:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:322:in `run_one_method'
minitest (5.9.0) lib/minitest.rb:310:in `block (2 levels) in run'
minitest (5.9.0) lib/minitest.rb:309:in `each'
minitest (5.9.0) lib/minitest.rb:309:in `block in run'
minitest (5.9.0) lib/minitest.rb:348:in `on_signal'
minitest (5.9.0) lib/minitest.rb:335:in `with_info_handler'
minitest (5.9.0) lib/minitest.rb:308:in `run'
minitest (5.9.0) lib/minitest.rb:158:in `block in __run'
minitest (5.9.0) lib/minitest.rb:158:in `map'
minitest (5.9.0) lib/minitest.rb:158:in `__run'
minitest (5.9.0) lib/minitest.rb:135:in `run'
minitest (5.9.0) lib/minitest.rb:62:in `block in autorun'
1/1: [=========================================================================================================================================================] 100% Time: 00:01:21, Time: 00:01:21
Finished in 81.31869s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
最新test.log
------------------------------------------
ComputersTest: test_basic_poltergeist_test
------------------------------------------
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = LIMIT 1[0m [["id", 980190962]]
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
[1m[36mUser Exists (0.4ms)[0m [1mSELECT 1 AS one FROM "users" WHERE ("users"."email" = 'jb@test.com' AND "users"."id" != 980190962) LIMIT 1[0m
[1m[35mSQL (0.2ms)[0m UPDATE "users" SET "role" = , "updated_at" = WHERE "users"."id" = [["role", "admin"], ["updated_at", "2017-05-12 22:56:37.823070"], ["id", 980190962]]
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT 1 [["id", 980190962]]
[1m[35mComputer Load (0.1ms)[0m SELECT "computers".* FROM "computers" WHERE "computers"."id" = LIMIT 1 [["id", 169251709]]
Started GET "/computers" for 127.0.0.1 at 2017-05-12 18:56:38 -0400
[1m[35m (0.1ms)[0m BEGIN
[1m[35mSQL (180058.1ms)[0m UPDATE "users" SET "last_sign_in_at" = , ... [...]
[1m[36m (0.3ms)[0m [1mROLLBACK[0m
[1m[36m (1.0ms)[0m [1mCOMMIT[0m
Processing by ComputersController#index as HTML
[1m[36mComputer Load (0.3ms)[0m [1mSELECT "computers".* FROM "computers" WHERE "computers"."company_id" = AND "computers"."company_id" = [0m [["company_id", 980190962], ["company_id", 980190962]]
[1m[35mComputer Load (0.2ms)[0m SELECT "computers".* FROM "computers" WHERE "computers"."company_id" = AND "computers"."company_id" = AND (project_id IS NULL OR project_id IN (980190962,298486374,198381282)) [["company_id", 980190962], ["company_id", 980190962]]
Rendered shared/_searchBox.html.erb (0.2ms)
Rendered computers/index.html.erb within layouts/application (7.4ms)
Rendered layouts/_google_analytics.js.erb (0.3ms)
Completed 200 OK in 99ms (Views: 49.8ms | ActiveRecord: 27.3ms)
运行测试时更新读数:
✗ RAILS_ENV="test" ruby -I test test/integration/computers_test.rb -n /polt/
Started with run options -n /polt/ --seed 20863
http://www.example.com/*** Capybara current_driver: poltergeist=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
* Min threads: 0, max threads: 4
* Environment: development
* Listening on tcp://127.0.0.1:50712
Use Ctrl-C to stop
{"id":"17f0e808-0a24-4d7a-90ce-d36fa5fd7092","name":"set_js_errors","args":[false]}
2017-05-12T18:56:38 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
...
2017-05-12T18:58:38 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(OperationCanceledError) ( "Operation canceled" ) URL: "http://127.0.0.1:50712/computers"
{"command_id":"75aada14-e9bf-4bba-b125-72de33da1fad","response":true}
{"id":"2bc940aa-359c-4148-9007-27e1553c3e86","name":"set_url_whitelist","args":["127.0.0.1","localhost","example.com"]}
{"command_id":"2bc940aa-359c-4148-9007-27e1553c3e86","response":true}
ERROR["test_basic_poltergeist_test", ComputersTest, 181.03450100000055]
test_basic_poltergeist_test#ComputersTest (181.03s)
Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError: Request to 'http://127.0.0.1:50712/computers' failed to reach server, check DNS and/or server status - Timed out with no open resource requests
poltergeist (1.15.0) lib/capybara/poltergeist/browser.rb:377:in `command'
...
1/1: [=========================================================================================================================================================] 100% Time: 00:03:01, Time: 00:03:01
Finished in 181.03610s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
它显示试图访问“http://127.0.0.1/users/sign_in”的事实告诉您某处存在配置错误,因为那里应该有一个端口号(水豚从未 运行 对其进行测试端口 80)。
首先,您设置了 Capybara.server_port = 3000
。您是否需要这样做而不是让 Capybara 分配一个随机的空闲端口?如果你确实需要修复它,3000 是一个糟糕的选择,因为这会阻止你在测试 运行.
其次,您设置了 Capybara.app_host
。你真的需要设置这个吗?当您要针对外部站点进行测试,或者如果您有特殊的 IP 要求时,通常会使用它。如果你真的需要设置 app_host
你可能还需要设置 Capybara.always_include_port = true
所以两个解决方案
取消设置
app_host
和server_port
,让 Capybara 管理它们将您的固定服务器端口更改为 3000 以外的端口并添加
Capybara.always_include_port = true
此外,您可能还想阅读 https://github.com/teamcapybara/capybara#using-capybara-with-minitest,因为在测试中设置 Capybara.default_driver = Capybara.javascript_driver
不会达到您想要的效果。
从 Rails 4.2 升级到 Rails 5.0 时,我的 issue/symptoms 与 OP 完全相同。我终于从注意到数据库时间太长中弄明白了——事务固定装置在它们应该被禁用的时候被启用了。我不确定是什么改变导致了这个默认翻转,但通过更明确地禁用事务固定装置,我能够解决这个问题。