Tuesday, March 13, 2012

Automatic generation of screenshots for a tutorial on Android app

I invested some time in finding a way to generate screenshots for the tutorial on my Android app. With now 11 images in four languages, keep the screenshots up to date when the app evolves, has become too tedious to be done manually
Monkeyrunner seems the perfect tool, but I found it very hard to have it execute a given scenario reliabily. The two main problems I encountered were:
  • Entering data in a form
  • Triggering context menu in listviews
The solution I found, involves defining a key (e.g. KEYCODE_ENVELOPE) to a backdoor in the app, that changes the activity's state in the desired way.  Then in the Monkeyrunner script, I just need to send the key at the right moment with

device.press('KEYCODE_ENVELOPE', MonkeyDevice.DOWN)

The method handling the key in the activity class is onKeyDown.
You can find examples in the classes AccountEdit, ExpenseEdit, SelectAccount and SelectCategory from here (tag r25). In the editing activities, I populate the form with data, in the selection activities, I make sure that the listview has the focus, I found no other reliable method to have the context menu triggered from Monkeyrunner.

No comments:

Post a Comment