monkey04--MonkeyRunner API及实践

三大模块:MonkeyRunner, MonkeyDevice, MonkeyImage

1. 使用python编写脚本

2. monkeyrunner demo.py 使用monkeyrunner执行python脚本

MonkeyRunner API

1. Alert警告框

void alert(string message, string title, string okTitle)

image.png

不用管这里的红线报错
用monkeyrunner直接执行这个脚本就好了
image.png

2. WaitForConnection
等待设备连接,有多个device id,需要指明具体哪个设备
waitForConnection(float timeout, string deviceid)
timeout等待时间,单位秒

3. drag界面上的拖动
drag(tuple start, tuple end, float duration, integer steps)
start 起点位置,
end 终点位置,
duration 手势持续的时间,
steps 插值点的步数,默认10。

4. press按键
press(string keycode, dictionary type)
keycode名,DOWN, UP, DOWN_AND_UP

5. startActivity
startActivity(package+'/'+activity)

6. touch点击
touch(integer x, integer y, integer type)

7. type输入
type(string message)

8. takeSnapshot截屏
MonkeyImage takeSnapshot()

MonkeyImage API

9. sameAs图像对比
boolean sameAs(MonkeyImage other, float percent)

10. writetoFile保存图像文件
void writeToFile(string path, string format)

实践:

实现在搜索框中输入查询词,并截图(与上一篇的步骤差不多)

image.png

使用pycharm或其它文本工具写好代码后,在终端使用以下命令运行即可。

monkeyrunner demo.py

你可能感兴趣的:(monkey04--MonkeyRunner API及实践)