Mobile applications testing using Python - an experimental technique
log in to bookmark this presentaton
Abstract
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
- Know what tools are available in BlackBerry, Android
- Learn how to abstract device-dependent test implementation from test cases
- See a demo of tests using native Address Book application on BlackBerry and Android.
- 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 bblib.py and androidlib.py
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() else: deviceClass = bb.BlackBerryImpl() log.debug('Device is ' + mobileDevice) return deviceClass #2. Usecase implementation # On BlackBerry def login(username, password): enter(username) thumbwheel('down',1) enter(password) thumbwheel('down',1) enter() #3. Testcases (device independent) for Login class LoginBAT(unittest.TestCase): device = testlib.testenv.getDevice() def testIncorrectUsername(): self.device.login(incorrectUser, correctPin) self.assertTrue(imagelib.compare(self.device,\ self._testMethodName, '100%x40%+0+35%')) def testSuccessfulLogin(): self.device.login(correctUser,correctPin) self.assertTrue(imagelib.compare(self.device,\ self._testMethodName, '100%x40%+0+35%')) Test assertion use imagelib.py - 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 - imagelib.py, logger.py testlib.py (exceptions handling etc.).
Next up is device simulator libraries - bblib.py, androidlib.py 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
Advantages
- 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.
Limitations
- 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.