Chrome version: 59.0.3071.104
Using Cucumber, Capybara, Selenium to implement automation testing with Headless Chrome.
features/support/env.rb
require 'rubygems'
require 'capybara/cucumber'
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome, args: ['headless'])
end
Capybara.default_driver = :selenium_chrome
When running a cucumber test, it says:
WARN Selenium [DEPRECATION] :args or :switches is deprecated. Use Selenium::WebDriver::Chrome::Options#add_argument instead.
What is the correct way to use capybara and selenium with Headless Chrome. Thank you.
EDIT 1: I tried the following using Ruby-Binding, Capybara and Working Example. But it gives errors as well.
require 'rubygems'
require 'capybara/cucumber'
require 'selenium-webdriver'
Capybara.register_driver :selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
driver = Selenium::WebDriver.for :chrome, options: options
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: driver
)
end
Capybara.default_driver = :selenium_chrome
Error:
> undefined method `each' for
> #<Selenium::WebDriver::Remote::Capabilities:0xd13baac> (NoMethodError)
Edit 2: Download the latest ChromeDriver 2.30
Using the example from ChromeDriver Capabilities & Chrome Command Line Switches I get an error.
Net::ReadTimeout (Net::ReadTimeout)
require 'rubygems'
require 'capybara/cucumber'
require 'selenium-webdriver'
Capybara.register_driver :selenium_chrome do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
"binary" => "/chromedriver_win32/chromedriver.exe",
"args" => [ "--disable-web-security", "--headless" ]
}
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: caps
)
end
Capybara.default_driver = :selenium_chrome
1) Make sure you don't have another registered driver, I made this mistake myself and had an
iphone
driver, which was using theargs
in the old way, that's why I was getting the warning.2) Make sure you have Chrome version 57+ on Linux, 59+ on macOS or 60+ on Windows;
3) Add/update the gem
selenium-webdriver
;4) Add the following driver to your
spec_helper.rb
orrails_helper.rb
:Windows support is coming in Chrome 60.
Download "Chome Canary" and give the installation path as a
binary
inchromeOptions.
Download the latest "chromedriver" and add to path in Environment Variables.
I could get this working with the current version of Chrome, but it would display a blank window. If you want to get rid of that, then you need to use the "Chrome Canary" build.
The code below is a combination of the answers that @lucas-caton and @shawn-derik, but solves the issue I mentioned above.
The simplest way to run headless Chrome with Rails apps is to add the following gems to the
Gemfile
And update your
application_system_test_case.rb
with the following:There is no need to pass
args
as the drivers are already available to use, available drivers are:rack_test
,:selenium
,:selenium_chrome
,:selenium_chrome_headless
.You can run
Headless Chrome
Or you can also run
Chrome
and see test running on it