熱衷於將Capybara烘焙成新版本的Rails (5.1)cf http://weblog.rubyonrails.org/2017/2/23/Rails-5-1-beta1/Net :: ReadTimeout:Net :: ReadTimeout和Selenium :: WebDriver :: Error :: UnknownError:未知錯誤:Chrome無法在Rails 5.1.beta上啓動系統測試
雖然我遇到了問題。這是我的步驟。任何線索的歡迎。
全新安裝的:
- Linux的Ubuntu桌面16.10(VM在Hyper-V),具有安裝Chrome,並且罰款運行;
- Ruby 2.4;
- Rails 5.1.beta。
1.-創建一個簡單的應用程序:
~$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
~$ rails -v
Rails 5.1.0.beta1
~$ mkdir railsapps
~$ cd railsapps
~/railsapps$ rails new smoketestapp
~/railsapps$ cd smoketestapp
~/railsapps/smoketestapp$ rails generate scaffold post title:string body:text
~/railsapps/smoketestapp$ rails db:migrate
2:運行測試
~/railsapps/smoketestapp$ cat test/system/posts_test.rb
require "application_system_test_case"
class PostsTest < ApplicationSystemTestCase
test "visiting the index" do
visit posts_url
assert_selector "h1", text: "Post"
end
end
~/railsapps/smoketestapp$ rake test TEST=test/system/posts_test.rb
Run options: --seed 55778
# Running:
...
Error:
PostsTest#test_visiting_the_index:
Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.
...
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
~/railsapps/smoketestapp$
3.- OK,讓我們繼續在錯誤訊息建議(安裝chromedriver
):
~/railsapps/smoketestapp$ ls /usr/bin/google-chrome
lrwxrwxrwx 1 root root 31 Mar 18 15:31 /usr/bin/google-chrome -> /etc/alternatives/google-chrome*
~/railsapps/smoketestapp$ echo $PATH
...:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:...
~/railsapps/smoketestapp$ wget https://chromedriver.storage.googleapis.com/2.28/chromedriver_linux64.zip
~/railsapps/smoketestapp$ unzip chromedriver_linux64.zip
~/railsapps/smoketestapp$ sudo cp chromedriver /usr/local/bin
~/railsapps/smoketestapp$ ls /usr/local/bin
total 7504
drwxr-xr-x 2 root root 4096 Mar 19 19:05 ./
drwxr-xr-x 10 root root 4096 Okt 12 22:42 ../
-rwxr-xr-x 1 root root 7673176 Mar 19 19:05 chromedriver*
~/railsapps/smoketestapp$
4.-確定。重試測試...
~/railsapps/smoketestapp$ rake test TEST=test/system/posts_test.rb
Run options: --seed 51574
# Running:
...
Error:
PostsTest#test_visiting_the_index:
Net::ReadTimeout: Net::ReadTimeout test/system/posts _test.rb:5:in `block in '
...
bin/rails test test/system/posts_test.rb:4
...
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
~/railsapps/smoketestapp$
不好!
上的根源甲線索「網:: ReadTimeout:淨:: ReadTimeout」在該應用運行目錄時rails -v
,給硒::的webdriver ::錯誤::不明錯誤給出錯誤消息:未知錯誤:瀏覽器無法啓動:
~/railsapps/smoketestapp$ rails -v
Run options: --seed 39896
# Running:
.......E
Error:
PostsTest#test_visiting_the_index:
Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.28.455506 (18f6627e265f442aeec9b6661a49fe819aeeea1f),platform=Linux 4.8.0-41-generic x86_64)
test/system/posts_test.rb:5:in `block in <class:PostsTest>'
Error:
PostsTest#test_visiting_the_index:
Net::ReadTimeout: Net::ReadTimeout
bin/rails test test/system/posts_test.rb:4
...
~/railsapps/smoketestapp$
這是我獲得直接從紅寶石調用硒的webdriver時:
~/railsapps/smoketestapp$ irb
2.4.0 :001 > require "selenium-webdriver"
=> true
2.4.0 :002 > driver = Selenium::WebDriver.for(:chrome)
Net::ReadTimeout: Net::ReadTimeout
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/protocol.rb:176:in `rbuf_fill'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/protocol.rb:154:in `readuntil'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/protocol.rb:164:in `readline'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http/response.rb:40:in `read_status_line'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http/response.rb:29:in `read_new'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1446:in `block in transport_request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `catch'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `transport_request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1416:in `request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1409:in `block in request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:877:in `start'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/net/http.rb:1407:in `request'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:124:in `response_for'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:78:in `request'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:669:in `raw_execute'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:108:in `create_session'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:71:in `initialize'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/chrome/bridge.rb:52:in `initialize'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:61:in `new'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:61:in `for'
from ~/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver.rb:87:in `for'
from (irb):2
from ~/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'
2.4.0 :003 > exit
~/railsapps/smoketestapp$
任何幫助apprec iated,謝謝,你
內翻
更新:
發現問題,尋找到了硒驅動程序的日誌文件。要做到這一點,我輸入了IRB如下:
require "selenium-webdriver"
Selenium::WebDriver::Chrome.driver_path="/usr/local/bin/chromedriver"
Selenium::WebDriver.for :chrome, :service_log_path => "/tmp/cd.log"
driver = Selenium::WebDriver.for(:chrome)
尾礦日誌文件釘它:鉻會無法啓動:
~/railsapps/smoketestapp$ tail /tmp/cd.log
...
[0.247][INFO]: Launching chrome: /opt/google/chrome/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-hang-monitor --disable-prompt-on-repost --disable-web-resources --enable-logging --full-memory-crash-report --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.Pdre6o/internal --logging-level=1 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12264 --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.mHJaEd data:,
[0.250][WARNING]: PAC support disabled because there is no system implementation
[20.281][INFO]: RESPONSE InitSession unknown error: Chrome failed to start: exited abnormally
~/railsapps/smoketestapp$
最後,我發現調用鉻遠程通過PuTTY沒有工作(這就是我一直在做的),儘管直接在虛擬機(在終端服務器)上做同樣的工作。
在膩子:
~$ google-chrome
[3938:3938:0320/213941.129923:ERROR:browser_main_loop.cc(279)] Gtk: cannot open display:
然而,直接在虛擬機上,它的工作。
不幸的是,我的幸福是短暫的,因爲我遇到了另一個錯誤,但這是另一個故事:
irb(main):001:0> require "selenium-webdriver"
=> true
irb(main):002:0> Selenium::WebDriver::Chrome.driver_path="/usr/local/bin/chromedriver"
=> "/usr/local/bin/chromedriver"
irb(main):003:0> driver = Selenium::WebDriver.for(:chrome)
=> #<Selenium::WebDriver::Driver:0x59d7c889a916c6b8 browser=:chrome>
irb(main):004:0> driver.navigate.to("http://www.google.com")
Selenium::WebDriver::Error::UnknownError: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"10797.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=57.0.2987.110)
(Driver info: chromedriver=2.4.226074,platform=Linux 4.8.0-41-generic x86_64)
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:107:in `request'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:669:in `raw_execute'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:647:in `execute'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/bridge.rb:120:in `get'
from ~/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/navigation.rb:32:in `to'
from (irb):4
from ~/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'
irb(main):005:0> exit
什麼版本的Chrome,你已經安裝了? –
嗨托馬斯,這是它: 'Google Chrome 57.0.2987.110' –