20

For a Cucumber scenario on my Rails 3.1 app, I used the @javascript tag, so Selenium is activated. I get the following error:

Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path= (Selenium::WebDriver::Error::WebDriverError)

If possible, I'd like to use Google Chrome as the browser - not Firefox (which I haven't installed). Is this possible? What could be done?

In fact, shouldn't Cucumber/Selenium detect a browser and use it?

====EDIT====

After adding

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

...to features/support/env.rb, I now get this error:

Unable to find the chromedriver executable. Please download the server from http://code.google.com/p/chromium/downloads/list and place it somewhere on your PATH. More info at http://code.google.com/p/selenium/wiki/ChromeDriver. (Selenium::WebDriver::Error::WebDriverError)
  ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
  features/update_memories.feature:11:in `Given I am on the home page'

I've downloaded from here, and I've tried putting the chromedriver executable in /usr/bin, but I still get the above error.

====EDIT 2====

After going one step further and running "sudo chmod +x /usr/bin/chromedriver" as suggested below, I now get a new error after running cucumber:

@javascript
  Scenario: navigate to memory update page from home page              # features/update_memories.feature:11
    Given I am on the home page                                        # features/step_definitions/web_steps.rb:44
      unable to connect to chromedriver http://127.0.0.1:57870 (Selenium::WebDriver::Error::WebDriverError)
      ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
      features/update_memories.feature:12:in `Given I am on the home page'
    When I activate the edit memory switch for the memory "I played"   # features/step_definitions/memories/memory_steps.rb:5
    Then I should be on the edit memory page for the memory "I played" # features/step_definitions/web_steps.rb:187
      PGError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
      : ROLLBACK (ActiveRecord::StatementInvalid)

Help appreciated! Getting closer...

dmonopoly
  • 3,251
  • 5
  • 34
  • 49

6 Answers6

32

For capybara, add this to env.rb

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

Download the Chrome driver executable and copy it in you path, e.g. /usr/bin/ and make it executable

$ sudo chmod +x /usr/bin/chromedriver
meatherly
  • 1,741
  • 2
  • 13
  • 16
Joel Cogen
  • 488
  • 3
  • 9
  • 1
    Okay, I got one step further with the chmod command you specified (thanks!), but I now get a new error. I'm updating my question right now. – dmonopoly Sep 23 '11 at 07:24
  • 1
    FWIW, I was able to install chromedriver with Homebrew, but needed to add /usr/local/bin to my Textmate PATH in Preferences -> Advanced -> Shell Variables – orbiteleven Nov 10 '11 at 17:28
  • For me this solution was successfull only when I placed driver into /usr/bin. Placing it into /usr/local/bin (also included in PATH) did not the trick. – Alexander Kuznetsov May 30 '12 at 13:52
  • Hey everyone. Don't download chromedriver2. It doesn't work. I don't think the rails selenium gem is set up for it. Remove this comment if anything has changed. – meatherly May 16 '13 at 18:52
  • link to Chrome drive executables has changed to http://chromedriver.storage.googleapis.com/index.html – equivalent8 Jan 10 '14 at 16:45
  • I just added this to `spec_helper.rb` anywhere and did not need to run the `sudo` command, in case it's helpful to anyone else. Also after you download the Chrome driver, you have to unzip before putting it in your /usr/bin/ folder – james Oct 21 '14 at 22:15
  • I downloaded it from http://chromedriver.storage.googleapis.com/index.html and when I execute `sudo mv chromedriver /usr/bin/chromedriver`, I got `Operation not permitted` error. – Jeff Tian Dec 07 '15 at 05:57
  • I finally succeeded with `sudo mv chromedriver /usr/local/bin/chromedriver` – Jeff Tian Dec 07 '15 at 05:59
  • THANK YOOOOOUUUUUUUUUUUUUUUUUUUU. P.S, in rails with rspec, i just had to put this in spec_helper.rb – Ali Jan 15 '16 at 10:06
3

Today the easiest way to get the chromedriver executable seem to be installing the chromedriver-helper gem. Please see https://github.com/flavorjones/chromedriver-helper for details.

Besides installing the gem you'll have to configure your environment the same way as already mentioned in several other answers:

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
DonSteep
  • 1,075
  • 10
  • 10
1
Capybara.default_driver = :chrome
Selenium::WebDriver::Chrome::Service.executable_path = '/usr/local/bin/chromedriver' # specify the path of chromedriver
Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Rubyist
  • 6,486
  • 10
  • 51
  • 86
1

If you're using capybara try this

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

See capybara docs for additional details (especially take a look into Configuring and adding drivers section)

iafonov
  • 5,152
  • 1
  • 25
  • 21
  • I followed what you suggested, but I get a new error (see updated question)... any chance you could help out and update your answer? – dmonopoly Sep 20 '11 at 02:07
0

Try changing the setting "*chrome" to "*googlechrome" in the class setUp function.

Nathan Katz
  • 739
  • 1
  • 7
  • 12
  • No. Selenium itself has the confusing *chrome vs *googlechrome options, but in Capybara the options are the less crazy :firefox vs :chrome. – Anders Kindberg Feb 20 '13 at 09:28
0

try putting the path of chrome drivers in your PATH variable if you are on a linux distro with bash.

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

Download the Chrome driver executable and copy it in you path, e.g. /usr/bin/ and make it executable

$ sudo chmod +x /usr/bin/chromedriver

this worked for me

Gaurav Saini
  • 137
  • 1
  • 12