WebDriver/Marionette/Marionette Client API: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 26: Line 26:
* {{done|'''execute_script(script)'''}}: executes a synchronous JavaScript script, and returns the value which the script returns
* {{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 TimeoutException if the script does not call <code>marionetteScriptFinished</code> within the timeout specified by 'set_script_timeout'.
* {{done|'''execute_async_script(script)'''}}: executes an asynchronous JavaScript script; returns only when script calls <code>marionetteScriptFinished(return_value);</code>.  script will generate a TimeoutException if the script does not call <code>marionetteScriptFinished</code> within the timeout specified by 'set_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.

Revision as of 06:53, 8 December 2011

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.

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; 'context' is either "chrome" or "content"
  • [ON TRACK] get_window(): returns an id representing the current window
  • [ON TRACK] get_windows(): returns a list of all available windows
  • [ON TRACK] switch_to_window(window): sets the active window; all future commands will be targeted here. 'window' is one of the id's returned by get_windows().
  • [ON TRACK] switch_to_frame(id): sets the active frame; all future commands will be targeted here. 'id' is either the id of an iframe, an HTMLElement (see below) representing an iframe, or None to target the default top-level frame.

Navigation

  • [ON TRACK] get_url(): returns the current url
  • [DONE] navigate(url): navigates to the specified url
  • [ON TRACK] go_back(): performs back navigation
  • [ON TRACK] go_forward(): performs forward navigation
  • [ON TRACK] 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 a TimeoutException if the script does not call marionetteScriptFinished within the timeout specified by 'set_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.