Class: Async::WebDriver::Session
- Inherits:
-
Object
- Object
- Async::WebDriver::Session
- Includes:
- RequestHelper, Async::WebDriver::Scope::Alerts, Async::WebDriver::Scope::Cookies, Async::WebDriver::Scope::Document, Async::WebDriver::Scope::Elements, Async::WebDriver::Scope::Fields, Async::WebDriver::Scope::Frames, Async::WebDriver::Scope::Navigation, Async::WebDriver::Scope::Printing, Async::WebDriver::Scope::ScreenCapture, Async::WebDriver::Scope::Timeouts
- Defined in:
- lib/async/webdriver/session.rb
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
Constant Summary
Constants included from RequestHelper
RequestHelper::CONTENT_TYPE, RequestHelper::ELEMENT_KEY, RequestHelper::GET_HEADERS, RequestHelper::POST_HEADERS
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
- #The session identifier.(sessionidentifier.) ⇒ Object readonly
- #The underlying HTTP client (or wrapper).(underlyingHTTPclient() ⇒ Object
Class Method Summary collapse
-
.open(endpoint, *arguments, **options) ⇒ Object
Open a new session.
Instance Method Summary collapse
-
#close ⇒ Object
Close the session.
- #current_scope ⇒ Object
-
#execute(script, *arguments) ⇒ Object
Execute a script in the current document.
-
#execute_async(script, *arguments) ⇒ Object
Execute a script in the current document asynchronously.
-
#initialize(delegate, id, capabilities, **options) ⇒ Session
constructor
Initialize the session.
- #inspect ⇒ Object
-
#request_path(path = nil) ⇒ Object
The path used for making requests to the web driver bridge.
-
#reset! ⇒ Object
Reset the session to a clean state.
- #session ⇒ Object
- #The capabilities of the session.=(capabilitiesofthesession. = (value)) ⇒ Object
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
Methods included from Async::WebDriver::Scope::Printing
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, **) @delegate = delegate @id = id @capabilities = capabilities @options = end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
70 71 72 |
# File 'lib/async/webdriver/session.rb', line 70 def capabilities @capabilities end |
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
64 65 66 |
# File 'lib/async/webdriver/session.rb', line 64 def delegate @delegate end |
#id ⇒ Object (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, **) client = self.new( Async::HTTP::Client.open(endpoint), *arguments, ** ) return client unless block_given? begin yield client ensure client.close end end |
Instance Method Details
#close ⇒ Object
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_scope ⇒ Object
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 |
#inspect ⇒ Object
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. # This does not work consistently: # self.execute("localStorage.clear();") # Detach the session instance from the underlying HTTP client: @delegate = nil end |
#session ⇒ Object
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 |