class Marionette::Session

Included Modules

Defined in:

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.


Instance Method Detail

def accept_alert #

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


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.


def active_element #

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


def alert_text #

Returns the text of the active alert dialog.


def alert_value=(value) #

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


def all_cookies #

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


def back #

Go back in history.


def capabilities : Hash(String, JSON::Any) #

def clear_actions #

Clears actions that are already stored on the remote end.


def close #

Close the current session.


def close_current_window #

Close the current Window.


def close_window(window : Window) #

Close the given Window.


def context #

Get the current browser context.

NOTE Available for Firefox only.


def context=(context : String) #

Set the current browser context.

NOTE Available for Firefox only.


def current_url #

Get the URL of the current page.


def current_window #

Return the current Window.


def debug #

Enable and attach the Safari debugger.

NOTE Available for Chrome/Chromium only.


def delete_all_cookies #

Delete all collected cookies


def delete_cookie(name : String) #

Delete the cookie with the specified name.


def dismiss_alert #

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


def driver : WebDriver #

def execute(command, params = {} of String => String) #

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


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.


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.


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.


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.


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.


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.


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.


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.


def find_elements(selector, strategy : LocationStrategy = :css) #

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


def forward #

Go forward in history.


def full_page_screenshot #

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

NOTE Available for Firefox only.


def get_cookie(cookie : HTTP::Cookie) #

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


def get_cookie(name : String) #

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


def id : String #

def implicit_wait(time : Time::Span) #

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


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.


def issue_message #

Get the issue message for the current cast context.

NOTE Available for Chrome/Chromium only.


def launch_app(app_id : String) #

Launch a Chrome app using its #id.

NOTE Available for Chrome/Chromium only.


def leave_frame #

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


def local? #

Returns true if this is a local session.


def log(log_type : String) #

def log_types #

def navigate(to url : String | URI) #

Go to the given URL.


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.


def network_conditions=(conditions : NetworkConditions) #

Set the network conditions.

NOTE Available for Chrome/Chromium only.


def new_window(type : Window::Type = :window) #

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


def orientation #

Get the orientation of the current driver.

NOTE only available on non-W3C compatible drivers.


def orientation=(origination : Orientation) #

Set the orientation of the current driver.

NOTE only available on non-W3C compatible drivers.


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.


def page_source #

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


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.


def permissions #

Get the currently set Safari permisisons.

NOTE Available for Safari only.


def permissions=(perms : Hash(String, Bool)) #

Set Safari permissions.

NOTE Available for Chrome/Chromium only.


def refresh #

Refresh the current page.


def remote? #

Returns true if this is a remote session.


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.


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.


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.


def service : Service? #

def service=(service : Service?) #

def service? : Service | Nil? #

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

Set a single Safari permission.

NOTE Available for Chrome/Chromium only.


def sink=(sink_name : String) #

Set the current casting sink.

NOTE Available for Chrome/Chromium only.


def sinks #

Get a list of sinks for casting.

NOTE Available for Chrome/Chromium only.


def start_tab_mirroring(sink_name : String) #

Start mirroring the current tab using the given sink.

NOTE Available for Chrome/Chromium only.


def status #

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


def stop #

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


def stop_casting(sink_name : String) #

Stop casting to the current sink.

NOTE Available for Chrome/Chromium only.


def switch_to_frame(frame : Element) #

Switch the context to the given frame or iframe element.


def switch_to_parent_frame #

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


def switch_to_window(handle : String) #

Switch to a given Window using its handle.


def switch_to_window(window : Window) #

Switch to a given Window.


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.


def take_screenshot #

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


def title #

Return the title of the current page.


def type : Type #

def uninstall_addon(id : String) #

Uninstall an addon using its #id.

NOTE Available for Firefox only.


def w3c? : Bool #

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.


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.


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.


def windows #

Return an array of all opened Windows.