/capybara-box

:package: Capybara Box - A Tool Box for Capybara

Primary LanguageRubyMIT LicenseMIT

Capybara Box

CI Gem Version Maintainability Coverage Sponsor

Configure Capybara with Chrome, Chrome Headless, Firefox and Firefox Headless with Screenshot feature without losing your mind.

install

Add the following code on your Gemfile and run bundle install:

group :test do
  gem 'capybara-box', require: false
end

Usage

Just require the lib after Capybara require and you done:

require 'capybara/rails'
require 'capybara-box'

CapybaraBox::Base.configure

By default, selenium_chrome is the driver, but you can use selenium_chrome_headless and selenium_firefox or selenium_firefox_headless too.

CapybaraBox::Base.configure(browser: :selenium_firefox)

Version

The version is setted via webdrivers. You can specify the version:

CapybaraBox::Base.configure(version: '83.0.4103.39')

Screenshot

You can enable screenshot on failure:

CapybaraBox.configure(screenshot: { enabled: true })

If you want to send the screenshot and html page to S3 setup your credentials via ENV:

ENV['CAPYBARA_BOX__S3_BUCKET_NAME']
ENV['CAPYBARA_BOX__S3_REGION']
ENV['CAPYBARA_BOX__S3_ACCESS_KEY_ID']
ENV['CAPYBARA_BOX__S3_SECRET_ACCESS_KEY']

And then enable S3 feature:

CapybaraBox.configure(screenshot: { enabled: true, s3: true })

Add Argument

By default some Switches are enabled for a better performance, you can add yours too:

capybara_box = CapybaraBox.configure

capybara_box.add_argument('--incognito')

Arguments

If you prefere, is possible override all of them:

CapybaraBox.configure(arguments: ['--incognito'])

Click here to see the avaiables.

Add Preference

By default some Preferences are enabled for a better performance, you can add yours too:

capybara_box = CapybaraBox.configure

capybara_box.add_preference(:credentials_enable_service, false)

Preferences

If you prefere, is possible override all of them:

CapybaraBox.configure(preferences: { credentials_enable_service: false })

You can check Chrome and Firefox.

HTTP Client Options

By default some timeout configs are enabled only on CI env for a better performance. It has this restrition because with timeout enabled, debugger cannot evaluate the variables values. You can override all of them too:

CapybaraBox.configure(http_client_options: { read_timeout: 60 })

Driver Options

You can override all driver options:

CapybaraBox.configure(driver_options: { clear_local_storage: true })

Logger

Logs are writen as WARN on the STDOUT by default. You can change it:

CapybaraBox.configure(logger: { level: :debug, output: 'log/selenium.log' })