質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

2回答

3615閲覧

「現場で使える Ruby on Rails 5速習実践ガイド」の第5章Rspecの実行で躓きます。

ItsukiN32

総合スコア13

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/10/06 13:51

編集2019/10/06 13:53

「現場で使える Ruby on Rails 5速習実践ガイド」の第5章Rspecの実行で躓きます。
うまく実行されなかったためネットで情報を集めていると、同じような方がいたので、

色んなサイトを参考にし、結果的に、以下のサイトのBにて対応しましたが、うまくいかず、続いてAを試しましたが、エラーは一向に変わりませんでした。

環境:WSL,ubuntu上, OS: windows10

参考にしたところ:
[https://gist.github.com/upinetree/fb71a947cc100e7918b7b280485d620c](現場で使える Ruby on Rails 5速習実践ガイド)

エラーが

Failure/Error: visit login_path Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

と表示されました。

関連ありそうな情報として、

google-chrome -v Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied Trace/breakpoint trap (core dumped) google-chrome -version Google Chrome 77.0.3865.90

その他、rspecを実行すると以下のようなコメントが冒頭にでるのも気になります。
(bundle updateはしています)

2019-10-06 22:36:43 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.

spec/spec_helper.rb の記述は以下です

spec/spec_helper.rb

1require 'capybara/rspec' 2require 'selenium-webdriver' 3Selenium::WebDriver::Chrome.driver_path = '/mnt/c/Windows/chromedriver.exe' 4 5RSpec.configure do |config| 6 config.before(:each, type: :system) do 7 driven_by :selenium_chrome_headless 8 end 9 # rspec-expectations config goes here. You can use an alternate 10 # assertion/expectation library such as wrong or the stdlib/minitest 11 # assertions if you prefer. 12 config.expect_with :rspec do |expectations| 13 # This option will default to `true` in RSpec 4. It makes the `description` 14 # and `failure_message` of custom matchers include text for helper methods 15 # defined using `chain`, e.g.: 16 # be_bigger_than(2).and_smaller_than(4).description 17 # # => "be bigger than 2 and smaller than 4" 18 # ...rather than: 19 # # => "be bigger than 2" 20 expectations.include_chain_clauses_in_custom_matcher_descriptions = true 21 end 22 23 # rspec-mocks config goes here. You can use an alternate test double 24 # library (such as bogus or mocha) by changing the `mock_with` option here. 25 config.mock_with :rspec do |mocks| 26 # Prevents you from mocking or stubbing a method that does not exist on 27 # a real object. This is generally recommended, and will default to 28 # `true` in RSpec 4. 29 mocks.verify_partial_doubles = true 30 end 31 32 # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 33 # have no way to turn it off -- the option exists only for backwards 34 # compatibility in RSpec 3). It causes shared context metadata to be 35 # inherited by the metadata hash of host groups and examples, rather than 36 # triggering implicit auto-inclusion in groups with matching metadata. 37 config.shared_context_metadata_behavior = :apply_to_host_groups 38 39# The settings below are suggested to provide a good initial experience 40# with RSpec, but feel free to customize to your heart's content. 41=begin 42 # This allows you to limit a spec run to individual examples or groups 43 # you care about by tagging them with `:focus` metadata. When nothing 44 # is tagged with `:focus`, all examples get run. RSpec also provides 45 # aliases for `it`, `describe`, and `context` that include `:focus` 46 # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 47 config.filter_run_when_matching :focus 48 49 # Allows RSpec to persist some state between runs in order to support 50 # the `--only-failures` and `--next-failure` CLI options. We recommend 51 # you configure your source control system to ignore this file. 52 config.example_status_persistence_file_path = "spec/examples.txt" 53 54 # Limits the available syntax to the non-monkey patched syntax that is 55 # recommended. For more details, see: 56 # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 57 # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 58 # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 59 config.disable_monkey_patching! 60 61 # Many RSpec users commonly either run the entire suite or an individual 62 # file, and it's useful to allow more verbose output when running an 63 # individual spec file. 64 if config.files_to_run.one? 65 # Use the documentation formatter for detailed output, 66 # unless a formatter has already been configured 67 # (e.g. via a command-line flag). 68 config.default_formatter = "doc" 69 end 70 71 # Print the 10 slowest examples and example groups at the 72 # end of the spec run, to help surface which specs are running 73 # particularly slow. 74 config.profile_examples = 10 75 76 # Run specs in random order to surface order dependencies. If you find an 77 # order dependency and want to debug it, you can fix the order by providing 78 # the seed, which is printed after each run. 79 # --seed 1234 80 config.order = :random 81 82 # Seed global randomization in this process using the `--seed` CLI option. 83 # Setting this allows you to use `--seed` to deterministically reproduce 84 # test failures related to randomization by passing the same `--seed` value 85 # as the one that triggered the failure. 86 Kernel.srand config.seed 87=end 88end

そのほか、関係ありそうな以下のコードも実行したのですが、ダメでした。

sudo apt-get install chromium-browser

chromedriverをデスクトップに解凍して、移動させたのですが、これもダメでした。

sudo mv /mnt/c/Users/user/Desktop/chromedriver_win32/chromedriver.exe /bin/chromedriver.exe

どうしたらうまくいくか分からないので、どなたかアドバイスをいただけたら幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

ubuntu内の問題railsアプリ外の他のプログラムからはseleniumよりchromedriverを起動することはできていました。
そこで、railsアプリ自体に問題があると考え、rspecに関係するプログラムを色々いじってみて当たりを引き当てました。

Selenium::WebDriver::Chrome.driver_path = '/mnt/c/Windows/chromedriver.exe'

※私はchromedriver.exeを C:/Windows/ 下に置いています。
の記入位置をconfig.before プロック内の

config.before(:each, type: :system) do Selenium::WebDriver::Chrome.driver_path = '/mnt/c/Windows/chromedriver.exe' driven_by :selenium_chrome_headless end

このようにすることで動作が確認できました。
config.beforeのプロックでseleniumの設定がリセットされるのか分かりませんが、初学者故に各関数を理解せずに配置しているので、勉強が必要だと感じました。

投稿2019/10/25 16:36

ItsukiN32

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

こちらの質問とも似ているので、リンクを添えておきますね。
https://teratail.com/questions/215554

また、Chromedriverですが、実際にはUbuntuの中でのRuby, Chrome, Seleniumの実行でしょうか。

であれば、Chromedriverは chromedriver.exe ではダメです。
これはWindows用のバイナリです。

リンクのコメントにもあるように、

https://chromedriver.chromium.org/downloads にアクセスし、Chrome本体のバージョンにあったchromedriverのリンクをクリックして、linux版のバイナリをダウンロードして、zipを展開して、パスの通ったところに置く、という流れにはなります。

linux版のバイナリをダウンロードして、zipを解凍して /bin/ の下に置くか、

# Windows版(*.exe)でなくLinux版! Selenium::WebDriver::Chrome.driver_path = '/mnt/c/Windows/chromedriver'

と、フルパスで指定する必要があります。

投稿2019/10/13 08:17

suama

総合スコア1997

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ItsukiN32

2019/10/24 14:41

お返事が遅くなり申し訳ありません。 あれから、ご指摘いただいた通り、linux版をダウンロード解凍し、bin/以下に配置、また、フルパス指定の両方を試したのですが、結果は同じで、 ``` Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) ``` と表示されてしまいます。 他にもググって検索したのですが、同じエラーが出ている人がいないので困惑しています。 何か思い当たる点などがありましたら教えてもらえると幸いです。 半ば諦めています。。。。
ItsukiN32

2019/10/25 16:10

お世話になります。 --no-sandboxもダメだったので、一度ubuntuを再インストールして、環境を再構築してやってみました。 すると、エラー文が変化し Webdrivers::BrowserNotFound: Failed to find Chrome binary. と表示されるようになりました。 その後、chromedriverのバイナリをデスクトップ上においてみたり、ubuntuの /usr/local/bin/ においてみたり、chromedriver.exeで同じことを試してみたりしましたが、すべて同じ表記のエラーのままでした。 driverのパスの指定は相変わらず同じです。例: Selenium::WebDriver::Chrome.driver_path = '/usr/local/bin/chromedriver.exe' どうやらchromedriverがないと判断しているようです。 ちなみにrbenvを使っていて、PATHは優先順から /home/username/.rbenv/shims /home/username/.rbenv/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin となっています。。 なぜchromedriverを認識してくれないのか。。
ItsukiN32

2019/10/25 16:37

すみません、すごく力を注いでいただいたのに申し訳ないのですが、自己解決することができました。 自身ではなぜうまくいっているかがまだ理解できていませんが、色々とアドバイスをありがとうございました!
suama

2019/10/26 00:20

良かったですね!自己解決が一番良いとおもっています! 「specのヘルパーでChromeDriverの設定をするあたりがあると思います」と添えたように、rspecの設定調整が’必要な場合はありますし、結局はそのあたりを確認されたのかな?とは思います。 「システムテストのときはChromeつかうよー」といった設定ですね。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問