Class: Async::WebDriver::Installer::Chrome::Installation

Inherits:
Object
  • Object
show all
Defined in:
lib/async/webdriver/installer/chrome/installation.rb

Overview

Represents a Chrome for Testing installation on disk, and provides class-level methods for resolving, locating, and downloading installations.

Installations are stored under the cache_path directory, organised as:

cache_path/#platform/#version/ chrome/ ← extracted chrome zip contents chromedriver/ ← extracted chromedriver zip contents

Channel names (e.g. ‘stable`) are stored as symlinks pointing at the specific version directory, so that Installation.find can resolve them without hitting the network. Installation.install always re-checks the API and updates the symlink if the channel has moved on to a newer version.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser_path:, driver_path:, version:, platform:) ⇒ Installation

Returns a new instance of Installation.



93
94
95
96
97
98
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 93

def initialize(browser_path:, driver_path:, version:, platform:)
	@browser_path = browser_path
	@driver_path = driver_path
	@version = version
	@platform = platform
end

Instance Attribute Details

#Absolute path to the Chrome browser executable.(pathtotheChromebrowserexecutable.) ⇒ Object (readonly)



101
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 101

attr :browser_path

#Absolute path to the chromedriver executable.(pathtothechromedriverexecutable.) ⇒ Object (readonly)



104
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 104

attr :driver_path

#browser_pathObject (readonly)

Returns the value of attribute browser_path.



101
102
103
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 101

def browser_path
  @browser_path
end

#driver_pathObject (readonly)

Returns the value of attribute driver_path.



104
105
106
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 104

def driver_path
  @driver_path
end

#Exact installed version, e.g. `"148.0.7778.56"`.(installedversion, e.g.`"148.0.7778.56"`.) ⇒ Object (readonly)



107
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 107

attr :version

#platformObject (readonly)

Returns the value of attribute platform.



110
111
112
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 110

def platform
  @platform
end

#Platform, e.g. `"mac-arm64"`.Object (readonly)



110
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 110

attr :platform

#versionObject (readonly)

Returns the value of attribute version.



107
108
109
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 107

def version
  @version
end

Class Method Details

.find(version, platform, cache_path:) ⇒ Object

Find an already-installed version or channel, without hitting the network.

For channel names (‘:stable`, `“stable”`, etc.), resolves the local symlink. For exact versions, checks the installation directory directly.



81
82
83
84
85
86
87
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 81

def self.find(version, platform, cache_path:)
	if channel = channel_name(version)
		find_channel(channel, platform, cache_path: cache_path)
	else
		find_version(version, platform, cache_path: cache_path)
	end
end

.install(version, cache_path:) ⇒ Object

Look up an existing installation, or download and install a fresh one.

For channel specifiers (‘:stable`, `:beta`, etc.), always hits the Chrome for Testing API to resolve the current version, downloads if needed, and updates the channel symlink. For exact versions, checks the local cache only.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/async/webdriver/installer/chrome/installation.rb', line 39

def self.install(version, cache_path:)
	platform = Platform.current
	release = Releases.resolve(version, platform)
	
	unless installation = find(release[:version], platform, cache_path: cache_path)
		Console.info(self, "Installing Chrome for Testing #{release[:version]}...", platform: platform)
		
		dir = installation_dir(release[:version], platform, cache_path: cache_path)
		FileUtils.mkdir_p(dir)
		
		begin
			download_and_extract(release[:chrome_url], File.join(dir, "chrome"))
			download_and_extract(release[:chromedriver_url], File.join(dir, "chromedriver"))
			
			installation = find(release[:version], platform, cache_path: cache_path) or
				raise "Installation failed: binaries not found after extraction"
			
			Console.info(self, "Installed Chrome for Testing #{release[:version]}.", platform: platform)
		rescue
			FileUtils.rm_rf(dir)
			raise
		end
	end
	
	# Update the channel symlink so subsequent find(:stable) calls
	# resolve locally without a network request.
	if channel = channel_name(version)
		update_channel_symlink(channel, release[:version], platform, cache_path: cache_path)
	end
	
	return installation
end