class Marionette::Session

Included Modules

Defined in:

marionette/session.cr

Constant Summary

Log = ::Log.for("marionette.session")

Class Method Summary

Instance Method Summary

Class Method Detail

def self.start(driver : WebDriver, type : Type, capabilities = {} of String => String, service = nil) #

Start a new Session using the given #driver and #type. You can pass in any #capabilities you want here, and they'll be merged with the browser's desired capabilities.


[View source]

Instance Method Detail

def accept_alert #

Accept an active alert. For confirmation boxes this is the same as clicking the "Ok" button.


[View source]
def actions(&) #

Creates a new ActionBuilder instance and passes it to the block. Given actions are not performed on block exit, so you will need to call ActionBuilder#perform eventually.


[View source]
def active_element #

Returns the element with focus, or the page Body if nothing has focus.


[View source]
def alert_text #

Returns the text of the active alert dialog.


[View source]
def alert_value=(value) #

Sets the text box content for alert dialogs that have one.


[View source]
def all_cookies #

Return all cookies collected so far as an Array(HTTP::Cookie).


[View source]
def back #

Go back in history.


[View source]
def capabilities : Hash(String, JSON::Any) #

[View source]
def clear_actions #

Clears actions that are already stored on the remote end.


[View source]
def close #

Close the current session.


[View source]
def close_current_window #

Close the current Window.


[View source]
def close_window(window : Window) #

Close the given Window.


[View source]
def context #

Get the current browser context.

NOTE Available for Firefox only.


[View source]
def context=(context : String) #

Set the current browser context.

NOTE Available for Firefox only.


[View source]
def current_url #

Get the URL of the current page.


[View source]
def current_window #

Return the current Window.


[View source]
def debug #

Enable and attach the Safari debugger.

NOTE Available for Chrome/Chromium only.


[View source]
def delete_all_cookies #

Delete all collected cookies


[View source]
def delete_cookie(name : String) #

Delete the cookie with the specified name.


[View source]
def dismiss_alert #

Dismiss an active alert. For confirmation boxes this is the same as clicking the "Cancel" button.


[View source]
def driver : WebDriver #

[View source]
def execute(command, params = {} of String => String) #

Execute an arbitrary command with the given permissions. See Commands for all available commands.


[View source]
def execute_cdp_command(cmd : String, args = {} of String => String) #

Execute a CDP (Chrome DevTools Protocol) command. See the API documentation for information on acceptable commands.

NOTE Available for Chrome/Chromium only.


[View source]
def execute_script(script, args = nil) #

Execute arbitrary JavaScript in the context of the given document. Any args to be passed into the script should be provided as an array.

For now the result is returned as raw JSON.


[View source]
def execute_script_async(script, args = nil) #

Execute arbitrary JavaScript in the context of the given document. Any args to be passed into the script should be provided as an array.

This is an async process and does not return a result.


[View source]
def find_element(selector, strategy : LocationStrategy = :css) #

Find an element using the given selector. The strategy can be any LocationStrategy. Default is LocationStrategy::Css. Returns nil if no element with the given selector was found.


[View source]
def find_element!(selector, strategy : LocationStrategy = :css) #

Find an element using the given selector. The strategy can be any LocationStrategy. Default is LocationStrategy::Css. Raises an exception if no element with the given selector was found.


[View source]
def find_element_child(element, selector, strategy : LocationStrategy = :css) #

Find a child of the given element. Returns nil if no element with the given selector was found.


[View source]
def find_element_child!(element, selector, strategy : LocationStrategy = :css) #

Find a child of the given element. Raises an exception if no element with the given selector was found.


[View source]
def find_element_children(element, selector, strategy : LocationStrategy = :css) #

Find multiple children of the given element with the given selector and return them as an array.


[View source]
def find_elements(selector, strategy : LocationStrategy = :css) #

Find multiple elements with the given selector and return them as an array.


[View source]
def forward #

Go forward in history.


[View source]
def full_page_screenshot #

Takes a full screen screenshot and return it as a Base64 encoded PNG string.

NOTE Available for Firefox only.


[View source]
def get_cookie(cookie : HTTP::Cookie) #

Get a browser cookie using an HTTP::Cookie instance.


[View source]
def get_cookie(name : String) #

Get the cookie with the specified name. Returns nil if no cookie was found.


[View source]
def id : String #

[View source]
def implicit_wait(time : Time::Span) #

Add an implicit wait that will occur before calls are made in a newly opened page.


[View source]
def install_addon(path : String, temporary = false) #

Install an addon from the given path. If temporary is set to true this addon will only be installed for the current session.

NOTE Available for Firefox only.


[View source]
def issue_message #

Get the issue message for the current cast context.

NOTE Available for Chrome/Chromium only.


[View source]
def launch_app(app_id : String) #

Launch a Chrome app using its #id.

NOTE Available for Chrome/Chromium only.


[View source]
def leave_frame #

Leave the current frame context and return to the default context.


[View source]
def local? #

Returns true if this is a local session.


[View source]
def log(log_type : String) #

[View source]
def log_types #

[View source]
def navigate(to url : String | URI) #

Go to the given URL.


[View source]
def network_conditions #

Return the set network conditions as a NetworkConditions object. This will raise if network conditions haven't been set already.

NOTE Available for Chrome/Chromium only.


[View source]
def network_conditions=(conditions : NetworkConditions) #

Set the network conditions.

NOTE Available for Chrome/Chromium only.


[View source]
def new_window(type : Window::Type = :window) #

Create a new Window. The window will not be switched to automatically.


[View source]
def orientation #

Get the orientation of the current driver.

NOTE only available on non-W3C compatible drivers.


[View source]
def orientation=(origination : Orientation) #

Set the orientation of the current driver.

NOTE only available on non-W3C compatible drivers.


[View source]
def page_load_timeout(time : Time::Span) #

Add a timeout for page loads. Pages that take longer than the given amount of time to load will throw an Error::TimeoutError.


[View source]
def page_source #

Return the source of the given page. For most pages this will be HTML markup.


[View source]
def perform_actions(debug_mouse_move = false, &) #

Creates a new ActionBuilder instance and passes it to the block. Actions are performed immediately upon block exit.

Set debug_mouse_move to true to get visual indicators on screen when the mouse changes location.


[View source]
def permissions #

Get the currently set Safari permisisons.

NOTE Available for Safari only.


[View source]
def permissions=(perms : Hash(String, Bool)) #

Set Safari permissions.

NOTE Available for Chrome/Chromium only.


[View source]
def refresh #

Refresh the current page.


[View source]
def remote? #

Returns true if this is a remote session.


[View source]
def save_full_page_screenshot(path : String) #

Take a fullscreen screenshot and save it to the given path as a PNG image.

NOTE Available for Firefox only.


[View source]
def save_screenshot(path, element_id = nil, scroll = true) #

Take a screenshot and save it as a PNG at the given path. If scroll is set to true the element will be scrolled to before taking the screenshot.


[View source]
def script_timeout(time : Time::Span) #

Add a timeout for script execution. Scripts that take longer than the given amount of time to execute will throw as Error::TimeoutError.


[View source]
def service : Service | Nil #

def service=(service : Service | Nil) #

[View source]
def service? : Service | Nil | Nil #

def set_permission(key : String, value : Bool) #

Set a single Safari permission.

NOTE Available for Chrome/Chromium only.


[View source]
def sink=(sink_name : String) #

Set the current casting sink.

NOTE Available for Chrome/Chromium only.


[View source]
def sinks #

Get a list of sinks for casting.

NOTE Available for Chrome/Chromium only.


[View source]
def start_tab_mirroring(sink_name : String) #

Start mirroring the current tab using the given sink.

NOTE Available for Chrome/Chromium only.


[View source]
def status #

Return the status of the current driver as a JSON object.


[View source]
def stop #

Stops the current session by closing it and then closing the WebDriver process.


[View source]
def stop_casting(sink_name : String) #

Stop casting to the current sink.

NOTE Available for Chrome/Chromium only.


[View source]
def switch_to_frame(frame : Element) #

Switch the context to the given frame or iframe element.


[View source]
def switch_to_parent_frame #

Switch the context to the parent of the given frame or iframe element.


[View source]
def switch_to_window(handle : String) #

Switch to a given Window using its handle.


[View source]
def switch_to_window(window : Window) #

Switch to a given Window.


[View source]
def take_screenshot(element_id : String, scroll = true) #

Take a screenshot of the element with the given element_id. If scroll is set to true the element will be scrolled to before taking the screenshot.

The PNG data is returned as a Base64 encoded string.


[View source]
def take_screenshot #

Take a screenshot of the current visible portion of the screen. The PNG is returned as a Base64 encoded string.


[View source]
def title #

Return the title of the current page.


[View source]
def type : Type #

[View source]
def uninstall_addon(id : String) #

Uninstall an addon using its #id.

NOTE Available for Firefox only.


[View source]
def w3c? : Bool #

[View source]
def wait_for_element(selector : String, strategy : LocationStrategy = :css, timeout = 3.seconds, poll_time = 50.milliseconds, &) #

Wait the given amount of time for an element to be available. If no element is found an exception will be raised.


[View source]
def wait_for_element(selector : String, strategy : LocationStrategy = :css, timeout = 3.seconds, poll_time = 50.milliseconds) #

Wait the given amount of time for an element to be available. If no element is found an exception will be raised.


[View source]
def wait_for_elements(selector : String, strategy : LocationStrategy = :css, timeout = 3.seconds, poll_time = 50.milliseconds, &) #

Wait the given amount of time for elements to be available. If no element is found an exception will be raised.


[View source]
def windows #

Return an array of all opened Windows.


[View source]