2016-12-14 41 views
0

Poltergeist無法連接到服務器。下面是我得到的錯誤:使用路徑助手時,水豚Poltergeist被迫通過https

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. 

與托馬斯 - 沃波爾@幫助我意識到,如果我具體的非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發送路徑助手將不勝感激。

+0

如果相關,我可以在命令行上使用phantomjs連接'http://127.0.0.1:3000 /'。 – equivalentideas

回答

0

您的應用將請求重定向到https,但Capybara不會使用https支持運行該應用。如果它是一款Rails應用程序,則可能在應用程序中啓用了config.force_ssl選項 - 在測試環境中將其設置爲false。如果這樣做不能解決問題,那麼你必須仔細查看你的應用,看看它爲什麼重定向,並在測試模式下關閉該行爲。

+0

我認爲你是對的。當我將測試從'訪問root_path'改爲'visit「http://127.0.0.1:3000」'它的工作。 – equivalentideas

+0

端口3000通常是您應用的開發實例,而不是Capybara開始測試的應用實例。缺省情況下,config/environments/development.rb中有'config.force_ssl = false',嘗試將其添加到'config/environments/test.rb'中。如果這不能解決它,那麼你需要弄清楚你是如何設置SSL重定向 –

+0

所以我已經調整了測試使用訪問'path_url',它的作品並沒有通過HTTPS,但使用'root_path'。我已經將'config.force_ssl = false'添加到'config/environments/test.rb'中,但這並沒有什麼不同。 – equivalentideas

相關問題