一.环境
- 1.安装jdk和安卓sdk
- 2.安装模拟器或者准备一个真机
二.介绍
使用adb命令adb shell monkey -help,来看一下帮助文档
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
[-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
[--ignore-crashes] [--ignore-timeouts]
[--ignore-security-exceptions]
[--monitor-native-crashes] [--ignore-native-crashes]
[--kill-process-after-error] [--hprof]
[--match-description TEXT]
[--pct-touch PERCENT] [--pct-motion PERCENT]
[--pct-trackball PERCENT] [--pct-syskeys PERCENT]
[--pct-nav PERCENT] [--pct-majornav PERCENT]
[--pct-appswitch PERCENT] [--pct-flip PERCENT]
[--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]
[--pct-permission PERCENT]
[--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]
[--pkg-whitelist-file PACKAGE_WHITELIST_FILE]
[--wait-dbg] [--dbg-no-events]
[--setup scriptfile] [-f scriptfile [-f scriptfile] ...]
[--port port]
[-s SEED] [-v [-v] ...]
[--throttle MILLISEC] [--randomize-throttle]
[--profile-wait MILLISEC]
[--device-sleep-time MILLISEC]
[--randomize-script]
[--script-log]
[--bugreport]
[--periodic-bugreport]
[--permission-target-system]
COUNT
| 命令 | 作用 | 说明 |
|---|---|---|
| -p | 要测试的包名 | 不填随机选一个 |
| -c | 指定categrory | |
| --ignore-crashes | 忽略崩溃 | 奔溃继续 |
| --ignore-timeouts | 忽略超时 | ANR时继续 |
| --ignore-security-exceptions | 忽略安全异常 | |
| --monitor-native-crashes | 监听native奔溃 | |
| --ignore-native-crashes | 忽略native异常 | |
| --kill-process-after-error | 发生错误后杀掉进程 | |
| --pct-touch PERCENT | 触摸事件百分比 | |
| --pct-motion PERCENT | 滑动事件百分比 | |
| --pct-syskeys PERCENT | 系统物理按键事件百分比 | Home、Back、音量等 |
| --pct-appswitch PERCENT | Activity启动的百分比 | |
| -s | 伪随机数生成器的seed值 | 使用相同的seed值会产生相同的随机事件流 |
| -v | 日志 | -v较少信息,-v -v较多,-v -v -v详细 |
| --throttle | 事件之间的延迟 | 毫秒 |
三.简单使用
adb shell monkey -p com.xxx.yyy 1000 //随机1000次操作
adb shell monkey -p com.xxx.yyy 1000 -v -v -v //详细的日志
adb shell monkey --throttle 100 -p com.xxx.yyy 1000 //每次从操作延迟100毫秒
adb shell monkey --pct-motion 20 -p com.xxx.yyy 1000 //滑动事件占20%










网友评论