Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

EmulatorBattery

This class allows interaction with an emulator's battery.  Tests running on an emulator will have an instance of this class available as self.marionette.emulator.battery.

Implementation:  https://github.com/mozilla/marionett...tor_battery.py

Attributes

Attribute Type Description
charging bool Sets or returns the charging state of the emulator's battery.
level float Sets or returns the battery level, from 0.0 to 1.0.

Example

This example sets the battery level to 25%. This example uses the execute_script call, which is used to execute arbitrary JavaScript in either the chrome or content process of a window. By default, as shown here, it gets executed in the content window.

from marionette_test import *

class TestBatteryLevel(MarionetteTestCase):

    def test_level(self):
        # make sure we're really running on an emulator
        assert(self.marionette.emulator.is_running)
        
        # set the current battery level to 25%
        self.marionette.emulator.battery.level = 0.25
        
        # read the battery level and make sure it's the same
        self.assertEqual(25, int(self.marionette.emulator.battery.level * 100), "unexpected battery level")
        
        # check it against the battery WebAPI by executing and returning the webAPI call in the window
        moz_level = self.marionette.execute_script("return navigator.mozBattery.level;")
        self.assertEqual(25, int(moz_level * 100), "unexpected mozBattery level")

Document Tags and Contributors

 Contributors to this page: fscholz, Sheppy, jgriffin, mdas
 Last updated by: fscholz,