????????
??????????о?Android???????????????????е??Щ??????????????????Щ????????????а???android???????CTS??Monkey??Monkeyrunner??benchmark??????test tool????????????????????в??????????????????????
???????????monkeyrunner
????monkeyrunner???????????API??????APIд????????????Android??????????Android?豸????????????monkeyrunner????????д?????Python???????????Android??ó????????????????????????????????????????????????????????????洢?????????monkeyrunner??????????????????????????/??????????ó?????豸???????????е??????????????????????????????????????
????????monkeyrunner?????Monkey???????
????Monkey??
????Monkey??????????????豸?????????adb shell?У??????????????α??????????
????monkeyrunner??
????monkeyrunner???????????????????API?????????????????????豸?????????
????????monkeyrunner?????????
????1?????豸?????monkeyrunner API????????豸?????????????????????????????????????е??豸????????????????????????????????????????????????????????????????????????????ó????????????ú?????????????????????????????????????
????2?? ???????? monkeyrunner??????????????????ι???????????????????????????????????????????????????
????3?? ???????monkeyrunner??????????????????????????????????????????????????????????????????
????4?? ??????????????????monkeyrunner?????API????????????????Python???????????????????????????Android?豸?????????monkeyrunner API??????????????????Python os??subprocess?????????Android Debug Bridge??????Android?????
???????????monkeyrunner
??????????????????????????????monkeyrunner????????????????????monkeyrunner?????????????????????????????SDK????tools?????μ?monkeyrunner????????????????????????в???????monkeyrunner????????????Python?????????????У???????????????????????????
????monkeyrunner???????????
????monkeyrunner -plugin <plugin_jar> <program_filename> <program_options>
?????塢???
??????sample?е?ApiDemos??????????????ApiDemos.apk??
???????????device????
????1?? ??ApiDemos.apk????$Android_Root ools???
????2?? ??$Android_Root ools????????monkeyrunnerprogram.py????????????????

 

1 # Imports the monkeyrunner modules used by this program
2
3  from com.android.monkeyrunner import MonkeyRunner?? MonkeyDevice?? MonkeyImage
4
5  # Connects to the current device?? returning a MonkeyDevice object
6
7 device = MonkeyRunner.waitForConnection()
8
9  # Installs the Android package. Notice that this method returns a boolean?? so you can test
10
11  # to see if the installation worked.
12
13 device.installPackage('./ApiDemos.apk')
14
15
16  # Runs the component
17
18 device.startActivity(component='com.example.android.apis/.ApiDemos')
19
20
21  # Presses the Menu button
22
23 device.press('KEYCODE_MENU'??'DOWN_AND_UP')
24
25
26  # Takes a screenshot
27
28 result = device.takeSnapshot()
29
30
31  # Writes the screenshot to a file
32
33 result.writeToFile('./shot1.png'??'png')