Monkeyrunner to learn, must have started the AVD, if you do not know how to start the AVD, please see my previous article, this article mainly on the simulator I use Monkeyrunner to do the first Test.
1. Path of terminal open Monkeyrunner:/usr/java/sdk/.../tools
2../monkeyrunner
3.from Com.android.monkeyrunner Import Monkeyrunner,monkeydevice,monkeyimage
4.device=monkeyrunner.waitforconnection ()
Connecting AvD and Monkeyrunner
5.device.installpackage (' .../***.apk ')
Install an app to emulator, true to indicate successful installation
6.device.startactivity ("Packagename/startactivity")
How to get PackageName and startactivity
2. Get PackageName,
I installed the apidemos.apk on the phone/simulator and opened it, which can be implemented by the following code:
Import Android
Import Pprint
Droid=android. Android ()
Pacs=droid.getrunningpackages ()
Pprint.pprint (Pacs.result)
So we can get packagename.
3. Get StartActivity
Get startactivity with the code below:
Import Android
Import Pprint
Droid=android. Android ()
Apps=droid.getlaunchableapplications ()
Pprint.pprint (Apps.result)
This will allow you to get to the startactivity.
Http://wenku.baidu.com/link?url= imim-3ulsmftwmlvulgp91fiwctgoramyaq8uvleetepri3qxarmgw-ayi9l0slga3k9w7zzyahie-cwm2uwws-ttgy6aemuahcaaopmtkg
Monkeyrunner's Android Automated Test Learning (I.)