class Chrome
A bridge to the Chrome browser using chromedriver.
begin
bridge = Async::WebDriver::Bridge::Chrome.start
client = Async::WebDriver::Client.open(bridge.endpoint)
ensure
bridge&.close
end
Nested
Definitions
def driver_path
Signature
-
returns
String The path to the
chromedriverexecutable.
Implementation
def driver_path
@options.fetch(:driver_path, "chromedriver")
end
def version
Signature
-
returns
String The version of the
chromedriverexecutable.
Implementation
def version
::IO.popen([self.driver_path, "--version"]) do |io|
return io.read
end
rescue Errno::ENOENT
return nil
end
def start(**options)
Start the driver, forwarding the bridge's own options to the driver process
so that a custom :driver_path reaches the chromedriver executable.
Implementation
def start(**options)
Driver.new(**@options, **options).tap(&:start)
end
def self.for(version = :stable, cache_path: Installer.cache_path("chrome"), **options)
Ensure the given version of Chrome for Testing is installed and return a
fully configured class Async::WebDriver::Bridge::Chrome bridge pointing at it.
Delegates to Async::WebDriver::Installer::Chrome.install for version
resolution and download, then wraps the result in a configured bridge.
Signature
-
parameter
versionSymbol | String :stable,:beta,:dev,:canary, a major version string like"148", or an exact version like"148.0.7778.56".-
parameter
cache_pathString Root of the cache directory. Default:
~/.cache/async-webdriver.rb(XDG-compliant).-
parameter
optionsHash Additional options forwarded to
.new(e.g.headless: false).-
returns
Chrome A configured bridge.
Implementation
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
def browser_path
The path to the Chrome browser executable. If nil, ChromeDriver uses its own discovery.
Signature
-
returns
String | Nil
Implementation
def browser_path
@options[:browser_path]
end
def default_capabilities(headless: self.headless?, browser_path: self.browser_path)
The default capabilities for the Chrome browser which need to be provided when requesting a new session.
Signature
-
parameter
headlessBoolean Whether to run the browser in headless mode.
-
parameter
browser_pathString | Nil Path to the Chrome browser executable. Overrides ChromeDriver's default discovery, useful for pointing at a specific Chrome for Testing installation.
-
returns
Hash The default capabilities for the Chrome browser.
Implementation
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