简体   繁体   中英

Getting Headless Chrome to work with Capybara

Im a bit stuck, im following thoughtbots tutorial on this and everything "looks" correct: https://robots.thoughtbot.com/headless-feature-specs-with-chrome

  • I've verified my Chrome is version 59
  • I've used brew to install chromedriver, and verified it's version 2.3 at least

my rails_helper file (the relevant part) looks like this:

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    'chromeOptions:' => { args: %w(headless disable-gpu) }
  )

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    desired_capabilities: capabilities
end

Capybara.javascript_driver = :headless_chrome

Using the chromedriver-helper gem does allow me to use chrome just fine, but it doesn't stay headless. Also when I would check it I would confirm on the chrome that the automation test uses that no --headless flag appears.

What it's giving me now using the brew install chromedriver is:

Selenium::WebDriver::Error::WebDriverError:
       unable to connect to chromedriver 127.0.0.1:9515

So something seems off....it doesn't seem to know how to connect the brew chromedriver version..however most tutorials don't seem to say anything about linking anything using the brew version.

Any ideas? (Im Running on Rails 4.1 btw)

Since you're using brew to install chromedriver you need to completely remove chromedriver-helper and all the binaries and stubs it has installed. This is because bundler adds the installed binaries/stubs into the path before the version of chromedriver installed by brew and therefore shadows it. You can use

bundle exec which chromedriver

to find out which chromedriver is actually being used when you run your tests. If it's not the one installed by brew (usually /usr/local/bin/chromedriver) then keep removing them until it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM