Low commit activity in last 3 years
No release in over a year
A nice and tidy Capybara driver for headless Chrome. Even supports file downloads!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 10.0
~> 3.0

Runtime

 Project Readme

Capybara::HeadlessChrome

Build Status

A nice and tidy Capybara driver for headless Chrome. Even supports file downloads!

Usage

Capybara Setup

Just require "capybara/headless_chrome" somewhere in your test setup. This will register the :chrome driver, and make it Capybara's default.

Options

If you want to change some of the options Chrome is started with, just reregister the driver:

Capybara.register_driver :chrome do |app|
  Capybara::HeadlessChrome::Driver.new(app, lang: "es_MX", headless: false, window_size: [1024,768])
end

Consult https://peter.sh/experiments/chromium-command-line-switches/ for a list of options. Although these are command-line options, conversion from a Ruby hash works as you would expect. E.g. headless: true works out to --headless, window_size: [1024,768] works out to --window-size=1024,768, etc.

Working with Downloaded Files

The Capybara session is extended with a single #downloads method that provides access to files downloaded during the session.

page.click_link "Download Report"
page.downloads.filenames # => ["report.csv"]
page.downloads["report.csv"] # => #<File:report.csv>

Note that the #[] method is wrapped with Capybara's synchronize, so it will keep trying to find the file for up to Capybara.default_max_wait_time seconds.

Be sure to run page.downloads.reset at the beginning of every test run to empty the downloaded files list.

If you're using Cucumber, you can require "capybara/headless_chrome/cucumber" somewhere in your cucumber configuration to set this up for you.

Installation

Add this to your application's Gemfile:

group :test do
  gem 'capybara-headless_chrome'
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install capybara-headless_chrome

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/capybara-headless_chrome.

License

The gem is available as open source under the terms of the MIT License.