Collective Idea

Collective Idea Logo

Daniel Morrison

Use Chrome with Cucumber & Capybara

By Daniel Morrison on September 27, 2011 in capybara, chrome, cucumber, firefox, rails, and selenium

We frequently swap out Firefox for Chrome in our selenium (@javascript) cucumber tests. It is actually very easy, but not widely known.

Update: I got some questions about why we’d use Chrome. Speed hasn’t been the issue (use capybara-webkit for that) but we have found some things that work better in Chrome vs Firefox (and vice-versa). Also, you get different rendering options and different standards support (for example, websockets). If you’re having test problems, switching probably isn’t your solution, but you can always try.

Step 1 – Tell Capybara about Chrome

Inside your features/support/env.rb add these lines:

Capybara.register_driver :chrome do |app|, :browser => :chrome)

Capybara.javascript_driver = :chrome

Step 2 – Install chromedriver

If you’re using homebrew on OS X (and why wouldn’t you?) simply install using:

brew install chromedriver

Otherwise, download it manually and make sure it is in your path (I typically put it in /usr/local/bin).

Step 3 – Run the features

Run your features and anything tagged with @javascript or @selenium is now running in Chrome instead of Firefox. Yay!

By Daniel Morrison on September 27, 2011 in capybara, chrome, cucumber, firefox, rails, and selenium


  1. glenn

    glenn September 27, 2012

    Thanks mate, this works fiine, but do you know how to override the user agent of the chrome browser? i’ve seen alot of tutorials but only with Firefox, but i much rather do it with chrome browser.

  2. Cyril

    Cyril December 17, 2012

    @glenn: see

  3. Maninder

    Maninder March 26, 2013

    no able to find inner html of an element

    Hello World

    not able o get value “Hello World”
    Using cucumber, capybara and crome driver
    All Latest versions

  4. Paul Kruger

    Paul Kruger November 15, 2013

    Does not work on mavricks

  5. gabe

    gabe October 16, 2014

    My env.rb looks like this:

    Capybara.default_selector = :css
    Capybara.register_driver :selenium do |app|, :browser => :chrome, :switches => %w[—test-type]) #comment it out!!!
    ActionController::Base.allow_rescue = false
      DatabaseCleaner.strategy = :transaction
    rescue NameError
      raise “You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it.”
    Cucumber::Rails::Database.javascript_strategy = :truncation

    that’s the parts that are not commented out anyway. It works great. I would like to test in firefox as well, and ideally eventually with other browsers. How do I switch back to firefox? 


Post a Comment

Contact Us

Find us on Google Maps
Collective Idea
44 East 8th Street, Suite 410
Holland, Michigan 49423 USA 42.790334-86.105251


Follow us on the Interwebs

We are currently available for medium and long term projects. Please get in touch if we can be of service.