Monkey是啥?
对Android自动化测试,通过Monkey命令模拟用户操作对应用进行压力测试,所有事件随机
Monkey的使用
使用格式:adb shell monkey 「命令参数」
monkey常用指令
参数 | 作用 | 示例 | 示例说明 |
---|---|---|---|
-p | 指定应用程序 | adb shell monkey -p 包名 | |
-v | 打印log级别 | adb shell monkey -v -v -v -p 包名 | log日志Level2,-v越多日志信息越细,最多3个 |
–throttle | 操作间的延迟毫秒 | adb shell monkey --throttle 5000 100 -p 包名 | 每个指令延迟5秒,100个随机事件 |
–pct-touch | 触摸 | ||
–pct-motion | 滑动 | ||
–pct-pinchzoom | 放大缩小手势操作 | ||
–pct-trackball | 轨迹球 | ||
–pct-rotation | 屏幕旋转(横竖屏) | ||
–pct-nav | 基本导航事件 | ||
–pct-majornav | 主要导航事件 | ||
–pct-syskeys | 系统按键(home键、拨号键、返回键、音量键等) | ||
–pct-appswitch | 启动事件 | ||
–pct-flip | 键盘翻转 | ||
–pct-anyevent | 其他事件 | ||
–ignore-crashes | 忽略崩溃,直到monkey运行结束 | adb shell monkey -p 包名 --ignore-crashes 1000 | 测试中即使程序崩溃,Monkey仍会继续执行直到1000个事件完毕 |
–ignore-timeouts | 忽略应用错误,直到monkey运行结束 | adb shell monkey -p 包名 --ignore-security 1000 |
eg: adb shell monkey -v -v -v --throttle 300 -s 123456 --ignore-crashes --ignore-timeouts --pct-touch 100 -p com.android.calculator 100
eg: adb shell monkey -v -v -v --throttle 300 -s 123456 --ignore-crashes --ignore-timeouts --pct-touch 50 --pct-motion 50 -p com.android.calculator 100
eg:adb shell monkey -p cn.emoney.acg --pct-syskeys 60 1000
eg:adb shell monkey -p cn.emoney.acg–pct-appswitch 70 1000
结束Monkey
1.新建窗口,
2.adb shell
3.ps | grep monkey,返回的第一个数字,就是monkey的进程号
4.kill pid 进程号
导出Monkey的log日志
1.保存到电脑上
例:adb shell monkey -p 包名 -v 1000 > /Desktop/monkey.txt
2.保存到电脑上,标准流和错误流分开保存,1为标准,2为错误
例:adb shell monkey -p 包名 -v 1000 1>/Desktop/info.txt 2>/Desktop/error.txt
Monkey日志讲解:https://testerhome.com/topics/12212
Monkey测试电量:https://testerhome.com/topics/12241