title: How to use headless chrome with capybara and selenium
body: <p>Chrome version: 59.0.3071.104</p>
  
  <p>Using Cucumber, Capybara, Selenium to implement automation testing with Headless Chrome.</p>
  
  <blockquote>
    <p>features/support/env.rb</p>
  </blockquote>
  
  <pre><code>require 'rubygems'
  require 'capybara/cucumber'
  
  Capybara.register_driver :selenium_chrome do |app|
    Capybara::Selenium::Driver.new(app, :browser =&gt; :chrome, args: ['headless'])
  end
  
  Capybara.default_driver = :selenium_chrome
  </code></pre>
  
  <p>When running a cucumber test, it says:</p>
  
  <blockquote>
    <p>WARN Selenium [DEPRECATION] :args or :switches is deprecated. Use
    Selenium::WebDriver::Chrome::Options#add_argument instead.</p>
  </blockquote>
  
  <p>What is the correct way to use capybara and selenium with Headless Chrome. Thank you.</p>
  
  <p>EDIT 1: I tried the following using <a href="https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings" rel="noreferrer">Ruby-Binding</a>, <a href="https://github.com/teamcapybara/capybara" rel="noreferrer">Capybara</a> and <a href="http://blog.faraday.io/headless-chromium/" rel="noreferrer">Working Example</a>. But it gives errors as well.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>&gt; undefined method `each' for
  &gt; #&lt;Selenium::WebDriver::Remote::Capabilities:0xd13baac&gt; (NoMethodError)
  </code></pre>
  
  <p>Edit 2:
  Download the latest <a href="https://sites.google.com/a/chromium.org/chromedriver/downloads" rel="noreferrer">ChromeDriver 2.30</a></p>
  
  <p>Using the example from <a href="https://sites.google.com/a/chromium.org/chromedriver/capabilities" rel="noreferrer">ChromeDriver Capabilities</a> &amp; <a href="http://peter.sh/experiments/chromium-command-line-switches/" rel="noreferrer">Chrome Command Line Switches</a> I get an error.</p>
  
  <blockquote>
    <p>Net::ReadTimeout (Net::ReadTimeout)</p>
  </blockquote>
  
  <pre><code>require 'rubygems'
  require 'capybara/cucumber'
  require 'selenium-webdriver'
  
  Capybara.register_driver :selenium_chrome do |app|
    caps = Selenium::WebDriver::Remote::Capabilities.chrome(
      "chromeOptions" =&gt; {
        "binary" =&gt; "/chromedriver_win32/chromedriver.exe",
        "args" =&gt; [ "--disable-web-security", "--headless" ]
      }
    )  
    Capybara::Selenium::Driver.new(
      app, 
      browser: :chrome, 
      desired_capabilities: caps
    )
  end
  
  Capybara.default_driver = :selenium_chrome
  </code></pre>