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 “`

Instance Attribute Summary

Attributes inherited from Generic

#The status of the driver after a connection has been established., #status

Instance Method Summary collapse

Methods inherited from Generic

#endpoint, #port, start, #supported?

Constructor Details

#initialize(path: "chromedriver") ⇒ Chrome

Create a new bridge to Chrome.



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

def initialize(path: "chromedriver")
  super()
  
  @path = path
  @process = nil
end

Instance Method Details

#argumentsObject



42
43
44
45
46
# File 'lib/async/webdriver/bridge/chrome.rb', line 42

def arguments
  [
    "--port=#{self.port}",
  ].compact
end

#closeObject

Close the driver.



56
57
58
59
60
61
62
63
# File 'lib/async/webdriver/bridge/chrome.rb', line 56

def close
  super
  
  if @process
    @process.close
    @process = nil
  end
end

#default_capabilities(headless: true) ⇒ Object

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



68
69
70
71
72
73
74
75
76
77
# File 'lib/async/webdriver/bridge/chrome.rb', line 68

def default_capabilities(headless: true)
  {
    alwaysMatch: {
      browserName: "chrome",
      "goog:chromeOptions": {
        args: [headless ? "--headless" : nil].compact,
      }
    },
  }
end

#startObject

Start the driver.



49
50
51
52
53
# File 'lib/async/webdriver/bridge/chrome.rb', line 49

def start
  @process ||= ProcessGroup.spawn(@path, *arguments)
  
  super
end

#versionObject



33
34
35
36
37
38
39
# File 'lib/async/webdriver/bridge/chrome.rb', line 33

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