Support headless Chrome
Closed this issue ยท 14 comments
Now that Chrome 59 has been released with support for headless mode, it'd be great if chromedriver-helper used the headless mode (by default). Or at the least, documented how to enable headless mode. I realize that this may require waiting on an updated version of chromedriver itself, but I wanted to make sure we don't forget about this nice new feature.
I found this article from Thoughtbot and tried following the instructions there. I verified that I'm using chromedriver 2.30 and Chrome 59, but the browser window appears, and when I go to chrome://version/, I don't see --headless
in the list.
Also worth mentioning is the Getting Started with Headless Chrome article from Google and the ChromeDriver Capabilities docs.
OK, I got it working. Oddly, I had to change chromeOptions:
in the Thoughtbot example code to 'chromeOptions' =>
to get it to work.
I still think it's worth mentioning how to get this working in the docs.
I love Ruby more than most (it is by far my favorite programming language), but I gotta say the "symbol vs. string" hash key issue is one of the biggest warts on the language. ๐ญ
If you're running on OSX - make sure to avoid the remote-debugging-port=9222
option, which causes chrome to hang, resulting in a Net::ReadTimeout
. (chrome 59.0.30, chromedriver 2.3)
Can you share your driver config, please?
I followed https://robots.thoughtbot.com/headless-feature-specs-with-chrome instructions along with converting chromeOptions key to string as you suggested and nothing happened. Capybara stucks without any log information.
PS My version is:
Chromium 59.0.3071.109 Built on Ubuntu , running on Ubuntu 16.04
Hey guys. I'm in the same boat as the others here. I've got Chromedriver working with Capybara, but I cannot, for the life of me, get the options working. Anytime I try to introduce the desired_capabilities
key, everything falls apart. I've tried changing symbols to keys, different options, chanting, yelling... nothing has worked yet.
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w(headless disable-gpu)
}
)
)
end
I've got Chromedriver 2.3 and selenium-webdriver
in the gemfile.
I was not able to get this to work with chromedriver version 2.28. When I updated to 2.31, it worked. Note that the path for the chromedriver bin is set by chromedriver-helper
and is in your gem path. I'd forgotten about this at first and so was inadvertently checking the version of chromedriver I had installed elsewhere.
Here is the code that I'm using in my cucumber features/support/env.rb
file that is working:
# Headless chrome browser.
# Use @selenium
Capybara.register_driver :selenium do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: ['headless', 'disable-gpu'])
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options
)
end
chromedriver-helper v. 1.1.0
selenium-webdriver 3.4.4
@weedySeaDragon Your config works for me! I've got headless chrome running. Now I have all kinds of problems related to changing from Poltergeist to Chrome, but progress is being made.
๐บ ๐ฎ ๐ Thanks very much.
It appears that when running headless, JavaScript is disabled. Has anyone else had this problem?
Thanks for opening this issue, and apologies for not responding earlier.
Honestly, I'm not sure it's within the ability of chromedriver-helper to opt into headless mode. All this gem does is download the correct executable for your platform and run it -- configuration needs to be done within your testing framework (e.g., Capybara).
I'm going to close this; though if I'm wrong and there's a PR that can be submitted to do this, I'm open to it.
@flavorjones No problem at all, this is absolutely unrelated to your work. I'm going to go bark up the right tree now. Thanks very much for the gem!
Thanks @weedySeaDragon, your config works. Did try ~ a dozen different config variants, to no avail.
@flavorjones Maybe how to pass options to the Driver (for example to run it headless) could be added to the Readme. I could open a PR, if desired.
I had to downgrade selenium-webdriver to v 3.4.4. My system test config looks like this. Note how I am forcing a version downloaded by the helper too. I found there is no class level property to set for future binstub run
to take advantage of. This seemed like a good way to be consistent.
require 'test_helper'
driver = Chromedriver::Helper.new
driver.update('2.30')
Selenium::WebDriver::Chrome.driver_path = driver.binary_path
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {
'args' => ['headless', 'disable-gpu', 'no-sandbox', 'window-size=1280,1024'],
'binary' => ENV['GOOGLE_CHROME_SHIM']
}.reject { |_k, v| v.nil? }
)
)
end
driven_by :headless_chrome
end
Ah, I am using latest selenium-webdriver
gem now and driver.update('2.36')
version now.