Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Chrome as Default Browser for RSpec/Capybara

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.

like image 414
Jacob Schaer Avatar asked Jan 29 '14 23:01

Jacob Schaer


People also ask

How do I set Google Chrome as the default browser on Windows?

In the Windows taskbar at the bottom, right-click on Chrome. Click Pin to taskbar. On your computer, click the Start menu . Click Control Panel. Click Programs Default Programs Set your default programs. On the left, select Google Chrome. Click Set this program as default. Click OK. On your computer, open Chrome. In the top right, click More .

How to enable capybara methods in test cases?

Some teams however may prefer using some of the Capybara methods (like feature ) to make it obvious that the test uses Capybara, while still disable the rest of the methods, like given (alias for let ), background (alias for before ), etc. You can configure which of the methods to be enabled by using the EnabledMethods configuration option.

Which capybara methods does the cop disable?

By default, the cop disables all Capybara-specific methods that have the same native RSpec method (e.g. are just aliases).

How to find elements that match a certain visibility in capybara?

Capybara lets you find elements that match a certain visibility using the :visible option. :visible accepts both boolean and symbols as values, however using booleans can have unwanted effects. visible: false does not find just invisible elements, but both visible and invisible elements.


2 Answers

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

like image 191
gotva Avatar answered Sep 20 '22 06:09

gotva


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.

like image 33
haley Avatar answered Sep 23 '22 06:09

haley