27

I'm having some trouble getting Chrome to work with RSpec/Capybara on Ubuntu 13.10 64-bit. By default it launches Firefox - we tried to change this a variety of ways, including:

http://actsasblog.ca/2011/09/28/how-to-use-chrome-with-capybara/

/home/.../xxx_spec.rb:8:in `<top (required)>': undefined local variable or method `“chromedriver”' for main:Object (NameError)

We also tried:

require 'capybara/rspec'
require 'rspec'
require 'selenium-webdriver'

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

/home/ubuntu/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/chrome/service.rb:50:in `start': unable to connect to chromedriver http://127.0.0.1:9515 (Selenium::WebDriver::Error::WebDriverError)

Is there another step required to use Chrome? I'm new with Selenium.

zetetic
  • 47,184
  • 10
  • 111
  • 119
Jacob Schaer
  • 727
  • 1
  • 9
  • 14

4 Answers4

23

if I remember correctly:

I downloaded latest chromedriver from this resource https://code.google.com/p/selenium/wiki/ChromeDriver

Then insert in spec_helper.rb

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

Capybara.javascript_driver = :chrome

and it worked for me

gotva
  • 5,919
  • 2
  • 25
  • 35
  • 2
    We had to remove the gem `chrome-helper`, and manually run `chromedriver` for it to work. It looks like `chrome-helper` was adding its own version to the path. Do you have to run `chromedriver` before your tests, or does selenium start it for you? If we don't, it just says it can't connect on port 9515. – Jacob Schaer Jan 30 '14 at 17:17
  • it seems to me I put downloaded driver to `/usr/bin/google-chrome` and it worked for me automatically (I do not start chromedriver manually) – gotva Jan 31 '14 at 08:46
  • 2
    I had to go through this again today, only this time on OSX. We could only get it to work using the `chromedriver` from Brew and *not* installing the `chromedriver-helper` gem. – Jacob Schaer Feb 20 '14 at 04:26
  • 1
    +1 for removing `chromedriver-helper`. It may have been helpful in the past but currently it is broken due to https://github.com/flavorjones/chromedriver-helper/issues/7. Until the gem is uninstalled, selenium-webdriver is not able to pick up the locally installed `/usr/bin/chromedriver`, leading to the cryptic: "WebDriverError: unable to connect to chromedriver http://127.0.0.1:9515" – prusswan Jul 30 '14 at 11:42
  • On Windows, I put chromedriver.exe in my home directory `C:\Users\bonh\bin`, and added that directory to my PATH. – bonh Jan 30 '15 at 20:55
20

Add this gem to Gemfile to install and update chromedriver.

gem "chromedriver-helper", "1.0.0"

See https://github.com/flavorjones/chromedriver-helper. The bugs listed in comments to previous answers have been fixed.

Then add this to spec_helper.rb:

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

That's it.

haley
  • 1,573
  • 2
  • 12
  • 19
5

Add gem "chromedriver-helper" to Gemfile and run bundle

Also include this lines of code below into you spec_helper.rb outside Rspec.configure block.

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Most importantly, do not forget to require 'capybara' in the spec_helper.rb

This will solve the problem. :)

Surge
  • 256
  • 3
  • 16
-2
gem "chromedriver-helper", "1.0.0"

This has helped me. Try it.

dcangulo
  • 1,888
  • 1
  • 16
  • 48