Class: Async::WebDriver::Session

Overview

A session represents a single browser session, potentially with multiple windows. It is the primary interface for interacting with a browser.

“‘ ruby begin bridge = Async::WebDriver::Bridge::Pool.start(Async::WebDriver::Bridge::Chrome.new) session = bridge.session session.navigate_to(“google.com”) # … ensure bridge&.close end “`

Direct Known Subclasses

Bridge::Pool::CachedWrapper

Constant Summary

Constants included from RequestHelper

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Async::WebDriver::Scope::Timeouts

#implicit_wait_timeout, #implicit_wait_timeout=, #page_load_timeout, #page_load_timeout=, #script_timeout, #script_timeout=, #timeouts

Methods included from Async::WebDriver::Scope::ScreenCapture

#screenshot

Methods included from Async::WebDriver::Scope::Printing

#print

Methods included from Async::WebDriver::Scope::Navigation

#current_path, #current_url, #navigate_back, #navigate_forward, #navigate_to, #refresh

Methods included from Async::WebDriver::Scope::Frames

#switch_to_frame, #switch_to_parent_frame

Methods included from Async::WebDriver::Scope::Fields

#check, #click_button, #fill_in, #find_field

Methods included from Async::WebDriver::Scope::Elements

#children, #find_element, #find_element_by_css, #find_element_by_link_text, #find_element_by_partial_link_text, #find_element_by_tag_name, #find_element_by_xpath, #find_elements, #find_elements_by_css, #find_elements_by_link_text, #find_elements_by_partial_link_text, #find_elements_by_tag_name, #find_elements_by_xpath

Methods included from Async::WebDriver::Scope::Document

#document_source, #document_title

Methods included from Async::WebDriver::Scope::Cookies

#add_cookie, #cookie, #cookies, #delete_all_cookies, #delete_cookie

Methods included from Async::WebDriver::Scope::Alerts

#accept_alert, #alert_text, #dismiss_alert, #set_alert_text

Methods included from RequestHelper

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

Constructor Details

#initialize(delegate, id, capabilities, **options) ⇒ Session

Initialize the session.



51
52
53
54
55
56
57
# File 'lib/async/webdriver/session.rb', line 51

def initialize(delegate, id, capabilities, **options)
	@delegate = delegate
	@id = id
	@capabilities = capabilities
	
	@options = options
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



70
71
72
# File 'lib/async/webdriver/session.rb', line 70

def capabilities
  @capabilities
end

#delegateObject (readonly)

Returns the value of attribute delegate.



64
65
66
# File 'lib/async/webdriver/session.rb', line 64

def delegate
  @delegate
end

#idObject (readonly)

Returns the value of attribute id.



67
68
69
# File 'lib/async/webdriver/session.rb', line 67

def id
  @id
end

#The session identifier.(sessionidentifier.) ⇒ Object (readonly)



67
# File 'lib/async/webdriver/session.rb', line 67

attr :id

#The underlying HTTP client (or wrapper).(underlyingHTTPclient() ⇒ Object



64
# File 'lib/async/webdriver/session.rb', line 64

attr :delegate

Class Method Details

.open(endpoint, *arguments, **options) ⇒ Object

Open a new session.



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

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

Instance Method Details

#closeObject

Close the session.



86
87
88
89
90
91
# File 'lib/async/webdriver/session.rb', line 86

def close
	if @delegate
		self.delete
		@delegate = nil
	end
end

#current_scopeObject



99
100
101
# File 'lib/async/webdriver/session.rb', line 99

def current_scope
	self
end

#execute(script, *arguments) ⇒ Object

Execute a script in the current document.



107
108
109
# File 'lib/async/webdriver/session.rb', line 107

def execute(script, *arguments)
	post("execute/sync", {script: script, args: arguments})
end

#execute_async(script, *arguments) ⇒ Object

Execute a script in the current document asynchronously.



115
116
117
# File 'lib/async/webdriver/session.rb', line 115

def execute_async(script, *arguments)
	post("execute/async", {script: script, args: arguments})
end

#inspectObject



59
60
61
# File 'lib/async/webdriver/session.rb', line 59

def inspect
	"\#<#{self.class} id=#{@id.inspect}>"
end

#request_path(path = nil) ⇒ Object

The path used for making requests to the web driver bridge.



75
76
77
78
79
80
81
# File 'lib/async/webdriver/session.rb', line 75

def request_path(path = nil)
	if path
		"/session/#{@id}/#{path}"
	else
		"/session/#{@id}"
	end
end

#reset!Object

Reset the session to a clean state.



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/async/webdriver/session.rb', line 131

def reset!
	# Go to a blank page (in theory this should also invalidate any Element instances):
	self.navigate_to("about:blank")
	
	# Clear cookies and local storage:
	self.delete_all_cookies
	
	# This does not work consistently:
	# self.execute("localStorage.clear();")
	
	# Detach the session instance from the underlying HTTP client:
	@delegate = nil
end

#sessionObject



94
95
96
# File 'lib/async/webdriver/session.rb', line 94

def session
	self
end

#The capabilities of the session.=(capabilitiesofthesession. = (value)) ⇒ Object



70
# File 'lib/async/webdriver/session.rb', line 70

attr :capabilities