4

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)

msmith1114
  • 2,717
  • 3
  • 33
  • 84
  • I would look into using poltergeist with phantomjs and capybara. It is fully headless & handles js great. – bkunzi01 Jul 12 '17 at 19:24
  • @bkunzi01 Thats what I used before, however I wanted to at least give headless chrome a try. – msmith1114 Jul 12 '17 at 19:31
  • do `bundle exec chromedriver -v` and tell us what it prints, also - comment out the :chrome driver registration so you only have :headless_chrome - that will make sure you're not setting the driver to :chrome somewhere else – Thomas Walpole Jul 12 '17 at 19:49
  • @bkunzi01 Unfortunately, phantomjs currently has the downside of not supporting anything beyond ES5 or newer CSS (grids, etc)- which means a lot of newer stuff requires polyfilling and transpiling every piece of JS in the app - headless chrome makes things a lot cleaner from a testing perspective – Thomas Walpole Jul 12 '17 at 19:52
  • @ThomasWalpole `bundler: failed to load command: chromedriver (/usr/local/var/rbenv/versions/2.3.1/bin/chromedriver) Gem::LoadError: chromedriver-helper is not part of the bundle. Add it to Gemfile.` I don't have chromedriver helper, as im using `brew install chromedriver` to run it. I am running this under dev, for the database were using, but that shouldn't be relevant Also I get the same issue when commenting out the other portion. – msmith1114 Jul 12 '17 at 19:53
  • You need to completely remove chromedriver-helper and all of its remnants from your machine (including deleting /usr/local/var/rbenv/versions/2.3.1/bin/chromedriver). Can you actually just run `chromedriver -v` without the bundle exec. – Thomas Walpole Jul 12 '17 at 19:55
  • ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262) is what that returns, I did remove chromedriver from my $HOME/.chromedriver directory – msmith1114 Jul 12 '17 at 19:59
  • I do see chromedriver and chromedriver-update in the directory you mentioned however – msmith1114 Jul 12 '17 at 20:00
  • Yeah - remove them from that /usr/local/var/rbenv/versions/2.3.1/bin directory -- unfortunately the chromedriver-helper gem leaves them behind and they still get added to the path by bundler when your tests run, which means they get preference over the instance installed by brew – Thomas Walpole Jul 12 '17 at 20:04
  • This guy got it working with `'chromeOptions' => ` instead of `'chromeOptions:' =>`. Note the missing colon https://github.com/flavorjones/chromedriver-helper/issues/42#issuecomment-309245224 – iNulty Jul 12 '17 at 20:26
  • @ThomasWalpole do I remove both chromedriver and chromedriver-update from that directory? – msmith1114 Jul 12 '17 at 20:38
  • @msmith1114 Yes - if you no longer have chromedriver-helper in your gemfile remove both – Thomas Walpole Jul 12 '17 at 20:39
  • Hmmmm no luck, I also tried what @Nultyi suggested as well. Same error unfortunately: `Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515` – msmith1114 Jul 12 '17 at 20:40
  • @msmith1114 Try the `bundle exec chromedriver -v` when that correctly tells you 2.30 your setup should then be correct – Thomas Walpole Jul 12 '17 at 20:41
  • @Nultyi . Good catch -- it should be `chromeOptions: { args: %w(headless disable-gpu) }` IIRC, although that wouldn't have any effect on chromedriver not starting – Thomas Walpole Jul 12 '17 at 20:43
  • I've got it working on Ubuntu, downloaded the binary here https://chromedriver.storage.googleapis.com/index.html, extracted and added it to my users path ~/bin. Capybara picked it up no problem. Have you run `find / -name 'chromedriver*'` to see if theres anything else left on your machine that could be confusing matters? – iNulty Jul 12 '17 at 20:53
  • @ThomasWalpole I get: ` rbenv: chromedriver: command not found The `chromedriver' command exists in these Ruby versions: 2.0.0-p598` So I guess I need to delete that one too in rbenv? Removing that just leaves a `rbenv: chromedriver: command not found` afterwards. – msmith1114 Jul 12 '17 at 21:03
  • Try run `chromedriver` in your terminal. and visit http://127.0.0.1:9515 in any browser. You should get a white window with `unknown command:` – iNulty Jul 12 '17 at 21:13
  • I get `rbenv: chromedriver: command not found` which is weird cause it's def. brew installed – msmith1114 Jul 12 '17 at 21:17
  • you can run `bundle exec which chromedriver` to try and figure out what stub it's actually running - and then remove that – Thomas Walpole Jul 12 '17 at 21:20
  • `/usr/local/var/rbenv/shims/chromedriver` is what I see, isn't that where brew installs it though? – msmith1114 Jul 12 '17 at 21:23
  • you should delete the chromedriver references in rbenv shims directory. likely thats whats giving you the `rbenv: chromedriver: command not found` error. They'll be higher in your PATH probably than the brew executable – iNulty Jul 12 '17 at 21:27
  • Whew! that worked! thanks. Wonder what installed it there? – msmith1114 Jul 12 '17 at 21:31
  • that would have been the `chromedriver-helper` – iNulty Jul 12 '17 at 21:36
  • 1
    Your chromedriver should be version `>= 2.30` not `>= 2.3` – iNulty Jul 13 '17 at 08:22
  • Possible duplicate of [How to use headless chrome with capybara and selenium](https://stackoverflow.com/questions/44591612/how-to-use-headless-chrome-with-capybara-and-selenium) – fabdurso Jul 13 '17 at 09:41
  • I guess someone can put an answer so I can upvote it and accept since my question was indeed answered? – msmith1114 Jul 13 '17 at 13:21

1 Answers1

5

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.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78