Chrome version: 59.0.3071.104
I am 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.
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)
I downloaded the latest ChromeDriver 2.30.
Using the example from ChromeDriver Capabilities and 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