Git Product home page Git Product logo

capybara-headless_chrome's Introduction

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.

capybara-headless_chrome's People

Contributors

botandrose-machine avatar josh-m-sharpe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.