项目作者: wbotelhos

项目描述 :
:package: Capybara Box - A Tool Box for Capybara
高级语言: Ruby
项目地址: git://github.com/wbotelhos/capybara-box.git
创建时间: 2017-09-27T20:47:45Z
项目社区:https://github.com/wbotelhos/capybara-box

开源协议:MIT License

下载


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:

  1. group :test do
  2. gem 'capybara-box', require: false
  3. end

Usage

Just require the lib after Capybara require and you done:

  1. require 'capybara/rails'
  2. require 'capybara-box'
  3. 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.

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

Version

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

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

Screenshot

You can enable screenshot on failure:

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

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

  1. ENV['CAPYBARA_BOX__S3_BUCKET_NAME']
  2. ENV['CAPYBARA_BOX__S3_REGION']
  3. ENV['CAPYBARA_BOX__S3_ACCESS_KEY_ID']
  4. ENV['CAPYBARA_BOX__S3_SECRET_ACCESS_KEY']

And then enable S3 feature:

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

Add Argument

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

  1. capybara_box = CapybaraBox.configure
  2. capybara_box.add_argument('--incognito')

Arguments

If you prefere, is possible override all of them:

  1. 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:

  1. capybara_box = CapybaraBox.configure
  2. capybara_box.add_preference(:credentials_enable_service, false)

Preferences

If you prefere, is possible override all of them:

  1. 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:

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

Driver Options

You can override all driver options:

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

Logger

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

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