Marionette Python Client for smartUI
Imagine, you are developing smartUI widgets for the content server.
Imagine, you have to prove, that your widget(s) are ok. You would use a programmable browser for your tests.
Then, think of the OpenText conforme solution to do this tests (its not the only one, but its non-heretic)
Now we are discussing the thing called Browser Remote Control (Firefox) on the right side (with the red frame) of this Requirements Diagram of smartUI.
The Marionette Python client library
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. This is one reason why you need Python when using this Client in the SDK
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 can be used as a browser-based testing device for your widgets in Mockup mode.
Marionette is available in all Firefox builds; it is not enabled, however, unless you launch Firefox with the -marionette command-line argument.
Marionette is also available on Firefox for Android (Fennec): the Marionette Python client can launch Fennec for you with Marionette enabled
The github page is https://github.com/AutomatedTester/marionette_client
Installing the Client: (If pip install is installed, otherwise check the paths. Normally c:\pythonxx\scripts is missing)
–pip install marionette_driver
Start a Marionette enabled Instance of Firefox (launch Firefox with the -marionette command-line argument)
Usage
–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 start_session():
from marionette_driver.marionette import Marionette
client = Marionette('localhost', 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 session_capabilities attribute. After finishing with a session, you can delete it with delete_session(). Note that this will also happen automatically when the Marionette object is garbage collected
DOM Elements
–In order to inspect or manipulate actual DOM elements, they must first be found using the find_element() or find_elements() methods:
from marionette_driver.marionette import HTMLElement
element = client.find_element(By.ID, 'my-id')
assert type(element) == HTMLElement
elements = client.find_elements(By.TAG_NAME, 'a')
assert type(elements) == list
–Now that an element has been found, it’s possible to manipulate it:
Recommended by LinkedIn
element.click()
element.send_keys('hello!')
print(element.get_attribute('style'))
–Be warned that a reference to an element object can become stale if it was modified or removed from the document.
Tutorial
–Let’s use a typical python shell:
python
–First, import Marionette:
from marionette_driver.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.opentext.com”)
–Now you’re at opentext.com! 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:
from marionette_driver import By
first_link = client.find_element(By.TAG_NAME, "a")
–first_link now holds a reference to the first link on the page. You can click it:
first_link.click()