1、直接使用adb命令

adb shell monkey -p 包名 <event-count>

例:

1)adb shell monkey -p 包名-s 500 --throttle 100 --ignore-crashes --ignore-timeouts --monitor-native-crashes -
v -v 10000

产生时间序列的种子值:500,事件间延迟 100 忽略程序崩溃 、 忽略超时 、 监视本地程序崩溃 、 详细信息级别为2 , 产生 10000个事件

2)adb shell monkey -p com.vlife.stage --throttle 100 --ignore-crashes --ignore-timeouts --kill-process-after-error

--pct-touch 35
--pct-syskeys 30
--pct-appswitch 35 --hprof -v -v -v 50000

注意:这个命令定义了事件的百分比,但并没有定义种子值,在实际应用中是非常不推荐的,只有同样的种子值才会产
生同样的序列,若遇见随机问题,没有种子数则无法复现该问题,为了方便重现问题一定要加-s, 另外日志的级别建议选择详细级别,三个-v -v -v

 

2、使用白名单的方法

1)使用adb命令将framework.jar 和monkey.jar 文件放到sdcard下(文件路径:https://github.com/zhangzhao4444/Maxim

adb push  framework.jar  monkey.jar  文件到 /sdcard

2)执行命令运行monkey(可根据需求改变参数)

adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p 包名 --uiautomatormix --running-minutes 60

参数说明:

1.tv.panda.test.monkey.Monkey 主调入口  无需修改

2.策略模式

--uiautomatormix 混合模式(70%控件解析随机点击,其余30%按原Monkey事件概率分布)

--pct-uiautomatormix n 可自定义混合模式中控件解析事件概率

--uiautomatordfs DFS深度遍历算法(优化版)(注 Android5不支持dfs)

3.--running-minutes 60  执行60分钟monkey

4.--act-whitelist-file  /sdcard/awl.strings    在sdcard中自定义Activity白名单(锁定跳转只可进入其中指定的Activity)

例如:

5.其他参数及用法同原始Monkey