Async::WebDriver SourceAsyncWebDriverBridgeDriver

class Driver

Represents an instance of a locally running driver (usually with a process group).

Definitions

attr :status

Signature

attribute Hash

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

def ephemeral_port

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

Signature

returns Integer

An ephemeral port number.

Implementation

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

def start(retries: 100)

Start the driver.

Signature

parameter retries Integer

The number of times to retry before giving up.

Implementation

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