This tutorial assumes you've set up Marionette for B2G.
Open a terminal and launch Python to get to the interactive prompt:
$ python
From the interactive prompt, run the commands necessary to invoke a Marionette session interactively:
>>> from marionette import Marionette
>>> marionette = Marionette('localhost', 2828)
>>> marionette.start_session()
u'session-b2g'
Here, we see that the system returns that a Marionette session is running.
The command "marionette.execute_script()
" can embed JavaScript commands, which can then run on B2G's Gecko platform. Using this, you can see which DOM elements return HTMLElement objects and available attributes and methods:
>>> marionette.execute_script("return navigator.battery;")
{u'onlevelchange': None, u'level': 0.91, u'dischargingTime': None, u'onchargingchange': None, u'ondischargingtimechange': None, u'onchargingtimechange': None, u'chargingTime': None, u'charging': True}
>>> marionette.execute_script("return navigator.battery.level;")
0.91
>>> marionette.execute_script("return navigator.geolocation;")
{}
>>> marionette.execute_script("return navigator.mozSms;")
{u'onreceived': None, u'ondelivered': None, u'onsent': None}
You can traverse the DOM tree using this technique to evaluate which objects, methods, and attributes are available.
Testing Basic Telephony interactively
you can test out basic telephony interactively with marionette. The following example requires two working phones, each with simcards. One is your Galaxy SII, with B2G running.
Start an interactive Marionette session and forward the port:
$ adb forward tcp:2828 tcp:2828
$ python
>>> from marionette import Marionette
>>> marionette = Marionette('localhost', 2828)
>>> marionette.start_session()
u'5-b2g
Now, you have two possible approaches with marionette. One is a little more Pythonic:
>>> marionette.set_context("chrome")
True
>>> marionette.execute_script("return navigator.mozTelephony;")
>>> num =
>>> marionette.execute_script("return navigator.mozTelephony.dial('%d');" % num)
Or else, this approach, which relies more on JS (embedded within marionette.execute_script()
) Notice the quotes around the JS number variable:
>>> marionette.set_context("chrome")
True
>>> marionette.execute_script("""
... var num = ""
... return navigator.mozTelephony.dial(num);
... """)
{}
We'll try the first approach:
This kicks off a phone call, the output of which can be monitored in $adb logcat