Class: Chromedriver::Binary::ChromedriverDownloader

Inherits:
Object
  • Object
show all
Extended by:
DownloaderHelper, Platform, SystemHelper, VersionResolver
Defined in:
lib/chromedriver/binary/chromedriver_downloader.rb

Constant Summary

Constants included from VersionResolver

VersionResolver::BASE_URL, VersionResolver::CHROME_FOR_TESTING_BASE_URL

Class Method Summary collapse

Methods included from SystemHelper

call, exists?

Methods included from DownloaderHelper

download_file, exec_get_request, extract_zip

Methods included from Platform

driver_filename, file_name, linux_arm64?, platform, platform_id

Methods included from VersionResolver

browser_build_version, current_installed_version, direct_url_from_api, driver_path, latest_patch_version_for_build, normalize_version, query_binary_version

Class Method Details

.correct_binary?Boolean

rubocop:enable Metrics/AbcSize

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/chromedriver/binary/chromedriver_downloader.rb', line 64

def correct_binary?
  current_installed_version == browser_version || current_installed_version == latest_patch_version_for_build
rescue VersionError
  false
end

.driver_pathObject

Returns the absolute path to the driver_path ChromeDriver binary.



24
25
26
# File 'lib/chromedriver/binary/chromedriver_downloader.rb', line 24

def driver_path
  File.absolute_path File.join(install_dir, file_name)
end

.install_dirObject

Define where to install ChromeDriver.



19
20
21
# File 'lib/chromedriver/binary/chromedriver_downloader.rb', line 19

def install_dir
  Chromedriver::Binary.install_dir
end

.update(force: false) ⇒ String

Downloads and extracts the latest ChromeDriver.

rubocop:disable Metrics/AbcSize

Returns:

  • (String)

    the full path to the downloaded executable.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/chromedriver/binary/chromedriver_downloader.rb', line 32

def update(force: false)
  return driver_path if up_to_date_binary?(force)

  Chromedriver::Binary.logger.warn(<<-EOF_WARNING) if linux_arm64?

     WARNING: The Linux ARM64 version of ChromeDriver is not officially supported by Google.
     Please use the OS version of ChromeDriver instead.
     For instance on Ubuntu, use the `chromium-driver` package and link it to #{driver_path}.
     `apt-get update && apt-get install chromium-driver`
     `mkdir -p #{install_dir} && ln -s /usr/bin/chromedriver #{driver_path}`
  EOF_WARNING

  version = latest_patch_version_for_build
  zip_filename = "chromedriver_#{platform_id}.zip"
  zip_path = File.join(install_dir, zip_filename)
  download_url = direct_url_from_api(version, driver_filename)

  prepare_install_dir
  log_download_start(version, download_url)

  download_file(download_url, zip_path)
  extract_zip(zip_path, install_dir)
  make_executable(driver_path)
  cleanup_zip(zip_path)

  Chromedriver::Binary.logger.debug "ChromeDriver downloaded and extracted to #{install_dir}"

  driver_path
end