Class: Async::WebDriver::Bridge::Chrome
- 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
-
.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 Chrome bridge pointing at it.
Instance Method Summary collapse
-
#browser_path ⇒ Object
The path to the Chrome browser executable.
-
#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.
- #driver_path ⇒ Object
-
#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.
- #version ⇒ Object
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.
90 91 92 93 94 |
# File 'lib/async/webdriver/bridge/chrome.rb', line 90 def self.for(version = :stable, cache_path: Installer.cache_path("chrome"), **) 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, **) end |
Instance Method Details
#browser_path ⇒ Object
The path to the Chrome browser executable. If ‘nil`, ChromeDriver uses its own discovery.
98 99 100 |
# File 'lib/async/webdriver/bridge/chrome.rb', line 98 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.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/async/webdriver/bridge/chrome.rb', line 106 def default_capabilities(headless: self.headless?, browser_path: self.browser_path) = { args: [headless ? "--headless=new" : nil].compact, } [:binary] = browser_path if browser_path { alwaysMatch: { browserName: "chrome", "goog:chromeOptions": , webSocketUrl: true, }, } end |
#driver_path ⇒ Object
24 25 26 |
# File 'lib/async/webdriver/bridge/chrome.rb', line 24 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.
74 75 76 |
# File 'lib/async/webdriver/bridge/chrome.rb', line 74 def start(**) Driver.new(**@options, **).tap(&:start) end |
#version ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/async/webdriver/bridge/chrome.rb', line 29 def version ::IO.popen([self.driver_path, "--version"]) do |io| return io.read end rescue Errno::ENOENT return nil end |