Mario洁 发表于 2019-3-20 16:19:45

Monkey常用命令及常见问题

adb shell monkey –p程序包名 –v测试次数

查看程序包名方法:adb shell, am monitor 点击要查看的app后出现包名



adb shell monkey -p 程序包名 --throttle 380 -v -s 3500 300000 >C:\log.txt

这个monkey命令,当monkey test 过程中遇到Crash 或者ANR(Application Not Responding),就会自动终止.

-p要指定多个包,需要使用多个-p选项,每个-p选项只能用于一个包

--throttle在事件之间插入固定延迟。延迟时间,单位ms。(throttle:节流、减速)

-v 命令行的每一个-v 将增加反馈信息的级别。Level 0( 缺省值) 除启动提示、测试完成和最终结果之外,提供较少信息。Level1 提供较为详细的测试信息,如逐个发送到Activity的事件。Level 2 提供更加详细的设置信息,如测试中被选中的或未被选中的Activity 事件。

-s<seed>伪随机数生成器的 seed 值。如果用相同的seed值再次运行Monkey ,它将生成相同的事件序列。命令中的300000 代表monkey event执行的次数,3500表示Seed值(影响随机事件的发生顺序)

adb shellmonkey -f <scriptfile> <event-count>
      -f:后接测试脚本名,表示要使用monkey运行指定的monkey脚本,
      如:$ adb shell monkey -f /mnt/sdcard/test01 3

注:这里的3是指循环次数,不是事件数



出现deviceoffline情况   

解决方法:

方法一:执行 #adbkill-server   #adb start-server#adb devices 看看设备是否还是处于offline状态,如果是,请尝试方法二

方法二:重新启动设备,开机后,执行:#adb devices

方法三:关闭豌豆荚、360等第三方手机助手,试下;

方法四:插拔手机USB,或者重启手机/电脑



停止Monkey测试

adb shell 回车

ps | grep monkey此时可以看到monkey进程的id(第一个数字)

输入kill id数字(此处为8088)



或者adb reboot 重启手机

1,adb install xx.apk:

把指定的安装包apk文件安装到测试设备中

2,adb shell monkey:(尽量不要用)

给指定的设备发送压力测试,number是要测试的次数。执行这个命令的效果就相当于有个手指在你的手机上乱点。我尝试了10000次,结果费了好一会儿功夫才把手机恢复到我想到的效果。

3,adb shell monkey -p pkgname :

同上面效果一样,只是对指定包名(pkgname)apk进行测试。

4,Monkey高级参数的应用

4.1.throttle参数:指定事件之间的间隔时间

adb shell monkey-throttle :milliseconds是时间值 ,单位毫秒

4.2.seed参数:伪随机数生成器的seed值。

adb shell monkey -s:如果用相同的 seed 值再次运行 Monkey ,它将生成相同的事件序列。

4.3.touch:设置触摸事件

adb shell monkey-pct-touch :指定touch事件的百分比percent

4.4.motion:设置动作事件

adb shell monkey-pct-motion :指定motion事件的百分比percent

4.5.trackball:设置轨迹球事件

adb shell monkey-pct-trackball :指定轨迹球事件百分比percent

4.6.nav:导航事件设置

adb shell monkey -pct-nav:指定基本导航事件百分比percent

4.7.majornav:设置主要导航事件

adb shell monkey-pct-majornav :设定主要导航事件百分比percent,兼容中间键,返回键,菜单按键

4.8.syskeys:设置事件

adb shell monkey-pct-syskeys :设定系统事件百分比percent,比如HOME,BACK,拨号及音量调节等事件。

4.9.appswitch:启动Activity事件

adb shell monkey-pct-appswitch :设定启动activity的事件百分比percent

4.10.anyevent:不常用事件设置

adb shell monkey-pct-anyevent :设定不常用事件地百分比

4.11.crashes :程序崩溃事件设置

adb shell monkey-ignore-crashes :忽略崩溃和异常事件

4.12.timeouts:超时事件设置

adb shell monkey-ignore-timeouts :忽略超时事件


页: [1]
查看完整版本: Monkey常用命令及常见问题