??????monkeyrunner?????????д????Android?豸?????????Android????????????API??????monkeyrunner?????????д??????Android??ó??????????????????????????????????????????????????????????????Python??????monkeyrunner???????????????/??????????е?????????????????ó?????豸??????????????????????????????
????????monkeyrunner??????????? ???????/??ó?????????????????﹤?????????????????? ADB???豸?????????????????????????????α???????????????monkeyrunner????????豸??????????????????API?????????????????
??????monkeyrunner?????Android????????Щ?????????
???????豸?????monkeyrunner API????????豸??????????????????????????????????????????????豸??????????е????????????????У??????????????????????????????????????????????????????????????????????????????????????????????
?????????????monkeyrunner????????Android??ó????????????????????????????????????????????????????????
?????????? - monkeyrunner?????????????ó??????????????????鱻??????????????????ó??????????
????????????????-????monkeyrunner?????API???????????????????Python???????Android?豸????????????????? ?????monkeyrunner API?????????????????Python OS?? ?? ???????Android?????????? Android????????
??????????????????????monkeyrunner API??????и??????????????? ???monkeyrunner??????
??????monkeyrunner????????Jython?????Java???????????Python????Jython????monkeyrunner API??Android???????????????Jython???????????Python????????????????API???????
???????????monkeyrunner????
???????????????????豸???????????????monkeyrunner???? MonkeyDevice ???????MonkeyDevice??????????????Android??ó?????????????????????????????????????????????????????????? MonkeyImage?????????????????д??????.png????????????
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner?? MonkeyDevice
# Connects to the current device?? returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package. Notice that this method returns a boolean?? so you can test
# to see if the installation worked.
device.installPackage('myproject/bin/MyApplication.apk')
# sets a variable with the package's internal name
package = 'com.example.android.myapplication'
# sets a variable with the name of an Activity in the package
activity = 'com.example.android.myapplication.MainActivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
# Presses the Menu button
device.press('KEYCODE_MENU'?? MonkeyDevice.DOWN_AND_UP)
# Takes a screenshot
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('myproject/shot1.png'??'png')
??????monkeyrunner API
????????monkeyrunner API??????????е???????? com.android.monkeyrunner??
????MonkeyRunner??????monkeyrunner???????÷??????????????????????monkeyrunner???豸????????????????????????????????????monkeyrunner???????????????e??????????
????MonkeyDevice?????????豸??????????????????????ж????????????????????????????????????ó?????????????????????????????в??????
????MonkeyImage????????????????????????????????????λ????????????????????????MonkeyImage????д????????????????
?????????Python?????????????????Python??顣??monkeyrunner????????????????Щ??顣???????飬???Python ?????
????from com.android.monkeyrunner import <module>
???????У?<???>???????????????????????????????????????????????????????