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 “`

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) ⇒ Session

Initialize the session.



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

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

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



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

def capabilities
  @capabilities
end

#delegateObject (readonly)

Returns the value of attribute delegate.



61
62
63
# File 'lib/async/webdriver/session.rb', line 61

def delegate
  @delegate
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

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



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

attr :id

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



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

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
# File 'lib/async/webdriver/session.rb', line 31

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

Instance Method Details

#closeObject

Close the session.



83
84
85
86
87
88
# File 'lib/async/webdriver/session.rb', line 83

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

#current_scopeObject



96
97
98
# File 'lib/async/webdriver/session.rb', line 96

def current_scope
	self
end

#execute(script, *arguments) ⇒ Object

Execute a script in the current document.



104
105
106
# File 'lib/async/webdriver/session.rb', line 104

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.



112
113
114
# File 'lib/async/webdriver/session.rb', line 112

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

#inspectObject



56
57
58
# File 'lib/async/webdriver/session.rb', line 56

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

#request_path(path = nil) ⇒ Object

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



72
73
74
75
76
77
78
# File 'lib/async/webdriver/session.rb', line 72

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

#reset!Object

Reset the session to a clean state.



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/async/webdriver/session.rb', line 128

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



91
92
93
# File 'lib/async/webdriver/session.rb', line 91

def session
	self
end

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



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

attr :capabilities