Android自动化测试之MonkeyRunner录制和回放脚本 android monkey脚本
转载
Monkey用法
伪随机(pseudo-random)
- 的用户事件流(如按键输入、触摸屏输入、手势输入等),可以对待测的目标应用或整个 Android 系统进行压力测试。因此 Monkey 测试是一种为了测试软件的稳定性、健壮性的快速有效的方法
- 基本语法:
| $ adb shell monkey [options] <event-count>
|
options
,即类似于使用命令adb shell monkey 1000
,那么将会对整个系统中安装的 package 发送事件流,换种说法就是对整个 Android 系统进行 Monkey 压力测试
这是一个对指定应用(Android自带的系统设置
应用)进行 Monkey 测试的例子,发送的事件流数目为1000:
| adb shell monkey -p com.android.settings 1000
|
Monkey 命令选项
adb shell monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| 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]
[--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]
[--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]
COUNT
|
• —ignore-crashes
• —ignore-timeouts
• —ignore-security-exceptions
• —monitor-native-crashes
• —ignore-native-crashes
• —kill-process-after-error
• —hprof 指定该选项后,monkey会在发送事件完成后生成性能报告,报告一般存放于/data/misc目录下,对报告的分析,需要使用Traceview
• —pct-touch
• —pct-motion
• —pct-trackball
• —pct-syskeys
• —pct-nav
• —pct-majornav
• —pct-appswitch
• —pct-pinchzoom
• —pct-anyevent
• -s
• -v
• —throttle
• COUNT
结束Monkey进程
执行 Monkey 的过程中如果想中途停止 Monkey 程序的运行,需要将 Monkey 的进程杀掉。
findstr
grep
adb shell ps | findstr monkey
adb shell kill 进程ID
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。