WebDriver/Marionette/Client

From MozillaWiki
Jump to: navigation, search

Getting the Client

The client is available on GitHub.

If you wish to implement your own client, then you can communicate with the Marionette server via JSON wire protocol.

Using the Client Interactively

Once you installed the client and have Marionette running, you can fire off your favourite an interactive python environment and start playing with Marionette:

 from marionette import Marionette 

Now create the client for this session. Assuming you're using the default port on a Marionette instance running locally:

 client =  Marionette(host='localhost', port=2828)
 client.start_session()

This will return some id representing your session id. Now that you've established a connection, let's start doing interesting things:

 client.execute_script("alert('o hai there!');")

You should now see this alert pop up! How exciting! Okay, let's do something practical. Close the dialog and try this:

 client.navigate("http://www.mozilla.org")

Now you're at mozilla.org! You can even verify it using the following:

 client.get_url()

You can even find an element and click on it. Let's say you want to get the first link:

 first_link = client.find_element("tag name", "a") #uses "tag name" as a search strategy. For different strategies, see HTML interaction

first_link now holds a reference to the first link on the page. You can click it:

 first_link.click()

For more information of what you can do with this client, check out our API

Using the Client for Testing

See our Marionette Tests section