DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on

setup a Capybara

πŸ”— Parent Note

1. install gem

# Gemfile
group :test do
  gem 'capybara'
  gem 'capybara-screenshot' # recommend
  gem 'selenium-webdriver'
end

2. configure capybara

# spec_helper.rb
require 'capybara/rails' # For Rails app
require 'capybara/rspec' # Load RSpec 3.5+ support

# set up driver
Capybara.register_driver :headless_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    http_client: client
    options: options)
end

## set up client
require 'selenium-webdriver'
client = Selenium::WebDriver.for :chrome # see also following link.

## set up options
options = Selenium::WebDriver::Chrome::Options.new.tap do |opts|
  opts.args << '--headless'
end

# configure
Capybara.configure do |config|
  config.ignore_hidden_elements = true
  config.default_max_wait_time = 3 #sec
end

Top comments (1)

Collapse
 
ianvaughan profile image
Ian Vaughan

Should ## set up client go before # set up driver?
As you use client within it!