Capybara Poltergeist 在使用路径助手时被迫通过 https
Capybara Poltergeist getting forced over https when using path helpers
Poltergeist 无法连接到服务器。这是我收到的错误:
Failure/Error: visit root_path
Capybara::Poltergeist::StatusFailError:
Request to 'http://127.0.0.1:58638/' failed to reach server, check DNS and/or server status
我已经打开了 phantomjs 调试输出,下面是对我来说相关的行:
2016-12-14T14:24:47 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"5eab3091-26bd-47b7-b779-95ec9523fb5b","response":true}
{"id":"1069af41-1b7c-4f5b-a9c7-258185aa8c73","name":"visit","args":["http://127.0.0.1:58638/"]}
2016-12-14T14:24:47 [DEBUG] WebPage - updateLoadingProgress: 10
2016-12-14T14:24:48 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "https://127.0.0.1/"
2016-12-14T14:24:48 [DEBUG] WebPage - updateLoadingProgress: 100
2016-12-14T14:24:48 [DEBUG] WebPage - setupFrame ""
2016-12-14T14:24:48 [DEBUG] WebPage - setupFrame ""
2016-12-14T14:24:48 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2016-12-14T14:24:48 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
{"command_id":"1069af41-1b7c-4f5b-a9c7-258185aa8c73","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1:58638/",null]}}
{"id":"cbe42cdc-58db-49c5-a230-4a1f4634d830","name":"reset","args":[]}
这一点似乎是一个线索 Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "https://127.0.0.1/"
,它可能是一个 ssl 错误,所以我添加了 phantomjs 选项 --ignore-ssl-errors=true
,但它对响应没有影响。
我切换到 capybara-webkit
看看是否会像某些人推荐的那样提供更多信息。我得到一个非常相似的错误:
"Visit(http://127.0.0.1:64341/)" started page load
Started request to "http://127.0.0.1:64341/"
Finished "Visit(http://127.0.0.1:64341/)" with response "Success()"
Started request to "https://127.0.0.1/"
Received 301 from "http://127.0.0.1:64341/"
Received 0 from "https://127.0.0.1/"
Page finished with false
Load finished
Page load from command finished
Wrote response false "{"class":"InvalidResponseError","message":"Unable to load URL: http://127.0.0.1:64341/ because of error loading https://127.0.0.1/: Unknown error"}"
Received "Reset()"
Started "Reset()"
undefined|0|SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.
在@thomas-walpole 的帮助下,我意识到如果我指定一个非 https url 来访问水豚,它就可以工作。例如 visit "http://localhost:3000"
它有效。使用 visit root_url
有效,但使用 visit root_path
我被定向到 https 和上面的错误。
config.force_ssl
不正确。我在 config/environments/test.rb
中设置了 config.force_ssl = false
并且还使用 pry 在测试上下文中检查了 Application.config
。
任何关于为什么路径助手通过 https 发送的想法将不胜感激。
您的应用正在将请求重定向到 https,但 Capybara 运行 应用不支持 https。如果它是 rails 应用程序,您可能已经在您的应用程序中启用了 config.force_ssl
选项 - 在测试环境中将其设置为 false
。如果这不能解决问题,那么您将不得不查看您的应用以了解其重定向的原因并在测试模式下关闭该行为。
Poltergeist 无法连接到服务器。这是我收到的错误:
Failure/Error: visit root_path
Capybara::Poltergeist::StatusFailError:
Request to 'http://127.0.0.1:58638/' failed to reach server, check DNS and/or server status
我已经打开了 phantomjs 调试输出,下面是对我来说相关的行:
2016-12-14T14:24:47 [DEBUG] WebpageCallbacks - getJsConfirmCallback
{"command_id":"5eab3091-26bd-47b7-b779-95ec9523fb5b","response":true}
{"id":"1069af41-1b7c-4f5b-a9c7-258185aa8c73","name":"visit","args":["http://127.0.0.1:58638/"]}
2016-12-14T14:24:47 [DEBUG] WebPage - updateLoadingProgress: 10
2016-12-14T14:24:48 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "https://127.0.0.1/"
2016-12-14T14:24:48 [DEBUG] WebPage - updateLoadingProgress: 100
2016-12-14T14:24:48 [DEBUG] WebPage - setupFrame ""
2016-12-14T14:24:48 [DEBUG] WebPage - setupFrame ""
2016-12-14T14:24:48 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n return typeof __poltergeist;\n })(); })()"
2016-12-14T14:24:48 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
{"command_id":"1069af41-1b7c-4f5b-a9c7-258185aa8c73","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1:58638/",null]}}
{"id":"cbe42cdc-58db-49c5-a230-4a1f4634d830","name":"reset","args":[]}
这一点似乎是一个线索 Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "https://127.0.0.1/"
,它可能是一个 ssl 错误,所以我添加了 phantomjs 选项 --ignore-ssl-errors=true
,但它对响应没有影响。
我切换到 capybara-webkit
看看是否会像某些人推荐的那样提供更多信息。我得到一个非常相似的错误:
"Visit(http://127.0.0.1:64341/)" started page load
Started request to "http://127.0.0.1:64341/"
Finished "Visit(http://127.0.0.1:64341/)" with response "Success()"
Started request to "https://127.0.0.1/"
Received 301 from "http://127.0.0.1:64341/"
Received 0 from "https://127.0.0.1/"
Page finished with false
Load finished
Page load from command finished
Wrote response false "{"class":"InvalidResponseError","message":"Unable to load URL: http://127.0.0.1:64341/ because of error loading https://127.0.0.1/: Unknown error"}"
Received "Reset()"
Started "Reset()"
undefined|0|SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.
在@thomas-walpole 的帮助下,我意识到如果我指定一个非 https url 来访问水豚,它就可以工作。例如 visit "http://localhost:3000"
它有效。使用 visit root_url
有效,但使用 visit root_path
我被定向到 https 和上面的错误。
config.force_ssl
不正确。我在 config/environments/test.rb
中设置了 config.force_ssl = false
并且还使用 pry 在测试上下文中检查了 Application.config
。
任何关于为什么路径助手通过 https 发送的想法将不胜感激。
您的应用正在将请求重定向到 https,但 Capybara 运行 应用不支持 https。如果它是 rails 应用程序,您可能已经在您的应用程序中启用了 config.force_ssl
选项 - 在测试环境中将其设置为 false
。如果这不能解决问题,那么您将不得不查看您的应用以了解其重定向的原因并在测试模式下关闭该行为。