Created
March 14, 2019 00:55
-
-
Save seanlinsley/36a204862f08942b0667e941331f3a75 to your computer and use it in GitHub Desktop.
Ensures that chromedriver always matches the version of Chrome that's currently installed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/flavorjones/chromedriver-helper/issues/79 | |
# http://chromedriver.storage.googleapis.com/index.html | |
require 'open-uri' | |
require 'shellwords' | |
executable = if RUBY_PLATFORM =~ /darwin/ | |
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' | |
else | |
'google-chrome' | |
end | |
version = if system("which #{Shellwords.escape(executable)} > /dev/null 2>&1") | |
`#{Shellwords.escape(executable)} --version` | |
else | |
fail 'unable to determine Chrome binary location. Chrome must already be installed before installing chromedriver' | |
end | |
# Matches all except the last set of digits, as documented here: | |
# https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection | |
if /Google Chrome ([0-9,.]+)\.\d+ \n/ =~ version | |
version = Regexp.last_match(1) | |
else | |
fail "unexpected version string: #{version}" | |
end | |
chromedriver_version = open("https://chromedriver.storage.googleapis.com/LATEST_RELEASE_#{version}").read | |
Chromedriver.set_version chromedriver_version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment