https://github.com/wbotelhos/capybara-box
:package: Capybara Box - A Tool Box for Capybara
https://github.com/wbotelhos/capybara-box
capybara chrome firefox headless-chrome screenshot selenium session
Last synced: about 1 year ago
JSON representation
:package: Capybara Box - A Tool Box for Capybara
- Host: GitHub
- URL: https://github.com/wbotelhos/capybara-box
- Owner: wbotelhos
- License: mit
- Created: 2017-09-27T20:47:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T11:39:17.000Z (over 3 years ago)
- Last Synced: 2025-03-26T08:37:11.116Z (about 1 year ago)
- Topics: capybara, chrome, firefox, headless-chrome, screenshot, selenium, session
- Language: Ruby
- Homepage: https://www.danca.com
- Size: 170 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Capybara Box
[](https://github.com/wbotelhos/capybara-box/actions)
[](https://badge.fury.io/rb/capybara-box)
[](https://codeclimate.com/github/wbotelhos/capybara-box/maintainability)
[](https://codecov.io/gh/wbotelhos/capybara-box)
[](https://github.com/sponsors/wbotelhos)
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:
```ruby
group :test do
gem 'capybara-box', require: false
end
```
## Usage
Just require the lib **after** Capybara require and you done:
```ruby
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.
```ruby
CapybaraBox::Base.configure(browser: :selenium_firefox)
```
## Version
The version is setted via `webdrivers`. You can specify the version:
```ruby
CapybaraBox::Base.configure(version: '83.0.4103.39')
```
## Screenshot
You can enable screenshot on failure:
```ruby
CapybaraBox.configure(screenshot: { enabled: true })
```
If you want to send the screenshot and html page to S3 setup your credentials via ENV:
```sh
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:
```ruby
CapybaraBox.configure(screenshot: { enabled: true, s3: true })
```
## Add Argument
By default some Switches are enabled for a better performance, you can add yours too:
```ruby
capybara_box = CapybaraBox.configure
capybara_box.add_argument('--incognito')
```
## Arguments
If you prefere, is possible override all of them:
```ruby
CapybaraBox.configure(arguments: ['--incognito'])
```
Click [here](https://peter.sh/experiments/chromium-command-line-switches) to see the avaiables.
## Add Preference
By default some Preferences are enabled for a better performance, you can add yours too:
```ruby
capybara_box = CapybaraBox.configure
capybara_box.add_preference(:credentials_enable_service, false)
```
## Preferences
If you prefere, is possible override all of them:
```ruby
CapybaraBox.configure(preferences: { credentials_enable_service: false })
```
You can check [Chrome](https://sites.google.com/a/chromium.org/chromedriver/home) and [Firefox](http://preferential.mozdev.org/preferences.html).
## 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:
```ruby
CapybaraBox.configure(http_client_options: { read_timeout: 60 })
```
## Driver Options
You can override all driver options:
```ruby
CapybaraBox.configure(driver_options: { clear_local_storage: true })
```
## Logger
Logs are writen as WARN on the `STDOUT` by default. You can change it:
```ruby
CapybaraBox.configure(logger: { level: :debug, output: 'log/selenium.log' })
```