MonkeyRunner使用

#-*- coding:utf-8 –*-
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
#连接设备
device=MonkeyRunner.waitForConnection(3,"172.10.10.124:5555")
#启动App
device.startActivity("包名/类名")
#暂停两秒
MonkeyRunner.sleep(2)
#点击搜索框
device.touch(100,100,"DOWN_AND_UP")
#输入查询词
device.type('test')
#点击回车键
device.press('KEYCODE_ENTER','DOWN_AND_UP')
#点击搜索按钮
device.touch(400,100,"DOWN_AND_UP")
#截图
image=device.takeSnapshot()
image.writeToFile('./test.png','png')
device.touch(300,100,"DOWN_AND_UP")
#弹出框
MonkeyRunner.alert('test over','This is title','OK')

备注:
1坐标值可通过 sdk自带的uiautomatorviewer获取
2运行方式
 在tool目录下执行monkeyrunner file.py
posted @ 2019-07-22 09:33  GeorgeXu  阅读(357)  评论(0编辑  收藏  举报