Class: Async::WebDriver::Bridge::Driver
- Inherits:
-
Object
- Object
- Async::WebDriver::Bridge::Driver
- Defined in:
- lib/async/webdriver/bridge/driver.rb
Overview
Represents an instance of a locally running driver (usually with a process group).
Direct Known Subclasses
Chrome::Driver, Firefox::Driver, ProcessDriver, Safari::Driver
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #client ⇒ Object
-
#close ⇒ Object
Mark the driver as closed.
- #closed? ⇒ Boolean
- #concurrency ⇒ Object
- #endpoint ⇒ Object
-
#ephemeral_port ⇒ Object
Generate a port number for the driver to listen on if it was not specified.
-
#initialize(**options) ⇒ Driver
constructor
Initialize a driver wrapper.
- #port ⇒ Object
- #reusable? ⇒ Boolean
-
#start(retries: 100) ⇒ Object
Start the driver.
- #The status of the driver after a connection has been established.=(statusofthedriverafteraconnectionhasbeenestablished. = (value)) ⇒ Object
- #viable? ⇒ Boolean
Constructor Details
#initialize(**options) ⇒ Driver
Initialize a driver wrapper.
13 14 15 16 17 |
# File 'lib/async/webdriver/bridge/driver.rb', line 13 def initialize(**) @options = @count = 0 @closed = false end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
24 25 26 |
# File 'lib/async/webdriver/bridge/driver.rb', line 24 def count @count end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
27 28 29 |
# File 'lib/async/webdriver/bridge/driver.rb', line 27 def status @status end |
Instance Method Details
#client ⇒ Object
71 72 73 |
# File 'lib/async/webdriver/bridge/driver.rb', line 71 def client Client.open(self.endpoint) end |
#close ⇒ Object
Mark the driver as closed.
40 41 42 |
# File 'lib/async/webdriver/bridge/driver.rb', line 40 def close @closed = true end |
#closed? ⇒ Boolean
35 36 37 |
# File 'lib/async/webdriver/bridge/driver.rb', line 35 def closed? @closed end |
#concurrency ⇒ Object
20 21 22 |
# File 'lib/async/webdriver/bridge/driver.rb', line 20 def concurrency @options.fetch(:concurrency, 128) end |
#endpoint ⇒ Object
66 67 68 |
# File 'lib/async/webdriver/bridge/driver.rb', line 66 def endpoint Async::HTTP::Endpoint.parse("http://localhost", port: self.port) end |
#ephemeral_port ⇒ Object
Generate a port number for the driver to listen on if it was not specified.
51 52 53 54 55 56 57 58 |
# File 'lib/async/webdriver/bridge/driver.rb', line 51 def ephemeral_port address = ::Addrinfo.tcp("localhost", 0) address.bind do |socket| # We assume that it's unlikely the port will be reused any time soon... return socket.local_address.ip_port end end |
#port ⇒ Object
61 62 63 |
# File 'lib/async/webdriver/bridge/driver.rb', line 61 def port @port ||= @options.fetch(:port, self.ephemeral_port) end |
#reusable? ⇒ Boolean
45 46 47 |
# File 'lib/async/webdriver/bridge/driver.rb', line 45 def reusable? @options.fetch(:reusable, !@closed) end |
#start(retries: 100) ⇒ Object
Start the driver.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/async/webdriver/bridge/driver.rb', line 77 def start(retries: 100) endpoint = self.endpoint Console.debug(self, "Waiting for driver to start...", endpoint: endpoint) count = 0 Async::HTTP::Client.open(endpoint) do |client| begin response = client.get("/status") @status = JSON.parse(response.read)["value"] Console.debug(self, "Successfully connected to driver.", status: @status) rescue Errno::ECONNREFUSED if count < retries count += 1 sleep(0.01 * count) Console.debug(self, "Driver not ready, retrying...") retry else raise end end end end |
#The status of the driver after a connection has been established.=(statusofthedriverafteraconnectionhasbeenestablished. = (value)) ⇒ Object
27 |
# File 'lib/async/webdriver/bridge/driver.rb', line 27 attr :status |
#viable? ⇒ Boolean
30 31 32 |
# File 'lib/async/webdriver/bridge/driver.rb', line 30 def viable? !@closed end |