Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber; Selenium WebDriver - how to use Google Chrome as the testing browser instead of Firefox

Tags:

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...

like image 841
dmonopoly Avatar asked Jul 25 '11 20:07

dmonopoly


2 Answers

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
like image 181
Joel Cogen Avatar answered Oct 27 '22 23:10

Joel Cogen


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
like image 31
DonSteep Avatar answered Oct 27 '22 22:10

DonSteep