Skip to content

Commit

Permalink
Chrome/Edgedriver - Fix #171 by making sure the cached driver's build…
Browse files Browse the repository at this point in the history
… version matches the browser's build version before using it.
  • Loading branch information
kapoorlakshya committed May 25, 2020
1 parent fcea4dc commit 564907d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
32 changes: 25 additions & 7 deletions lib/webdrivers/chromedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ def current_version
def latest_version
@latest_version ||= begin
# Versions before 70 do not have a LATEST_RELEASE file
return normalize_version('2.41') if release_version < normalize_version('70')
return normalize_version('2.41') if browser_build_version < normalize_version('70')

latest_applicable = with_cache(file_name) { latest_point_release(release_version) }
# Cache check
# Cached version should exist and be compatible with the current browser version.
# Otherwise, fetch the latest compatible driver.
latest_applicable = with_cache(file_name,
current_build_version,
browser_build_version) { latest_point_release(browser_build_version) }

Webdrivers.logger.debug "Latest version available: #{latest_applicable}"
normalize_version(latest_applicable)
Expand Down Expand Up @@ -98,15 +103,28 @@ def download_url
@download_url = url
end

# Returns release version from the currently installed Chrome version
# Returns major.minor.build version from the currently installed chromedriver version
#
# @example
# 73.0.3683.75 -> 73.0.3683
def release_version
chrome = normalize_version(browser_version)
normalize_version(chrome.segments[0..2].join('.'))
# 73.0.3683.68 (major.minor.build.patch) -> 73.0.3683 (major.minor.build)
def current_build_version
build_ver = if current_version.nil? # Driver not found
nil
else
current_version.segments[0..2].join('.')
end
normalize_version(build_ver)
end

# Returns major.minor.build version from the currently installed Chrome version
#
# @example
# 73.0.3683.75 (major.minor.build.patch) -> 73.0.3683 (major.minor.build)
def browser_build_version
normalize_version(browser_version.segments[0..2].join('.'))
end
alias chrome_build_version browser_build_version

def sufficient_binary?
super && current_version && (current_version < normalize_version('70.0.3538') ||
current_version.segments.first == release_version.segments.first)
Expand Down
12 changes: 9 additions & 3 deletions lib/webdrivers/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@ def binary_version
nil
end

def with_cache(file_name)
if System.valid_cache?(file_name)
normalize_version System.cached_version(file_name)
# Returns cached driver version if cache is still valid and the driver binary exists.
# Otherwise caches the given version (typically the latest available)
# In case of Chrome, it also verifies that the driver build and browser build versions are compatible.
# Example usage: lib/webdrivers/chromedriver.rb:34
def with_cache(file_name, driver_build = nil, browser_build = nil)
if System.valid_cache?(file_name) && exists? && (driver_build == browser_build)
cached_version = System.cached_version(file_name)
Webdrivers.logger.debug "using cached version as latest: #{cached_version}"
normalize_version cached_version
else
version = yield
System.cache_version(file_name, version)
Expand Down

0 comments on commit 564907d

Please sign in to comment.