[RUBY] Test with RSpec + Capybara + selenium + chromedriver

I mainly recorded it because I had trouble installing the chrome driver.

Gemfile settings

Gemfile


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

Introduction of chrome driver

$ brew install chromedriver 

Run'brew install chromedriver' on terminal Note: (Run in the root directory of your PC)

② Update to the latest version

$ brew update chromedriver

To start chrome in headless mode

spec/rails_helper.rb


RSpec.configure dp |config|
  #Other description
  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
 
  #Description for using capybara
  config.include Capybara::DSL
end

Finally#

I wrote an article like this I don't know why, but in rails_helper.rb It worked fine with metadata [: js].

I would be grateful if anyone could give me some advice.

Recommended Posts

Test with RSpec + Capybara + selenium + chromedriver
[Rails] Test with RSpec
Test Nokogiri with Rspec.
Test Active Strage with RSpec
Test GraphQL resolver with rspec
Copy and paste test with RSpec
Let's unit test with [rails] Rspec!
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
I want to test Action Cable with RSpec test
I rewrote the Rails tutorial test with RSpec
[For beginners] Test devise user registration with RSpec
Build an E2E test environment with Selenium (Java)
RSpec test code execution
Integration Test with Gradle
Introduction to RSpec 1. Test, RSpec
Testing model with RSpec
Use webmock with Rspec
Automatically test with Gauge
Load test with JMeter
Unit test with Junit.
Introduction to RSpec 4. Create test data with Factory Bot
How to test a private method with RSpec for yourself
How to erase test image after running Rspec test with CarrierWave
[Note] Design pattern considered when automating GUI test with Selenium
Check CSV value with RSpec
[Rails] Test code using Rspec
Remote debugging with Gradle test
[Rails] About Rspec response test
Understand code coverage with Rspec, the Ruby on Rails test framework