1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RSpec+Capybara+selenium+chromedriverでのテスト

Last updated at Posted at 2021-01-08

主にchromedriverの導入に手こずったので記録しておきます。

Gemfileの設定#

Gemfile
group :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'selenium-webdriver'
end

chromedriverの導入#

$ brew install chromedriver 

terminalにて 'brew install chromedriver'を実行
注意点:(PCのrootディレクトリーで実行すること)
※which chromedriverにでinstall先が見れる

②最新版にアップデートする

$ brew upgrade chromedriver

chromeをヘッドレスモードで起動するために#

spec/rails_helper.rb
RSpec.configure dp |config|
  #他の記述
  config.before(:each) do |example|
    if example.metadata[:type] == :system
      if example.metadata[:js]
        driven_by :selenium_chrome_headless, screen_size: [1400, 1400]
      else
        driven_by :rack_test
      end
    end
  end
 
  #capybaraを使うための記述
  config.include Capybara::DSL
end

最後に#

こんな記事を書いておいてなんですが、
なぜかわからないがrails_helper.rbに
metadata[:js]にしたらうまく動作しました。

どなたかアドバイスをいただければありがたいです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?