Class: Async::WebDriver::Client

Inherits:
Object
  • Object
show all
Includes:
RequestHelper
Defined in:
lib/async/webdriver/client.rb

Overview

A client for the WebDriver protocol.

If you have a running web driver server, you can connect to it like so (assuming it is running on port 4444):

“‘ ruby begin client = Async::WebDriver::Client.open(Async::HTTP::Endpoint.parse(“localhost:4444”)) session = client.session ensure client&.close end “`

Constant Summary

Constants included from RequestHelper

RequestHelper::CONTENT_TYPE, RequestHelper::ELEMENT_KEY, RequestHelper::GET_HEADERS, RequestHelper::POST_HEADERS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RequestHelper

#delete, #extract_value, #get, #post, #request_path, #unwrap_object, #unwrap_objects

Constructor Details

#initialize(delegate) ⇒ Client

Initialize the client.



47
48
49
# File 'lib/async/webdriver/client.rb', line 47

def initialize(delegate)
	@delegate = delegate
end

Class Method Details

.open(endpoint, **options) ⇒ Object

Open a new session.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/async/webdriver/client.rb', line 31

def self.open(endpoint, **options)
	client = self.new(
		Async::HTTP::Client.open(endpoint, **options)
	)
	
	return client unless block_given?
	
	begin
		yield client
	ensure
		client.close
	end
end

Instance Method Details

#closeObject

Close the client.



52
53
54
# File 'lib/async/webdriver/client.rb', line 52

def close
	@delegate.close
end

#session(capabilities, &block) ⇒ Object

Request a new session.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/async/webdriver/client.rb', line 60

def session(capabilities, &block)
	reply = post("session", {capabilities: capabilities})
	
	session = Session.new(@delegate, reply["sessionId"], reply["capabilities"])
	
	return session unless block_given?
	
	begin
		yield session
	ensure
		session.close
	end
end