Class: Async::WebDriver::Bridge::Chrome

Inherits:
Generic
  • Object
show all
Defined in:
lib/async/webdriver/bridge/chrome.rb

Overview

A bridge to the Chrome browser using ‘chromedriver`.

“‘ ruby begin bridge = Async::WebDriver::Bridge::Chrome.start client = Async::WebDriver::Client.open(bridge.endpoint) ensure bridge&.close end “`

Defined Under Namespace

Classes: Driver

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#headless?, #initialize, #supported?

Constructor Details

This class inherits a constructor from Async::WebDriver::Bridge::Generic

Class Method Details

.for(version = :stable, cache_path: Installer.cache_path("chrome"), **options) ⇒ Object

Ensure the given version of Chrome for Testing is installed and return a fully configured Async::WebDriver::Bridge::Chrome bridge pointing at it.

Delegates to Installer::Chrome.install for version resolution and download, then wraps the result in a configured bridge.



91
92
93
94
95
# File 'lib/async/webdriver/bridge/chrome.rb', line 91

def self.for(version = :stable, cache_path: Installer.cache_path("chrome"), **options)
	require_relative "../installer/chrome"
	installation = Installer::Chrome.find(version, cache_path: cache_path) || Installer::Chrome.install(version, cache_path: cache_path)
	new(driver_path: installation.driver_path, browser_path: installation.browser_path, **options)
end

Instance Method Details

#browser_pathObject

The path to the Chrome browser executable. If ‘nil`, ChromeDriver uses its own discovery.



99
100
101
# File 'lib/async/webdriver/bridge/chrome.rb', line 99

def browser_path
	@options[:browser_path]
end

#default_capabilities(headless: self.headless?, browser_path: self.browser_path) ⇒ Object

The default capabilities for the Chrome browser which need to be provided when requesting a new session.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/async/webdriver/bridge/chrome.rb', line 107

def default_capabilities(headless: self.headless?, browser_path: self.browser_path)
	chrome_options = {
		args: [headless ? "--headless=new" : nil].compact,
	}
	
	chrome_options[:binary] = browser_path if browser_path
	
	{
		alwaysMatch: {
			browserName: "chrome",
			"goog:chromeOptions": chrome_options,
			webSocketUrl: true,
		},
	}
end

#driver_pathObject



25
26
27
# File 'lib/async/webdriver/bridge/chrome.rb', line 25

def driver_path
	@options.fetch(:driver_path, "chromedriver")
end

#start(**options) ⇒ Object

Start the driver, forwarding the bridge’s own options to the driver process so that a custom ‘:driver_path` reaches the chromedriver executable.



75
76
77
# File 'lib/async/webdriver/bridge/chrome.rb', line 75

def start(**options)
	Driver.new(**@options, **options).tap(&:start)
end

#versionObject



30
31
32
33
34
35
36
# File 'lib/async/webdriver/bridge/chrome.rb', line 30

def version
	::IO.popen([self.driver_path, "--version"]) do |io|
		return io.read
	end
rescue Errno::ENOENT
	return nil
end