WebDriver/Marionette/Marionette Client API
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.
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;
contextis either "chrome" or "content" - [DONE] get_window(): returns an id representing the current window
- Template: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.
windowis one of the id's returned byget_windows(). 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.
idis either the id of an iframe, an HTMLElement (see below) representing an iframe, or None to target the default top-level frame.
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
marionetteScriptFinished(return_value);. script will generate aTimeoutExceptionif the script does not callmarionetteScriptFinishedwithin the timeout specified byset_script_timeout.
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 window.wrappedJSObject.
HTML Interaction
- [DONE] find_element(method, target): returns an HTMLElement object representing an HTML Element, which can be used with other HTML interaction methods.
methodis one of:HTMLElement.CLASS,HTMLElement.ID,HTMLElement.NAME, orHTMLElement.TAG. Methods planned but not yet implemented are:HTMLElement.SELECTOR,HTMLElement.XPATH,HTMLElement.LINK_TEXT, andHTMLElement.PARTIAL_LINK_TEXT. If multiple elements match the specified method and target, only the first (in DOM order) is returned. - [ON TRACK] 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
- [ON TRACK] get_attribute(attr): returns the value of the specified attribute
- [ON TRACK] text(): returns the element's text, if any
- [ON TRACK] 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
- [ON TRACK] value(): returns the element's value
- [ON TRACK] clear(): clears the element's input, e.g., for text fields
- [ON TRACK] selected(): returns True if the element is currently selected
- [ON TRACK] enabled(): returns True if the element is currently enabled
- [ON TRACK] displayed(): returns True if the element is currently displayed