Class: Async::WebDriver::Bridge::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/async/webdriver/bridge/generic.rb

Overview

Generic W3C WebDriver implementation.

Direct Known Subclasses

Chrome, Firefox

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port: nil) ⇒ Generic

Initialize the driver.



24
25
26
27
# File 'lib/async/webdriver/bridge/generic.rb', line 24

def initialize(port: nil)
	@port = port
	@status = nil
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



30
31
32
# File 'lib/async/webdriver/bridge/generic.rb', line 30

def status
  @status
end

#The status of the driver after a connection has been established.(statusofthedriverafteraconnectionhasbeenestablished.) ⇒ Object (readonly)



30
# File 'lib/async/webdriver/bridge/generic.rb', line 30

attr :status

Class Method Details

.start(**options) ⇒ Object

Start the driver and return a new instance.



16
17
18
19
20
# File 'lib/async/webdriver/bridge/generic.rb', line 16

def self.start(**options)
	self.new(**options).tap do |bridge|
		bridge.start
	end
end

Instance Method Details

#closeObject

Close the driver and any associated resources.



67
68
# File 'lib/async/webdriver/bridge/generic.rb', line 67

def close
end

#endpointObject



85
86
87
# File 'lib/async/webdriver/bridge/generic.rb', line 85

def endpoint
	Async::HTTP::Endpoint.parse("http://localhost:#{port}")
end

#portObject

Generate a port number for the driver to listen on if it was not specified.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/async/webdriver/bridge/generic.rb', line 72

def port
	unless @port
		address = ::Addrinfo.tcp("localhost", 0)
		address.bind do |socket|
			# We assume that it's unlikely the port will be reused any time soon...
			@port = socket.local_address.ip_port
		end
	end
	
	return @port
end

#start(retries: 100) ⇒ Object

Start the driver.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/async/webdriver/bridge/generic.rb', line 44

def start(retries: 100)
	Console.debug(self, "Waiting for driver to start...")
	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.001 * count)
				Console.debug(self, "Driver not ready, retrying...")
				retry
			else
				raise
			end
		end
	end
end

#supported?Boolean

Returns:



38
39
40
# File 'lib/async/webdriver/bridge/generic.rb', line 38

def supported?
	version != nil
end

#versionObject



33
34
35
# File 'lib/async/webdriver/bridge/generic.rb', line 33

def version
	nil
end