from com.android.monkeyrunner import MonkeyRunner as mr,MonkeyDevice as md
1.与设备进行通讯:
device = mr.waitForConnection()
2.安装app应用:
device.installPackage("D:/app/app_name.apk"),路径
3.查看包名:
device.shell("pm list package | grep pkg_name")已安装的某的应用的app名
4.删除应用
device.removePackage("pak_name"),参数为包名
5.启动应用:(以启动计算器为例)
package = "com.android.calculator2"
activity = “com.android.calcculator2.Calculator”
runComponent = package +'/' +activity
device.startActivity(runComponent)
计算器按键操作:
device.press("KEYCODE_7",md.DOWN_AND_UP)
device.type("+")
device.touch(400,500,md.DOWN_AND_UP)
6.获取属性:(分辨率)
device.getProperty("display.height")
device.getProperty("display.width")