Class: Async::WebDriver::Bridge::Driver
- Inherits:
-
Object
- Object
- Async::WebDriver::Bridge::Driver
show all
- Defined in:
- lib/async/webdriver/bridge/driver.rb
Overview
Represents an instance of a locally running driver (usually with a process group).
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**options) ⇒ Driver
Returns a new instance of Driver.
11
12
13
14
15
|
# File 'lib/async/webdriver/bridge/driver.rb', line 11
def initialize(**options)
@options = options
@count = 0
@closed = false
end
|
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
21
22
23
|
# File 'lib/async/webdriver/bridge/driver.rb', line 21
def count
@count
end
|
#status ⇒ Object
Returns the value of attribute status.
24
25
26
|
# File 'lib/async/webdriver/bridge/driver.rb', line 24
def status
@status
end
|
Instance Method Details
#client ⇒ Object
61
62
63
|
# File 'lib/async/webdriver/bridge/driver.rb', line 61
def client
Client.open(self.endpoint)
end
|
#close ⇒ Object
34
35
36
|
# File 'lib/async/webdriver/bridge/driver.rb', line 34
def close
@closed = true
end
|
#closed? ⇒ Boolean
30
31
32
|
# File 'lib/async/webdriver/bridge/driver.rb', line 30
def closed?
@closed
end
|
#concurrency ⇒ Object
17
18
19
|
# File 'lib/async/webdriver/bridge/driver.rb', line 17
def concurrency
@options.fetch(:concurrency, 128)
end
|
#endpoint ⇒ Object
57
58
59
|
# File 'lib/async/webdriver/bridge/driver.rb', line 57
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.
44
45
46
47
48
49
50
51
|
# File 'lib/async/webdriver/bridge/driver.rb', line 44
def ephemeral_port
address = ::Addrinfo.tcp("localhost", 0)
address.bind do |socket|
return socket.local_address.ip_port
end
end
|
#port ⇒ Object
53
54
55
|
# File 'lib/async/webdriver/bridge/driver.rb', line 53
def port
@port ||= @options.fetch(:port, self.ephemeral_port)
end
|
#reusable? ⇒ Boolean
38
39
40
|
# File 'lib/async/webdriver/bridge/driver.rb', line 38
def reusable?
@options.fetch(:reusable, !@closed)
end
|
#start(retries: 100) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/async/webdriver/bridge/driver.rb', line 67
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
24
|
# File 'lib/async/webdriver/bridge/driver.rb', line 24
attr :status
|
#viable? ⇒ Boolean
26
27
28
|
# File 'lib/async/webdriver/bridge/driver.rb', line 26
def viable?
!@closed
end
|