#Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
#Connects to the current device,retuning a MonkeyDevice object
device=MonkeyRunner.waitForConnection()
#Install the Android package.Notice that this method returns a boolean,so you #can test to see if the installation worked.
device.installPackage('./ApiDemos.apk')
#Remove the Android package.
device.removePackage('com.example.android.apis')
#Runs the component
device.startActivity(component='com.example.android.apis/.ApiDemos')
#Presses the Menu button
device.press('KEYCODE_MENU','DOWN_AND_UP')
#Takes a screenshot
result=device.takeSnapshot()
#Writes the screenshot to a file
result.writeToFile('./shot1.png','png')
#Delay(second)
MonkeyRunner.sleep(3)
#Slides touch screen
for i in range(1,70):
device.drag((250,850),(250,110),0.1,10) //Start,End,duration,steps
for i in range(1,70):
device.drag((250,110),(250,850),0.1,10)
MonkeyRunner.sleep(1)
#Touch screen
device.touch(507,72,"DOWN_AND_UP")
#exc adb shell
device.shell("input text group01")
#Presses keys
device.press('KEYCODE_HOME','DOWN_AND_UP')
#menu: KEYCODE_MENU
#home: KEYCODE_HOME
#back: KEYCODE_BACK
#search: KEYCODE_SEARCH
#call: KEYCODE_CALL
#end: KEYCODE_ENDCALL
#NAV up: KEYCODE_DPAD_UP
#NAV down: KEYCODE_DPAD_DOWN
#NAV left: KEYCODE_DPAD_LEFT
#NAV right: KEYCODE_DPAD_RIGHT
#OK: KEYCODE_DPAD_CENTER
#volume up: KEYCODE_VOLUME_UP
#volume down: KEYCODE_VOLUME_DOWN
#power: KEYCODE_POWER
#power: KEYCODE_CAMERA
#Input asd
device.type('asd')
#Input enter
device.press('KEYCODE_ENTER')
#Recode
monkeyrunner monkey_recorder.py
save as:monkey_test.mr
#play back
monkeyrunner monkey_playback.py monkey_test.mr
#help and save
monkeyrunner help.py <format> <outfile> //format:text or html,outfile:directory+filename
#Reboot
device.reboot()
#Get the Phone model
print str(device.getProperty('build.model'))
print str(device.getProperty('build.board'))
print str(device.getProperty('build.device'))
print str(device.getProperty('build.fingerprint'))
print str(device.getProperty('build.brand'))
1. adb命令的执行:os.system()
例如 adb root, adb push, adb pull, 可以用 os.system()来实现,例如os.system("adb push e:\\tmp\\email_eception.log /sdcard/")
2.目录操作: os.chdir(),os.getcwd()
os.chdir('e:\\tmp')
os.getcwd()
3. 创建以时间命名的文件夹
首先获取时间:time.ctime(), 获得的时间格式如"Mon Oct 31 15:48:30 2011",因为window不支持文件夹名包括“:”,并且带有空格也会带来兼容性的问题,可以用字符串处理函数str.replace来将空格用“_”替换,将“:”删除,st2.replace(" ","_").replace(":","")
4. 判断文件是否存在
os.path.exists(), 返回True 或 False
os.path.exists("D:\\shellwork\\devtool\\setup\\music\\setup.bat")
5. 连接之前要确保是以root身份连接的(adb root)
os.system('adb root')
os.system('adb wait-for-device')
Monkey Runner常用语句
最新推荐文章于 2023-12-27 19:34:08 发布