Within the past year i have done some considerable amount of test automation on Android 2.3.x ++. Mostly using Python + monkeyrunner.The thing is , there are much more convenient tools out there like monkey talk and robotium , etc. But if you are doing B2B applications with big clients than using extra 3rd party libraries becomes a hassle and you left with no choice other than python + monkeyrunner combo which isn’t bad but has downsides , lets just say there is too much hassle in that road :)
An android test automation script that instantites a smoke test generally includes 10 to 40 steps.Before we start to implement the reproduction steps we first define the connection between the device and the Android debug bridge. Define the touch actions within python environment like : MonkeyDevice.DOWN_AND_UP (which simulates you touching the screen). Than i advice you to implement a function which gets the ADB LOGS that are higher or equal to the level of ERROR and write them down somewhere. While developing the script make sure to implement the touch actions based on UI element id’s. This is much , much more practical than finding the x,y coordinates of that element(in case you didn’t know , you can activate coordinates under options / developer options) ..
You can inspect id’s with android debug monitor. While automation itself isn’t hard or cumbersome , catching errors is. You can easily understand if there is an error or not with automating id’s but eventually you gonna have to use coordinates and when you do you have to scan the adb logs to make sure if the smoke test failed or not.
Down this road lies many ugly hacks :) , like for example if you are automating an application where it opens a WebView and there is an input box which you have to focus , you will not be able to focus it by touching it , instead ..
a 2 or 3 pixel wide drag actions does :
device.drag (tuple start, tuple end, float duration, integer steps)
device.drag((350, 620), (353, 620), 0.5, 50)
> An ugly hack is better than no hack !
Thanks for reading, take care!