Skip to content

Commit

Permalink
Fix a bug where the browser version was used instead of the driver ve…
Browse files Browse the repository at this point in the history
…rsion for Apple M1 and Linux compatibility check.
  • Loading branch information
kapoorlakshya committed Jan 17, 2021
1 parent a46c6fd commit b875f79
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
38 changes: 24 additions & 14 deletions lib/webdrivers/chromedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,43 @@ def file_name
System.platform == 'win' || System.wsl_v1? ? 'chromedriver.exe' : 'chromedriver'
end

def apple_m1_compatible?
if System.apple_m1_architecture? && browser_version >= normalize_version('87.0.4280.88')
Webdrivers.logger.debug 'Chrome version is Apple M1 compatible.'
def apple_m1_compatible?(driver_version)
if System.apple_m1_architecture? && driver_version >= normalize_version('87.0.4280.88')
Webdrivers.logger.debug 'chromedriver version is Apple M1 compatible.'
return true
end

Webdrivers.logger.debug 'Chrome version is NOT Apple M1 compatible. Required >= 87.0.4280.88'
Webdrivers.logger.debug 'chromedriver version is NOT Apple M1 compatible. Required >= 87.0.4280.88'
false
end

def download_url
return @download_url if @download_url

version = if required_version == EMPTY_VERSION
latest_version
else
normalize_version(required_version)
end

apple_arch = apple_m1_compatible? ? '_m1' : ''

file_name = System.platform == 'win' || System.wsl_v1? ? 'win32' : "#{System.platform}64#{apple_arch}"
url = "#{base_url}/#{version}/chromedriver_#{file_name}.zip"
driver_version = if required_version == EMPTY_VERSION
latest_version
else
normalize_version(required_version)
end
filename = driver_filename(driver_version)
url = "#{base_url}/#{driver_version}/chromedriver_#{filename}.zip"
Webdrivers.logger.debug "chromedriver URL: #{url}"
@download_url = url
end

def driver_filename(driver_version)
if System.platform == 'win' || System.wsl_v1?
'win32'
elsif System.platform == 'linux'
'linux64'
elsif System.platform == 'mac'
apple_arch = apple_m1_compatible?(driver_version) ? '_m1' : ''
"mac64#{apple_arch}"
else
raise 'Failed to determine driver filename to download for your OS.'
end
end

# Returns major.minor.build version from the currently installed chromedriver version
#
# @example
Expand Down
50 changes: 27 additions & 23 deletions lib/webdrivers/edgedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,44 @@ def file_name
System.platform == 'win' ? 'msedgedriver.exe' : 'msedgedriver'
end

def apple_m1_compatible?
if System.apple_m1_architecture? && browser_version >= normalize_version('87.0.669.0')
Webdrivers.logger.debug 'Edge version is Apple M1 compatible.'
def apple_m1_compatible?(driver_version)
if System.apple_m1_architecture? && driver_version >= normalize_version('87.0.669.0')
Webdrivers.logger.debug 'msedgedriver version is Apple M1 compatible.'
return true
end

Webdrivers.logger.debug 'Edge version is NOT Apple M1 compatible. Required >= 87.0.669.0'
Webdrivers.logger.debug 'msedgedriver version is NOT Apple M1 compatible. Required >= 87.0.669.0'
false
end

def linux_compatible?
System.platform == 'linux' && browser_version >= normalize_version('89.0.731.0')
def linux_compatible?(driver_version)
System.platform == 'linux' && driver_version >= normalize_version('89.0.731.0')
end

def driver_filename(driver_version)
if System.platform == 'win'
'win32'
elsif linux_compatible?(driver_version)
'linux64'
elsif System.platform == 'mac'
# Determine M1 or Intel architecture
apple_arch = apple_m1_compatible?(driver_version) ? 'arm' : 'mac'
"#{apple_arch}64"
else
raise 'Failed to determine driver filename to download for your OS.'
end
end

def download_url
return @download_url if @download_url

version = if required_version == EMPTY_VERSION
latest_version
else
normalize_version(required_version)
end

file_name = if System.platform == 'win'
'win32'
elsif linux_compatible?
'linux64'
elsif apple_m1_compatible?
'amd64'
else
'mac64'
end

url = "#{base_url}/#{version}/edgedriver_#{file_name}.zip"
driver_version = if required_version == EMPTY_VERSION
latest_version
else
normalize_version(required_version)
end
filename = driver_filename(driver_version)
url = "#{base_url}/#{driver_version}/edgedriver_#{filename}.zip"
Webdrivers.logger.debug "msedgedriver URL: #{url}"
@download_url = url
end
Expand Down

0 comments on commit b875f79

Please sign in to comment.