|
|
| Line 1: |
Line 1: |
| When writing Marionette tests in Python, the following API's are available. These are all available in the self.marionette object which is available to all Marionette tests. Most of these API's are analogs to Selenium methods WebDriver methods.
| | This page has been moved to [https://developer.mozilla.org/en/Marionette/Marionette mdn] |
| | |
| All of these calls should be supported by end of Q1/2012 for the B2G and desktop Firefox environments.
| |
| | |
| === Configuration ===
| |
| | |
| * {{done|'''set_script_timeout(ms)'''}}: sets the timeout for asynchronous scripts
| |
| * {{done|'''set_search_timeout(ms)'''}}: sets the maximum time Marionette will wait while searching for a DOM element using any of the find_ methods
| |
| | |
| === Context Management ===
| |
| | |
| * {{done|'''set_context(context)'''}}: sets the context in which future commands will be executed; <code>context</code> is either "chrome" or "content"
| |
| * {{done|'''get_window()'''}}: returns an id representing the current window
| |
| * {{done'''get_windows()'''}}: returns a list of all available windows
| |
| * {{done|'''switch_to_window(window)'''}}: sets the active window; all future commands will be targeted here. <code>window</code> is one of the id's returned by <code>get_windows()</code>. Note: WebDriver is not clear on the definition of 'window'. Selenium uses the 'navigator:browser' windows, so this will not work as expected in B2G, where we don't use navigator:browser within Gaia. Fortunately, there is only one window in gaia, so this should not be a problem.
| |
| * {{done|'''switch_to_frame(id)'''}}: sets the active frame; all future commands will be targeted here. <code>id</code> is either the id of an iframe, an HTMLElement (see below) representing an iframe, or None to target the default top-level frame.
| |
| | |
| === Navigation ===
| |
| | |
| Not all are supported in B2G. get_url works as expected.
| |
| | |
| * {{done|'''get_url()'''}}: returns the current url
| |
| * {{done|'''navigate(url)'''}}: navigates to the specified url.
| |
| * {{done|'''go_back()'''}}: performs back navigation
| |
| * {{done|'''go_forward()'''}}: performs forward navigation
| |
| * {{done|'''refresh()'''}}: refresh the current page
| |
| | |
| === Script Execution ===
| |
| | |
| * {{done|'''execute_script(script)'''}}: executes a synchronous JavaScript script, and returns the value which the script returns
| |
| * {{done|'''execute_async_script(script)'''}}: executes an asynchronous JavaScript script; returns only when script calls <code>marionetteScriptFinished(return_value);</code>. script will generate a <code>TimeoutException</code> if the script does not call <code>marionetteScriptFinished</code> within the timeout specified by <code>set_script_timeout</code>.
| |
| | |
| For both methods, scripts can not set global variables which persist between script executions. Instead, scripts wishing to share data between calls should add properties to the window object. For scripts executed in the content context, security restrictions require that custom properties of the window object be accessed using <code>window.wrappedJSObject</code>.
| |
| | |
| === HTML Interaction ===
| |
| | |
| * {{done|'''find_element(method, target)'''}}: returns an HTMLElement object representing an HTML Element, which can be used with other HTML interaction methods. <code>method</code> is one of: <code>HTMLElement.CLASS</code>, <code>HTMLElement.ID</code>, <code>HTMLElement.NAME</code>, or <code>HTMLElement.TAG</code>. Methods planned but not yet implemented are: <code>HTMLElement.SELECTOR</code>, <code>HTMLElement.XPATH</code>, <code>HTMLElement.LINK_TEXT</code>, and <code>HTMLElement.PARTIAL_LINK_TEXT</code>. If multiple elements match the specified method and target, only the first (in DOM order) is returned.
| |
| * {{done|'''find_elements(method, target)'''}}: same as above, but returns a list of all elements that match the specified method and target.
| |
| | |
| NYI: variations of the above two methods which accept a third parameter, which is an HTMLElement under which the find should be performed.
| |
| | |
| ==== HTMLElement Methods ====
| |
| | |
| All of the following are methods of HTMLElement objects, returned by the find_ methods above.
| |
| | |
| * {{done|'''click()'''}}: clicks the element
| |
| * {{ok|'''get_attribute(attr)'''}}: returns the value of the specified attribute. Completed but not pushed.
| |
| * {{ok|'''text()'''}}: returns the element's text, if any
| |
| * {{ok|'''send_keys(string)'''}}: sends key events to the element. The format of 'string' is defined at http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value
| |
| * {{ok|'''clear()'''}}: clears the element's input, e.g., for text fields
| |
| * {{ok|'''selected()'''}}: returns True if the element is currently selected. Completed but not pushed.
| |
| * {{ok|'''enabled()'''}}: returns True if the element is currently enabled
| |
| * {{ok|'''displayed()'''}}: returns True if the element is currently displayed
| |