title: Getting Selenium WebDriver to use Chrome in RSpec/Rails
body: <p>I'm using Selenium WebDriver with my RSpec tests on a Rails 4 web app. There's no problem using Firefox in my tests, but I can't get the Chrome web driver to work.</p>
  
  <p>This is what I've done:</p>
  
  <ol>
  <li><p>Downloaded Chrome driver (version 2.9) from <a href="http://chromedriver.storage.googleapis.com/index.html" rel="nofollow">http://chromedriver.storage.googleapis.com/index.html</a></p></li>
  <li><p>Unzipped and put the driver into <code>/usr/bin/</code></p>
  
  <pre><code>sudo mv chromedriver /usr/bin/
  sudo chmod +x /usr/bin/chromedriver
  </code></pre></li>
  <li><p>Added this to <code>spec_helper.rb</code>:</p>
  
  <pre><code>Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(app, :browser =&gt; :chrome)
  end
  </code></pre></li>
  <li><p>Modify my test (<code>page_spec.rb</code>) to use Chrome for web driver.</p>
  
  <pre><code>require 'rspec_gem'
  require 'rspec-expectations'
  require 'selenium-webdriver'
  
  driver = Selenium::WebDriver.for :chrome
  </code></pre></li>
  <li><p>This is the dev and test group in my <code>Gemfile.rb</code>:</p>
  
  <pre><code>group :development, :test do
    gem 'sqlite3', '1.3.7'               # Using sqlite for development builds
    gem 'rspec-rails', '2.13.2'          # Unit Test tool
    gem 'annotate', '2.5.0'              # For annotating models
    gem 'simplecov'                      # Code coverage analysis.
    gem 'capybara', '~&gt;2.0'              # Headless browser for test.
    gem 'selenium-webdriver'
    gem 'database_cleaner', '1.2.0' # github: 'bmabey/database_cleaner'
    gem 'better_errors'                  # Replaces standard rails errors page
    gem 'binding_of_caller'
    gem 'factory_girl_rails', '4.1.0'    # Generate user factories for testing.
    gem 'faker', '1.1.2'                 # Tool to seed the user database.
    gem 'rspec_gem'                      # For Selenium tests
    gem 'rspec-expectations'
    gem 'debugger'
  end
  </code></pre></li>
  <li><p>I run the test using this command:</p>
  
  <pre><code>bundle exec rspec -fd page_spec.rb
  </code></pre></li>
  </ol>
  
  <p>This is the error I get when I try to run the test:</p>
  
  <pre><code>/home/jchan/.rvm/gems/ruby-2.0.0-p247/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/chrome/service.rb:50:in `start': unable to connect to chromedriver http://127.0.0.1:9516 (Selenium::WebDriver::Error::WebDriverError)
  </code></pre>
  
  <p>I'm not sure why it cannot connect to the chromedriver.</p>