我们查看官方文档,表里只给出了8种事件(可以看我上篇的翻译文档)。但我们运行Monkey后,却发现有11种事件!最坑爹的是,在每种事件的百分比后面,他还不给注明是什么事件!
原来不同的Android SDK中的Event percentages种类数和顺序是不一样的!
我们可以查看android-4.2.2_r1.2中的MonkeySourceRandom.java中定义的这些值:
- public static final int FACTOR_TOUCH = 0;
- public static final int FACTOR_MOTION = 1;
- public static final int FACTOR_PINCHZOOM = 2;
- public static final int FACTOR_TRACKBALL = 3;
- public static final int FACTOR_ROTATION = 4;
- public static final int FACTOR_NAV = 5;
- public static final int FACTOR_MAJORNAV = 6;
- public static final int FACTOR_SYSOPS = 7;
- public static final int FACTOR_APPSWITCH = 8;
- public static final int FACTOR_FLIP = 9;
- public static final int FACTOR_ANYTHING = 10;
- public static final int FACTORZ_COUNT = 11; // should be last+1
- private static final int GESTURE_TAP = 0;
- private static final int GESTURE_DRAG = 1;
- private static final int GESTURE_PINCH_OR_ZOOM = 2;
然后再来看Monkey.java源码中的processOptions()方法
- private boolean processOptions() {
- // quick (throwaway) check for unadorned command
- if (mArgs.length < 1) {
- showUsage();
- return false;
- }
- try {
- String opt;
- while ((opt = nextOption()) != null) {
- if (opt.equals("-s")) {
- mSeed = nextOptionLong("Seed");
- } else if (opt.equals("-p")) {
- mValidPackages.add(nextOptionData());
- } else if (opt.equals("-c")) {
- mMainCategories.add(nextOptionData());
- } else if (opt.equals("-v")) {
- mVerbose += 1;
- } else if (opt.equals("--ignore-crashes")) {
- mIgnoreCrashes = true;
- } else if (opt.equals("--ignore-timeouts")) {
- mIgnoreTimeouts = true;
- } else if (opt.equals("--ignore-security-exceptions")) {
- mIgnoreSecurityExceptions = true;
- } else if (opt.equals("--monitor-native-crashes")) {
- mMonitorNativeCrashes = true;
- } else if (opt.equals("--ignore-native-crashes")) {
- mIgnoreNativeCrashes = true;
- } else if (opt.equals("--kill-process-after-error")) {
- mKillProcessAfterError = true;
- } else if (opt.equals("--hprof")) {
- mGenerateHprof = true;
- } else if (opt.equals("--pct-touch")) {
- int i = MonkeySourceRandom.FACTOR_TOUCH;
- mFactors[i] = -nextOptionLong("touch events percentage");
- } else if (opt.equals("--pct-motion")) {
- int i = MonkeySourceRandom.FACTOR_MOTION;
- mFactors[i] = -nextOptionLong("motion events percentage");
- } else if (opt.equals("--pct-trackball")) {
- int i = MonkeySourceRandom.FACTOR_TRACKBALL;
- mFactors[i] = -nextOptionLong("trackball events percentage");
- } else if (opt.equals("--pct-rotation")) {
- int i = MonkeySourceRandom.FACTOR_ROTATION;
- mFactors[i] = -nextOptionLong("screen rotation events percentage");
- } else if (opt.equals("--pct-syskeys")) {
- int i = MonkeySourceRandom.FACTOR_SYSOPS;
- mFactors[i] = -nextOptionLong("system (key) operations percentage");
- } else if (opt.equals("--pct-nav")) {
- int i = MonkeySourceRandom.FACTOR_NAV;
- mFactors[i] = -nextOptionLong("nav events percentage");
- } else if (opt.equals("--pct-majornav")) {
- int i = MonkeySourceRandom.FACTOR_MAJORNAV;
- mFactors[i] = -nextOptionLong("major nav events percentage");
- } else if (opt.equals("--pct-appswitch")) {
- int i = MonkeySourceRandom.FACTOR_APPSWITCH;
- mFactors[i] = -nextOptionLong("app switch events percentage");
- } else if (opt.equals("--pct-flip")) {
- int i = MonkeySourceRandom.FACTOR_FLIP;
- mFactors[i] = -nextOptionLong("keyboard flip percentage");
- } else if (opt.equals("--pct-anyevent")) {
- int i = MonkeySourceRandom.FACTOR_ANYTHING;
- mFactors[i] = -nextOptionLong("any events percentage");
- } else if (opt.equals("--pct-pinchzoom")) {
- int i = MonkeySourceRandom.FACTOR_PINCHZOOM;
- mFactors[i] = -nextOptionLong("pinch zoom events percentage");
- } else if (opt.equals("--pkg-blacklist-file")) {
- mPkgBlacklistFile = nextOptionData();
- } else if (opt.equals("--pkg-whitelist-file")) {
- mPkgWhitelistFile = nextOptionData();
- } else if (opt.equals("--throttle")) {
- mThrottle = nextOptionLong("delay (in milliseconds) to wait between events");
- } else if (opt.equals("--randomize-throttle")) {
- mRandomizeThrottle = true;
- } else if (opt.equals("--wait-dbg")) {
- // do nothing - it's caught at the very start of run()
- } else if (opt.equals("--dbg-no-events")) {
- mSendNoEvents = true;
- } else if (opt.equals("--port")) {
- mServerPort = (int) nextOptionLong("Server port to listen on for commands");
- } else if (opt.equals("--setup")) {
- mSetupFileName = nextOptionData();
- } else if (opt.equals("-f")) {
- mScriptFileNames.add(nextOptionData());
- } else if (opt.equals("--profile-wait")) {
- mProfileWaitTime = nextOptionLong("Profile delay" +
- " (in milliseconds) to wait between user action");
- } else if (opt.equals("--device-sleep-time")) {
- mDeviceSleepTime = nextOptionLong("Device sleep time" +
- "(in milliseconds)");
- } else if (opt.equals("--randomize-script")) {
- mRandomizeScript = true;
- } else if (opt.equals("--script-log")) {
- mScriptLog = true;
- } else if (opt.equals("--bugreport")) {
- mRequestBugreport = true;
- } else if (opt.equals("--periodic-bugreport")){
- mGetPeriodicBugreport = true;
- mBugreportFrequency = nextOptionLong("Number of iterations");
- } else if (opt.equals("-h")) {
- showUsage();
- return false;
- } else {
- System.err.println("** Error: Unknown option: " + opt);
- showUsage();
- return false;
- }
- }
- } catch (RuntimeException ex) {
- System.err.println("** Error: " + ex.toString());
- showUsage();
- return false;
- }
- // If a server port hasn't been specified, we need to specify
- // a count
- if (mServerPort == -1) {
- String countStr = nextArg();
- if (countStr == null) {
- System.err.println("** Error: Count not specified");
- showUsage();
- return false;
- }
- try {
- mCount = Integer.parseInt(countStr);
- } catch (NumberFormatException e) {
- System.err.println("** Error: Count is not a number");
- showUsage();
- return false;
- }
- }
- return true;
- }
所以,Monkey运行结果中对应的就应该是:
0:--pct-touch//touch events percentage触摸事件百分比(触摸事件是一个在屏幕单一位置的按下-抬起事件)
1:--pct-motion//motion events percentage手势事件百分比(手势事件是由一个在屏幕某处的按下事件、一系列的伪随机移动、一个抬起事件组成)即一个滑动操作,但是是直线的,不能拐弯
2:--pct-pinchzoom//pinch zoom events percentage二指缩放百分比,即智能机上的放大缩小手势操作
3:--pct-trackball//trackball events percentage轨迹球事件百分比(轨迹球事件包括一个或多个随机移动,有时还伴有点击。轨迹球现在智能手机上已经没有了,就是类似手柄的方向键一样)
4:--pct-rotation//screen rotation events percentage屏幕旋转百分比,横屏竖屏
5:--pct-nav//nav events percentage”基本”导航事件百分比(导航事件包括上下左右,如方向输入设备的输入)老手机的上下左右键,智能机上没有
6:--pct-majornav//major nav events percentage”主要”导航事件百分比(这些导航事件通常会引发UI的事件,例如5-way pad的中间键、回退键、菜单键)
7:--pct-syskeys//system(key) operations percentage”系统”按钮事件百分比(这些按钮一般专供系统使用,如Home, Back, Start Call, End Call,音量控制)
8:--pct-appswitch//app switch events percentage启动activity事件百分比。在随机的间隔里,Monkey会执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法
9:--pct-flip//keyboard flip percentage键盘轻弹百分比,如点击输入框,键盘弹起,点击输入框以外区域,键盘收回
10:--pct-anyevent//anyevents percentage其他类型事件百分比。包括了其他所有的类型事件,如按键、其他不常用的设备上的按钮等等。
参考:
http://blog.csdn.net/jlminghui/article/details/42261307
http://blog.csdn.net/jlminghui/article/details/42268187
源码:
https://code.google.com/p/android-source-browsing/source/browse/cmds/monkey/src/com/android/commands/monkey/Monkey.java?repo=platform--development&name=android-4.2.2_r1.2
--------------------------------------------------------------------------------
关注微信公众号(测试工程师小站)即可在手机上查阅,并可接收更多测试分享,发送【测试资料】更可获取百G测试教程~