Search code examples
ruby-on-railsruby-on-rails-4capybarapoltergeist

Capybara/Poltergeist failed to reach server (Connection refused + GET '/identify')


Update

  • test.log is showing that the server is responding to our test and rendering the page.
  • Poltergeist fails with 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 is unable to connect to the server.

I have tried many variations, including:

  • Longer timeout periods (up to 300 seconds).
  • Setting the Capybara.app_host to www.example.com, localhost, or 127.0.0.1.
  • Removing phantomjs_options.
  • Removing force_ssl if: :ssl_configured? from static_controller.rb.
  • Rendering users/sign_in with no layout to eliminate external javascript.
  • Changing the test to call new_user_session_path, new_user_session_url, and /users/sign_in.
  • Running RAILS_ENV=test rake assets:precompile before running the test (manually).

When I run rails s -e test, I can open the URL 127.0.0.1:3000/users/sign_in.

Here's the error I'm getting:

✗ 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"

The server logs when I run a test (this block happens twice):

[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'

New logs after:

  • Switching to Puma
  • Adding in the code for Minitest
  • Setting Capybara.default_driver = :poltergeist in test_helper.rb to stop running rack_test by mistake.
  • Removing Capybara.default_driver = Capybara.javascript_driver from the test.

Logs:

✗ 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

Latest test.log

------------------------------------------
ComputersTest: test_basic_poltergeist_test
------------------------------------------
  [1m[36mUser Load (0.2ms)[0m  [1mSELECT  "users".* FROM "users" WHERE "users"."id" = $1 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" = '[email protected]' AND "users"."id" != 980190962) LIMIT 1[0m
  [1m[35mSQL (0.2ms)[0m  UPDATE "users" SET "role" = $1, "updated_at" = $2 WHERE "users"."id" = $3  [["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" = $1 LIMIT 1  [["id", 980190962]]
  [1m[35mComputer Load (0.1ms)[0m  SELECT  "computers".* FROM "computers" WHERE "computers"."id" = $1 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" = $1, ...  [...]
  [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" = $1 AND "computers"."company_id" = $2[0m  [["company_id", 980190962], ["company_id", 980190962]]
  [1m[35mComputer Load (0.2ms)[0m  SELECT "computers".* FROM "computers" WHERE "computers"."company_id" = $1 AND "computers"."company_id" = $2 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)

Updated readout when running the test:

✗ 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

Solution

  • The fact that it shows an attempted visit to "http://127.0.0.1/users/sign_in" tells you there is a configuration error somewhere because there should be a port number in there (Capybara never runs its tests on port 80).

    First, you've set Capybara.server_port = 3000. Do you have a need for that rather than letting Capybara assign a random free port? If you do need it fixed, 3000 is a bad choice since that will prevent you from having your dev instance running while tests run.

    Second, you've set Capybara.app_host. Do you have a real need for setting this? It's generally used when you want to test against an external site, or if you have special IP requirements. If you really have a need for setting app_host you probably also need to set Capybara.always_include_port = true

    So two solutions

    1. Get rid of setting app_host and server_port and just let Capybara manage them

    2. Change your fixed server port to something other than 3000 and add Capybara.always_include_port = true

    Additionally you probably want to read https://github.com/teamcapybara/capybara#using-capybara-with-minitest because setting Capybara.default_driver = Capybara.javascript_driver inside your test isn't going to do what you want.