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::Window

#fullscreen_window, #maximize_window, #minimize_window, #resize_window, #set_window_rect, #window_rect

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, #wait_for_navigation

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.



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

def capabilities
  @capabilities
end

#delegateObject (readonly)

Returns the value of attribute delegate.



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

def delegate
  @delegate
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

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



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

attr :id

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



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

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.



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

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

#current_scopeObject



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

def current_scope
	self
end

#execute(script, *arguments) ⇒ Object

Execute a script in the current document.



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

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.



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

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

#inspectObject



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

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

#request_path(path = nil) ⇒ Object

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



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

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

#reset!Object

Reset the session to a clean state.



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

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



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

def session
	self
end

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



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

attr :capabilities