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 1000eg: 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