monkey 自动化测试命令
monkey命令是一个用于对应用程序进行压力测试的实用工具,该命令随机发送指定次数的用户事件流(按键输入、触屏、手势等)到 APP 界面。monkey 是猴子的单词,顾名思义就是在手机 APP 上蹿下跳不断地随意乱输入一通。
语法格式:
Usage: monkey [options]
options 参数:
-p <allowed_package> # 允许测试的软件包, 可以指定多个 -p 参数支持多个软件包
-c <main_category> # 主分类, 可以指定多个 -c 参数
--ignore-crashes # 忽略崩溃, 继续执行事件
--ignore-native-crashes # 忽略 native 崩溃, 继续执行事件
--ignore-timeouts # 忽略超时, 继续执行事件
--ignore-security-exceptions # 忽略安全异常, 继续执行事件
--monitor-native-crashes # 监控 native 崩溃
--kill-process-after-error # 发生错误时杀死进程
--hprof
--match-description <text>
--pct-touch <percent> # 触摸事件百分比, 例如指定触摸事件比例为 30%, 格式为: --pct-touch 30
--pct-motion <percent> # 手势动作事件百分比, 所有事件百分比之和不能超过 100%
--pct-trackball <percent> # 轨迹事件百分比
--pct-syskeys <percent> # 系统按键事件百分比
--pct-nav <percent> # 基本导航事件百分比
--pct-majornav <percent> # 主要导航事件百分比
--pct-appswitch <percent> # APP 切换事件百分比
--pct-flip <percent> # 弹事件百分比
--pct-anyevent <percent> # 其他事件百分比
--pct-pinchzoom <percent> # 缩放(捏)事件百分比
--pct-permission <percent> # 权限事件百分比
--pkg-blacklist-file <file> #
--pkg-whitelist-file <file> #
--wait-dbg # 如果 adb 断开, 等待 adb 连接, 直到 adb 恢复连接后继续执行 monkey
--dbg-no-events
--setup scriptfile
-f <scriptfile> # 指定用于测试的脚步文件, 可以指定多个 -f 参数
--port <port>
-s <seed> # 产生伪随机事件的种子, 相同的 -s 产生的事件流相同, 格式(可指定多个-s): -s 1
-v # 反馈信息级别, -v 越多个, 输如的日志信息越详细, 最多支持 3 个 -v
--throttle <ms> # 事件之间的间隔(单位为毫秒), 例如 200毫秒 的格式: --throttle 200
--randomize-throttle # 随机事件间隔时间
--profile-wait <ms> #
--device-sleep-time <ms> #
--randomize-script #
--script-log #
--bugreport #
--periodic-bugreport #
--permission-target-system #
命令示例:
在 com.example.app 这个 APP 上随机发送 10000 个事件
monkey -p com.example.app 10000
事件间隔10毫秒, 随机发送 10000 个事件
monkey -p com.example.app --throttle 10 10000
触屏事件占 30%, 手势事件占 10%, 发送 10000 个事件
monkey -p com.example.app --pct