.. py:currentmodule:: marionette_driver.marionette Marionette Python Client ======================== The Marionette Python client library allows you to remotely control a Gecko-based browser or device which is running a Marionette_ server. This includes Firefox Desktop and Firefox for Android. The Marionette server is built directly into Gecko and can be started by passing in a command line option to Gecko, or by using a Marionette-enabled build. The server listens for connections from various clients. Clients can then control Gecko by sending commands to the server. This is the official Python client for Marionette. There also exists a `NodeJS client`_ maintained by the Firefox OS automation team. .. _Marionette: https://developer.mozilla.org/en-US/docs/Marionette .. _NodeJS client: https://github.com/mozilla-b2g/gaia/tree/master/tests/jsmarionette Getting the Client ------------------ The Python client is officially supported. To install it, first make sure you have `pip installed`_ then run: .. code-block:: bash $ pip install marionette_driver It's highly recommended to use virtualenv_ when installing Marionette to avoid package conflicts and other general nastiness. You should now be ready to start using Marionette. The best way to learn is to play around with it. Start a `Marionette-enabled instance of Firefox`_, fire up a python shell and follow along with the :doc:`interactive tutorial `! .. _pip installed: https://pip.pypa.io/en/latest/installing.html .. _virtualenv: http://virtualenv.readthedocs.org/en/latest/ .. _Marionette-enabled instance of Firefox: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/Builds Using the Client for Testing ---------------------------- Please visit the `Marionette Tests`_ section on MDN for information regarding testing with Marionette. .. _Marionette Tests: https://developer.mozilla.org/en/Marionette/Tests Session Management ------------------ A session is a single instance of a Marionette client connected to a Marionette server. Before you can start executing commands, you need to start a session with :func:`start_session() `: .. code-block:: python from marionette_driver.marionette import Marionette client = Marionette('127.0.0.1', port=2828) client.start_session() This returns a session id and an object listing the capabilities of the Marionette server. For example, a server running on Firefox Desktop will have some features which a server running from Firefox Android won't. It's also possible to access the capabilities using the :attr:`~Marionette.session_capabilities` attribute. After finishing with a session, you can delete it with :func:`~Marionette.delete_session()`. Note that this will also happen automatically when the Marionette object is garbage collected. Context Management ------------------ Commands can only be executed in a single window, frame and scope at a time. In order to run commands elsewhere, it's necessary to explicitly switch to the appropriate context. Use :func:`~Marionette.switch_to_window` to execute commands in the context of a new window: .. code-block:: python original_window = client.current_window_handle for handle in client.window_handles: if handle != original_window: client.switch_to_window(handle) print("Switched to window with '{}' loaded.".format(client.get_url())) client.switch_to_window(original_window) Similarly, use :func:`~Marionette.switch_to_frame` to execute commands in the context of a new frame (e.g an