pycon logo

PyCon 2011 Atlanta

March 9th–17th

Log in or Sign Up

Mobile applications testing using Python - an experimental technique

log in to bookmark this presentaton

Novice / Talk
March 11th 2:55 p.m. – 3:40 p.m.
This session presents an experimental approach that uses mobile simulators - BlackBerry™ and Android™ to run automated end-to-end tests using the Python™ programming language. We’ll walk through the testing process - from the basics of interacting with both device simulators, writing reusable tests on both these devices and executing these tests in PyUnit. Sample code is included.


If you like to learn about how to interact with BlackBerry and Android mobile simulators, then this session is for you. A step-by-step demo with code snippets on how to automate native mobile applications from running a use case/test, validating your test and reporting test results, and using Python mobile simulators libraries. The tests can be reused to run against different resolutions and the framework can be used for different mobile platforms.

Key Takeaways: What benefits will attendees get from participating in your session

  1. Know what tools are available in BlackBerry, Android
  2. Learn how to abstract device-dependent test implementation from test cases
  3. See a demo of tests using native Address Book application on BlackBerry and Android.
  4. One is able to quickly automate tests after this session

Session Discussion Points

1. Overview : Tools in device simulators

Outline what the tools are in Android and BlackBerry simulators that will help users interact with the simulators. E.g. For BlackBerry, there is fledgecontroller. For Android, there is adb.

2. Introduce and

Show how we can abstract these tools using Python and provide common interaction interface with both devices. Demo examples of commonly used commands in both Python libraries.

    def enter(string=None):
        """ If string is None, simulate Enter key in simulator. 

    def backspaces(count=1):
        """ Press backspaces specified by count."""

    def touch(xcoord, ycoord):
        """ Touch screen at (xcoord, ycoord)."""

    def thumbwheel(direction='up', count=1):

    def trackball(direction='left', count=1):

3. Writing device independent tests

       #1. Use python name typing to decide the device to use
       def getDevice(self):
           mobileDevice = testenv.getDevice()
           if mobileDevice == 'android':
               deviceClass = android.AndroidImpl()
               deviceClass = bb.BlackBerryImpl()
           log.debug('Device is ' + mobileDevice)
           return deviceClass 

       #2. Usecase implementation
       # On BlackBerry
       def login(username, password):

      #3. Testcases (device independent) for Login

      class LoginBAT(unittest.TestCase):
          device = testlib.testenv.getDevice()

          def testIncorrectUsername():
              self.device.login(incorrectUser, correctPin)
              self._testMethodName, '100%x40%+0+35%'))

          def testSuccessfulLogin():
              self._testMethodName, '100%x40%+0+35%'))

     Test assertion use - takes screenshot of current
     image and compare with expected image with crop settings and 
     tolerance level using ImageMagick. 

     def compare(device, image, cropSettings=None, tolerance=500):

     #4. Run test, showing assertion results.

4. Summary : Test Framework

Walkthrough test framework architecture (diagram will be included). Lowest level is test utilities -, (exceptions handling etc.).

Next up is device simulator libraries -, containing device controls.

Above this is application use case implementation, followed by end-to-end device independent tests.

Finally, at the top layer is test runner and reporting framework.

5. Advantages and Limitations


- Zero startup cost low cost of maintenance
- Can be agile
- Full control of the devices
- No sharing or scheduling of resources
- Reuse of tests for different resolutions, OS and devices.


- Device simulator is not suitable for hardware (e.g. blue tooth,
  multimedia) and network configurations testing.
- Does not simulate actual performance.
- Does not test dynamic images or results well.