Capybara Poltergeist无法使用StatusFailError在vpn中加载网站

时间:2017-06-09 20:20:50

标签: phantomjs capybara poltergeist

我试图在我们公司的CI系统中设置Poltergeist进行无头测试。

当我在内部服务器上使用Poltergeist时,看起来远程站点正在关闭连接。知道为什么吗?

Google.com很好,我们也可以使用Chrome进行测试。

当错误发生时,它立即发生(没有长时间超时)。这是以下调试信息。

    {"id":"b29e0ebb-6fd3-4ac4-9699-133579c0bc5b","name":"set_debug","args":[true]}
2017-06-09T13:42:25 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2017-06-09T13:42:26 [DEBUG] Set  "http"  proxy to:  "" : 1080
2017-06-09T13:42:26 [DEBUG] Phantom - execute: Configuration
2017-06-09T13:42:26 [DEBUG]      0 objectName : ""
2017-06-09T13:42:26 [DEBUG]      1 cookiesFile : ""
2017-06-09T13:42:26 [DEBUG]      2 diskCacheEnabled : "false"
2017-06-09T13:42:26 [DEBUG]      3 maxDiskCacheSize : "-1"
2017-06-09T13:42:26 [DEBUG]      4 diskCachePath : ""
2017-06-09T13:42:26 [DEBUG]      5 ignoreSslErrors : "true"
2017-06-09T13:42:26 [DEBUG]      6 localUrlAccessEnabled : "true"
2017-06-09T13:42:26 [DEBUG]      7 localToRemoteUrlAccessEnabled : "false"
2017-06-09T13:42:26 [DEBUG]      8 outputEncoding : "UTF-8"
2017-06-09T13:42:26 [DEBUG]      9 proxyType : "http"
2017-06-09T13:42:26 [DEBUG]      10 proxy : ":1080"
2017-06-09T13:42:26 [DEBUG]      11 proxyAuth : ":"
2017-06-09T13:42:26 [DEBUG]      12 scriptEncoding : "UTF-8"
2017-06-09T13:42:26 [DEBUG]      13 webSecurityEnabled : "true"
2017-06-09T13:42:26 [DEBUG]      14 offlineStoragePath : ""
2017-06-09T13:42:26 [DEBUG]      15 localStoragePath : ""
2017-06-09T13:42:26 [DEBUG]      16 localStorageDefaultQuota : "-1"
2017-06-09T13:42:26 [DEBUG]      17 offlineStorageDefaultQuota : "-1"
2017-06-09T13:42:26 [DEBUG]      18 printDebugMessages : "true"
2017-06-09T13:42:26 [DEBUG]      19 javascriptCanOpenWindows : "true"
2017-06-09T13:42:26 [DEBUG]      20 javascriptCanCloseWindows : "true"
2017-06-09T13:42:26 [DEBUG]      21 sslProtocol : "tlsv1"
2017-06-09T13:42:26 [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-06-09T13:42:26 [DEBUG]      23 sslCertificatesPath : ""
2017-06-09T13:42:26 [DEBUG]      24 sslClientCertificateFile : ""
2017-06-09T13:42:26 [DEBUG]      25 sslClientKeyFile : ""
2017-06-09T13:42:26 [DEBUG]      26 sslClientKeyPassphrase : ""
2017-06-09T13:42:26 [DEBUG]      27 webdriver : ":"
2017-06-09T13:42:26 [DEBUG]      28 webdriverLogFile : ""
2017-06-09T13:42:26 [DEBUG]      29 webdriverLogLevel : "INFO"
2017-06-09T13:42:26 [DEBUG]      30 webdriverSeleniumGridHub : ""
2017-06-09T13:42:26 [DEBUG] Phantom - execute: Script & Arguments
2017-06-09T13:42:26 [DEBUG]      script: "/Users/gslzwol/.rvm/gems/ruby-2.1.7@cardinal/gems/poltergeist-1.13.0/lib/capybara/poltergeist/client/compiled/main.js"
2017-06-09T13:42:26 [DEBUG]      0 arg: "53944"
2017-06-09T13:42:26 [DEBUG]      1 arg: "1024"
2017-06-09T13:42:26 [DEBUG]      2 arg: "768"
2017-06-09T13:42:26 [DEBUG] Phantom - execute: Starting normal mode
2017-06-09T13:42:26 [DEBUG] WebPage - setupFrame ""
2017-06-09T13:42:26 [DEBUG] FileSystem - _open: ":/modules/fs.js" QMap(("mode", QVariant(QString, "r")))
2017-06-09T13:42:26 [DEBUG] FileSystem - _open: ":/modules/system.js" QMap(("mode", QVariant(QString, "r")))
2017-06-09T13:42:26 [DEBUG] FileSystem - _open: ":/modules/webpage.js" QMap(("mode", QVariant(QString, "r")))
2017-06-09T13:42:26 [DEBUG] Phantom - injectJs: "/Users/gslzwol/.rvm/gems/ruby-2.1.7@cardinal/gems/poltergeist-1.13.0/lib/capybara/poltergeist/client/compiled/web_page.js"
2017-06-09T13:42:26 [DEBUG] Phantom - injectJs: "/Users/gslzwol/.rvm/gems/ruby-2.1.7@cardinal/gems/poltergeist-1.13.0/lib/capybara/poltergeist/client/compiled/node.js"
2017-06-09T13:42:26 [DEBUG] Phantom - injectJs: "/Users/gslzwol/.rvm/gems/ruby-2.1.7@cardinal/gems/poltergeist-1.13.0/lib/capybara/poltergeist/client/compiled/connection.js"
2017-06-09T13:42:26 [DEBUG] Phantom - injectJs: "/Users/gslzwol/.rvm/gems/ruby-2.1.7@cardinal/gems/poltergeist-1.13.0/lib/capybara/poltergeist/client/compiled/cmd.js"
2017-06-09T13:42:26 [DEBUG] Phantom - injectJs: "/Users/gslzwol/.rvm/gems/ruby-2.1.7@cardinal/gems/poltergeist-1.13.0/lib/capybara/poltergeist/client/compiled/browser.js"
2017-06-09T13:42:26 [DEBUG] WebpageCallbacks - getJsConfirmCallback
2017-06-09T13:42:26 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"b29e0ebb-6fd3-4ac4-9699-133579c0bc5b","response":true}
{"id":"89134f88-b0bd-48ab-8ba2-bc518460754f","name":"visit","args":["https://internal.server?foo=bar"]}
2017-06-09T13:42:26 [DEBUG] WebPage - updateLoadingProgress: 10
2017-06-09T13:42:28 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(RemoteHostClosedError) ( "Connection closed" ) URL: "https://internal.server/?foo=bar"
2017-06-09T13:42:28 [DEBUG] WebPage - updateLoadingProgress: 100
2017-06-09T13:42:28 [DEBUG] WebPage - setupFrame ""
2017-06-09T13:42:28 [DEBUG] WebPage - setupFrame ""
2017-06-09T13:42:28 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n      return typeof __poltergeist;\n    })(); })()"
2017-06-09T13:42:28 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
{"command_id":"89134f88-b0bd-48ab-8ba2-bc518460754f","error":{"name":"Poltergeist.StatusFailError","args":["https://internal.server?foo-bar",null]}}

这是我的浏览器设置:

 when 'poltergeist'
      Capybara.register_driver :poltergeist do |app|
        options = { 
          :debug => true,
          :phantomjs_options => [
            '--ignore-ssl-errors=yes',
            '--debug=true',
          ]
        } 
        Capybara::Poltergeist::Driver.new(app, options)
      end
      Capybara.default_driver = :poltergeist

Poltergeist 1.13.0,Capybara 2.6.2,Ruby 2.1.7-p400,OSX 10.11.6。谢谢!

1 个答案:

答案 0 :(得分:0)

这段代码解决了这个问题。我怀疑这是一个SSL安全问题,而ssl-protocol = any选项修复了它。

从现在开始,我将把这个用于我的所有错误:)

    phantomjs_options: [
      '--proxy-type=none', 
      '--load-images=no', 
      '--ignore-ssl-errors=yes', 
      '--ssl-protocol=any',
      '--web-security=false',
      '--debug=true
    ]