原文地址https://blog.csdn.net/beyond_f/article/details/78543070

一、Monkey测试简介

Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕、滑动Trackball、按键等操作来对设备上的程序进行压力测试,检测程序多久的时间会发生异常。
  • Monkey程序由Android系统自带,使用Java语言写成,在Android文件系统中的存放路径是:/system/framework/monkey.jar;
  • Monkey.jar程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在Android文件系统中的存放路径是:/system/bin/ monkey;
  • 通过在CMD窗口中执行: adb shell monkey{+命令参数}来进行Monkey测试。(注意部分机型需要在开发者选项中勾选USB模拟点击,否则会不运行或报Kill问题)

二、Monkey参数

adb shell monkey –help可以查看详细命令

1) 参数 -p 指定一个或多个包 
指定包之后,Monkey将只允许系统启动指定的APP。如果不指定包,Monkey将允许系统启动设备中的所有APP。 
* 指定一个包: adb shell monkey -p com.htc.Weather 100 [100是事件计(即让Monkey程序模拟100次随机用户事件)]。 
* 指定多个包:adb shell monkey -p com.htc.Weather –p com.htc.pdfreader -p com.htc.photo.widgets 100 
* 不指定包:adb shell monkey 100 
2) 参数 -v 指定日志详细 
分为三级信息日志,-v -v -v三级日志最详细, -v一级日志缺省值信息量少 
日志级别 Level0 
* 示例 adb shell monkey -p com.ddinfo.ddmall –v 100,说明缺省值,仅提供启动提示、测试完成和最终结果等少量信息 
* 日志级别 Level 1 
示例 adb shell monkey -p com.ddinfo.ddmall –v -v 100,说明提供较为详细的日志,包括每个发送到Activity的事件信息 
* 日志级别 Level 2 
示例 adb shell monkey -p com.ddinfo.ddmall –v -v –v 100,说明最详细的日志,包括了测试中选中/未选中的Activity信息 
3) 参数 -s 用于指定伪随机数生成器的seed值 
如果seed相同,则两次Monkey测试所产生的事件序列也相同的。 
* Monkey测试1:adb shell monkey -p com.htc.Weather –s 10 100|| Monkey 测试2:adb shell monkey -p com.htc.Weather–s 10 100 运行展示的行为是完全一致的 
4) 参数 –throttle 模拟用户操作时间的延迟时间,单位是毫秒1000ms=1s 
* adb shell monkey -p com.htc.Weather –throttle 3000 100 
5) 参数 –ignore-crashes 
用于指定当应用程序崩溃时,Monkey是否停止运行。如果使用此参数,即使应用程序崩溃,Monkey依然会发送事件,直到事件计数完成。 
* 示例1:adb shellmonkey -p com.htc.Weather –ignore-crashes 1000 
测试过程中即使Weather程序崩溃,Monkey依然会继续发送事件直到事件数目达到1000为止; 
* 示例2:adb shellmonkey -p com.htc.Weather 1000 
测试过程中,如果Weather程序崩溃,Monkey将会停止运行。 
6) 参数 –ignore-timeouts 
用于指定当应用程序发生ANR(Application NoResponding)错误时,Monkey是否停止运行。如果使用此参数,即使应用程序发生ANR错误,Monkey依然会发送事件,直到事件计数完成。 
7) 参数 –ignore-security-exceptions 
用于指定当应用程序发生许可错误时(如证书许可,网络许可等),Monkey是否停止运行。如果使用此参数,即使应用程序发生许可错误,

8) 参数 –kill-process-after-error

用于指定当应用程序发生错误时,是否停止其运行。如果指定此参数,当应用程序发生错误时,应用程序停止运行并保持在当前状态(注意应用程序仅是静止在发生错误时的状态,系统并不会结束该应用程序的进程)。 
9) 参数 –monitor-native-crashes 
用于指定是否监视并报告应用程序发生崩溃的本地代码。 
10) 参数 –pct-{+事件类别}{+事件类别百分比} 
用于指定每种类别事件的数目百分比(在Monkey事件序列中,该类事件数目占总事件数目的百分比)

详细说明参数–pct-,并且主要分析log日志来说明monkey运行过程
  • –pct-touch+百分比 调整触摸事件的百分比,仅限于屏幕上某个点的down-up事件,adb shell monkey –pct-touch 100 -v -v -v 10 (为了说明–pct-touch参数,故意把百分比写满 100来分析问题,)
  1. 运行日志 备注{**内容}为个人后追加解释
  2. C:\Users\hahah>adb shell monkey --throttle 1000 --pct-touch 100 -v -v -v 10
  3. :Monkey: seed=1510815654118 count=10 {**未定义monkeyseed时随机定义一个seed值,count是事件综合10}
  4. :IncludeCategory: android.intent.category.LAUNCHER {**要运行的package内活动名}
  5. :IncludeCategory: android.intent.category.MONKEY {**要运行的package内活动名}
  6. // Selecting main activities from category android.intent.category.LAUNCHER {**选择主要activities,未定义包名则所有包活动都作为main activity}
  7. // + Using main activity com.android.gallery3d.vivo.GalleryTabActivity (from package com.vivo.gallery)
  8. // + Using main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  9. // + Using main activity com.android.contacts.DialtactsContactsEntryActivity (from package com.android.contacts)
  10. // + Using main activity com.android.dialer.TwelveKeyDialer (from package com.android.dialer)
  11. // + Using main activity com.vivo.email.activity.Welcome (from package com.vivo.email)
  12. // + Using main activity com.android.mms.ui.ConversationList (from package com.android.mms)
  13. // + Using main activity com.android.settings.Settings (from package com.android.settings)
  14. // + Using main activity com.android.bbksoundrecorder.SoundRecorder (from package com.android.bbksoundrecorder)
  15. // + Using main activity com.android.VideoPlayer.VideoPlayer (from package com.android.VideoPlayer)
  16. // + Using main activity com.bbk.calendar.MainActivity (from package com.bbk.calendar)
  17. // + Using main activity com.android.camera.CameraActivity (from package com.android.camera)
  18. // + Using main activity com.android.bbkmusic.WidgetToTrackActivity (from package com.android.bbkmusic)
  19. // + Using main activity com.chaozh.iReader.ui.activity.WelcomeActivity (from package com.chaozh.iReader)
  20. // + Using main activity com.bbk.theme.Theme (from package com.bbk.theme)
  21. // + Using main activity com.baidu.baidumaps.WelcomeScreen (from package com.baidu.BaiduMap)
  22. // + Using main activity com.tencent.assistant.activity.SplashActivity (from package com.tencent.android.qqdownloader)
  23. // + Using main activity com.android.bbkcalculator.Calculator (from package com.android.bbkcalculator)
  24. // + Using main activity com.bbk.cloud.activities.BBKCloudHomeScreen (from package com.bbk.cloud)
  25. // + Using main activity com.vivo.FMRadio.FMRadio (from package com.vivo.FMRadio)
  26. // + Using main activity com.android.filemanager.FileManagerActivity (from package com.android.filemanager)
  27. // + Using main activity com.android.notes.Notes (from package com.android.notes)
  28. // + Using main activity com.android.BBKClock.Timer (from package com.android.BBKClock)
  29. // + Using main activity com.vivo.weather.WeatherMain (from package com.vivo.weather)
  30. // + Using main activity com.vivo.compass.CalibrationActivity (from package com.vivo.compass)
  31. // + Using main activity com.iqoo.secure.MainGuideActivity (from package com.iqoo.secure)
  32. // + Using main activity com.vivo.Tips.MainActivity (from package com.vivo.Tips)
  33. // + Using main activity com.vivo.space.ui.LogoActivity (from package com.vivo.space)
  34. // + Using main activity com.bbk.appstore.ui.AppStore (from package com.bbk.appstore)
  35. // + Using main activity com.vivo.game.ui.LogoActivity (from package com.vivo.game)
  36. // + Using main activity com.vivo.browser.BrowserActivity (from package com.vivo.browser)
  37. // + Using main activity com.wuba.activity.launch.LaunchActivity (from package com.wuba)
  38. // + Using main activity com.ddinfo.ddmall.activity.menu.HelloActivity (from package com.ddinfo.ddmall)
  39. // + Using main activity com.sankuai.meituan.activity.Welcome (from package com.sankuai.meituan)
  40. // + Using main activity com.android.bbk.lockscreen3.LockScreenActivity (from package com.android.bbk.lockscreen3)
  41. // + Using main activity com.vivo.easyshare.activity.SplashScreenActivity (from package com.vivo.easyshare)
  42. // + Using main activity com.youku.phone.ActivityWelcome (from package com.youku.phone)
  43. // + Using main activity com.sina.weibo.SplashActivity (from package com.sina.weibo)
  44. // + Using main activity com.ss.android.article.news.activity.SplashBadgeActivity (from package com.ss.android.article.news)
  45. // + Using main activity com.tencent.mm.ui.LauncherUI (from package com.tencent.mm)
  46. // + Using main activity com.ddinfo.salesman.activity.LaunchActivity (from package com.ddinfo.salesman)
  47. // + Using main activity io.appium.settings.Settings (from package io.appium.settings)
  48. // + Using main activity com.sh.gj.MainActivity (from package com.sh.gj)
  49. // + Using main activity io.appium.unlock.Unlock (from package io.appium.unlock)
  50. // + Using main activity com.bbk.iqoo.feedback.activities.UserFeedBackActivity (from package com.bbk.iqoo.feedback)
  51. // + Using main activity com.jingdong.app.mall.main.MainActivity (from package com.jingdong.app.mall)
  52. // + Using main activity com.taobao.tao.welcome.Welcome (from package com.taobao.taobao)
  53. // + Using main activity com.tencent.mobileqq.activity.SplashActivity (from package com.tencent.mobileqq)
  54. // + Using main activity com.tencent.qqlive.ona.activity.WelcomeActivity (from package com.tencent.qqlive)
  55. // + Using main activity ctrip.business.splash.CtripSplashActivity (from package ctrip.android.view)
  56. // Selecting main activities from category android.intent.category.MONKEY
  57. // + Using main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  58. // + Using main activity com.android.settings.Settings$RunningServicesActivity (from package com.android.settings)
  59. // + Using main activity com.android.settings.Settings$StorageUseActivity (from package com.android.settings)
  60. // + Using main activity com.bbk.launcher2.Launcher (from package com.bbk.launcher2)
  61. // + Using main activity com.bbk.scene.launcher.theme.SceneLauncherThemeMainActivity (from package com.bbk.scene.launcher.theme)
  62. // + Using main activity com.iqoo.engineermode.EngineerMode (from package com.iqoo.engineermode)
  63. // + Using main activity com.android.systemui.vivo.common.monkeytest.MonkeyTestActivity (from package com.android.systemui)
  64. // Seeded: 1510815654118 {**seeded 种子同初始化一致}
  65. // Event percentages: {**事件百分比,可以都看到--pct-touch默认event类型为0,所有事件总和必为100%}
  66. // 0: 100.0%
  67. // 1: 0.0%
  68. // 2: 0.0%
  69. // 3: 0.0%
  70. // 4: -0.0%
  71. // 5: -0.0%
  72. // 6: 0.0%
  73. // 7: 0.0%
  74. // 8: 0.0%
  75. // 9: 0.0%
  76. // 10: 0.0%
  77. // 11: 0.0%
  78. {**跳转到主事件,未定义包则随机选中了com.bbk.iqoo.feedback,并且启动了.activities.UserFeedBackActivity}
  79. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.bbk.iqoo.feedback/.activities.UserFeedBackActivity;end
  80. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.bbk.iqoo.feedback/.activities.UserFeedBackActivity } in package com.bbk.iqoo.feedback {**代表允许此跳转}
  81. Sleeping for 1000 milliseconds
  82. :Sending Touch (ACTION_DOWN): 0:(167.0,734.0)
  83. :Sending Touch (ACTION_UP): 0:(178.81384,737.14557) {**sleep 1秒可以看出--pct-touchdown-up事件是两个步骤,但是作为一个整体动作,执行完毕然后进入延迟等待}
  84. Sleeping for 1000 milliseconds
  85. :Sending Touch (ACTION_DOWN): 0:(453.0,1107.0)
  86. :Sending Touch (ACTION_UP): 0:(440.52118,1109.9523)
  87. Sleeping for 1000 milliseconds
  88. :Sending Touch (ACTION_DOWN): 0:(56.0,500.0)
  89. :Sending Touch (ACTION_UP): 0:(53.049572,499.63184)
  90. Sleeping for 1000 milliseconds
  91. :Sending Touch (ACTION_DOWN): 0:(500.0,420.0)
  92. :Sending Touch (ACTION_UP): 0:(487.34482,410.93445)
  93. Sleeping for 1000 milliseconds
  94. :Sending Touch (ACTION_DOWN): 0:(170.0,1209.0)
  95. Events injected: 10 {**注入事件10,数一下动作只有9个,其实还有switch的一个启动动作,则共10个}
  96. :Sending rotation degree=0, persist=false {**发送屏幕翻转 度=0,存留=假}
  97. :Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0 {**丢弃:键=0,指针=0,轨迹球=0,键盘轻弹=0,屏幕翻转=0}
  98. ## Network stats: elapsed time=5064ms (0ms mobile, 0ms wifi, 5064ms not connected) {**网络状态:占用时间=5064ms(手机0ms,wifi0ms,未连接5064ms}
  99. // Monkey finished {**测试完成}
  100. C:\Users\hahah>
  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • –pct-motion+百分比 调整动作事件的百分比(动作事件由屏幕上某处的一个down事件、一系列的伪随机事件和一个up事件组成), 
    adb shell monkey -p com.ddinfo.ddmall –pct-motion 100 -v -v -v 10,如下新加package运行日志不相同点
  1. 运行日志 备注{**内容}为个人后追加解释
  2. C:\Users\hahah>adb shell monkey -p com.ddinfo.ddmall --pct-motion 100 -v -v -v 10
  3. :Monkey: seed=1510817506766 count=10
  4. :AllowPackage: com.ddinfo.ddmall {**定义了包,则只允许这个包运行}
  5. :IncludeCategory: android.intent.category.LAUNCHER
  6. :IncludeCategory: android.intent.category.MONKEY
  7. // Selecting main activities from category android.intent.category.LAUNCHER {**如下可以看到主活动除了定义的包的活动,其他都是not using不可用}
  8. // - NOT USING main activity com.android.gallery3d.vivo.GalleryTabActivity (from package com.vivo.gallery)
  9. // - NOT USING main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  10. // - NOT USING main activity com.android.contacts.DialtactsContactsEntryActivity (from package com.android.contacts)
  11. // - NOT USING main activity com.android.dialer.TwelveKeyDialer (from package com.android.dialer)
  12. // - NOT USING main activity com.vivo.email.activity.Welcome (from package com.vivo.email)
  13. // - NOT USING main activity com.android.mms.ui.ConversationList (from package com.android.mms)
  14. // - NOT USING main activity com.android.settings.Settings (from package com.android.settings)
  15. // - NOT USING main activity com.android.bbksoundrecorder.SoundRecorder (from package com.android.bbksoundrecorder)
  16. // - NOT USING main activity com.android.VideoPlayer.VideoPlayer (from package com.android.VideoPlayer)
  17. // - NOT USING main activity com.bbk.calendar.MainActivity (from package com.bbk.calendar)
  18. // - NOT USING main activity com.android.camera.CameraActivity (from package com.android.camera)
  19. // - NOT USING main activity com.android.bbkmusic.WidgetToTrackActivity (from package com.android.bbkmusic)
  20. // - NOT USING main activity com.chaozh.iReader.ui.activity.WelcomeActivity (from package com.chaozh.iReader)
  21. // - NOT USING main activity com.bbk.theme.Theme (from package com.bbk.theme)
  22. // - NOT USING main activity com.baidu.baidumaps.WelcomeScreen (from package com.baidu.BaiduMap)
  23. // - NOT USING main activity com.tencent.assistant.activity.SplashActivity (from package com.tencent.android.qqdownloader)
  24. // - NOT USING main activity com.android.bbkcalculator.Calculator (from package com.android.bbkcalculator)
  25. // - NOT USING main activity com.bbk.cloud.activities.BBKCloudHomeScreen (from package com.bbk.cloud)
  26. // - NOT USING main activity com.vivo.FMRadio.FMRadio (from package com.vivo.FMRadio)
  27. // - NOT USING main activity com.android.filemanager.FileManagerActivity (from package com.android.filemanager)
  28. // - NOT USING main activity com.android.notes.Notes (from package com.android.notes)
  29. // - NOT USING main activity com.android.BBKClock.Timer (from package com.android.BBKClock)
  30. // - NOT USING main activity com.vivo.weather.WeatherMain (from package com.vivo.weather)
  31. // - NOT USING main activity com.vivo.compass.CalibrationActivity (from package com.vivo.compass)
  32. // - NOT USING main activity com.iqoo.secure.MainGuideActivity (from package com.iqoo.secure)
  33. // - NOT USING main activity com.vivo.Tips.MainActivity (from package com.vivo.Tips)
  34. // - NOT USING main activity com.vivo.space.ui.LogoActivity (from package com.vivo.space)
  35. // - NOT USING main activity com.bbk.appstore.ui.AppStore (from package com.bbk.appstore)
  36. // - NOT USING main activity com.vivo.game.ui.LogoActivity (from package com.vivo.game)
  37. // - NOT USING main activity com.vivo.browser.BrowserActivity (from package com.vivo.browser)
  38. // - NOT USING main activity com.wuba.activity.launch.LaunchActivity (from package com.wuba)
  39. // + Using main activity com.ddinfo.ddmall.activity.menu.HelloActivity (from package com.ddinfo.ddmall) {** 可以看到定义的主活动名可以被使用}
  40. // - NOT USING main activity com.sankuai.meituan.activity.Welcome (from package com.sankuai.meituan)
  41. // - NOT USING main activity com.android.bbk.lockscreen3.LockScreenActivity (from package com.android.bbk.lockscreen3)
  42. // - NOT USING main activity com.vivo.easyshare.activity.SplashScreenActivity (from package com.vivo.easyshare)
  43. // - NOT USING main activity com.youku.phone.ActivityWelcome (from package com.youku.phone)
  44. // - NOT USING main activity com.sina.weibo.SplashActivity (from package com.sina.weibo)
  45. // - NOT USING main activity com.ss.android.article.news.activity.SplashBadgeActivity (from package com.ss.android.article.news)
  46. // - NOT USING main activity com.tencent.mm.ui.LauncherUI (from package com.tencent.mm)
  47. // - NOT USING main activity com.ddinfo.salesman.activity.LaunchActivity (from package com.ddinfo.salesman)
  48. // - NOT USING main activity io.appium.settings.Settings (from package io.appium.settings)
  49. // - NOT USING main activity com.sh.gj.MainActivity (from package com.sh.gj)
  50. // - NOT USING main activity io.appium.unlock.Unlock (from package io.appium.unlock)
  51. // - NOT USING main activity com.bbk.iqoo.feedback.activities.UserFeedBackActivity (from package com.bbk.iqoo.feedback)
  52. // - NOT USING main activity com.jingdong.app.mall.main.MainActivity (from package com.jingdong.app.mall)
  53. // - NOT USING main activity com.taobao.tao.welcome.Welcome (from package com.taobao.taobao)
  54. // - NOT USING main activity com.tencent.mobileqq.activity.SplashActivity (from package com.tencent.mobileqq)
  55. // - NOT USING main activity com.tencent.qqlive.ona.activity.WelcomeActivity (from package com.tencent.qqlive)
  56. // - NOT USING main activity ctrip.business.splash.CtripSplashActivity (from package ctrip.android.view)
  57. // Selecting main activities from category android.intent.category.MONKEY
  58. // - NOT USING main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  59. // - NOT USING main activity com.android.settings.Settings$RunningServicesActivity (from package com.android.settings)
  60. // - NOT USING main activity com.android.settings.Settings$StorageUseActivity (from package com.android.settings)
  61. // - NOT USING main activity com.bbk.launcher2.Launcher (from package com.bbk.launcher2)
  62. // - NOT USING main activity com.bbk.scene.launcher.theme.SceneLauncherThemeMainActivity (from package com.bbk.scene.launcher.theme)
  63. // - NOT USING main activity com.iqoo.engineermode.EngineerMode (from package com.iqoo.engineermode)
  64. // - NOT USING main activity com.android.systemui.vivo.common.monkeytest.MonkeyTestActivity (from package com.android.systemui)
  65. // Seeded: 1510817506766
  66. // Event percentages: {** 可以看到--pct-motion的event类型为1}
  67. // 0: 0.0%
  68. // 1: 100.0%
  69. // 2: 0.0%
  70. // 3: 0.0%
  71. // 4: -0.0%
  72. // 5: -0.0%
  73. // 6: 0.0%
  74. // 7: 0.0%
  75. // 8: 0.0%
  76. // 9: 0.0%
  77. // 10: 0.0%
  78. // 11: 0.0%
  79. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  80. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  81. Sleeping for 0 milliseconds
  82. :Sending Touch (ACTION_DOWN): 0:(244.0,931.0)
  83. :Sending Touch (ACTION_MOVE): 0:(257.84354,936.4823)
  84. :Sending Touch (ACTION_MOVE): 0:(271.68744,940.2001)
  85. :Sending Touch (ACTION_MOVE): 0:(281.8605,941.76605)
  86. :Sending Touch (ACTION_MOVE): 0:(287.41925,943.70874)
  87. :Sending Touch (ACTION_MOVE): 0:(295.70917,954.2028)
  88. :Sending Touch (ACTION_MOVE): 0:(298.17896,958.79175)
  89. :Sending Touch (ACTION_MOVE): 0:(304.72922,965.4881)
  90. :Sending Touch (ACTION_MOVE): 0:(306.156,970.51776)
  91. Events injected: 10
  92. :Sending rotation degree=0, persist=false
  93. :Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
  94. ## Network stats: elapsed time=48ms (0ms mobile, 0ms wifi, 48ms not connected)
  95. // Monkey finished
  96. C:\Users\hahah>
  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • –pct-trackball+百分比,调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击),adb shell monkey -p com.ddinfo.ddmall –pct-trackball 30 1000
  1. 部分日志
  2. :Sending Trackball (ACTION_MOVE): 0:(1.0,3.0)
  3. :Sending Trackball (ACTION_MOVE): 0:(-3.0,4.0)
  4. :Sending Trackball (ACTION_MOVE): 0:(1.0,2.0)
  5. :Sending Trackball (ACTION_MOVE): 0:(-1.0,-1.0)
  6. :Sending Trackball (ACTION_MOVE): 0:(-2.0,-4.0)
  7. :Sending Trackball (ACTION_MOVE): 0:(-5.0,0.0)
  8. :Sending Trackball (ACTION_MOVE): 0:(3.0,-4.0)
  9. :Sending Trackball (ACTION_MOVE): 0:(2.0,-4.0)
  10. :Sending Trackball (ACTION_MOVE): 0:(2.0,-2.0)
  11. :Sending Trackball (ACTION_MOVE): 0:(0.0,0.0)
  12. :Sending Trackball (ACTION_MOVE): 0:(-5.0,-3.0)
  13. :Sending Trackball (ACTION_MOVE): 0:(-5.0,-1.0)
  14. :Sending Trackball (ACTION_MOVE): 0:(0.0,-3.0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • –pct-nav+百分比,调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成),adb shell monkey –pct-nav 40 1000,类似于上下左右滑动
  1. 部分日志
  2. :Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
  3. :Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT
  4. Sleeping for 1000 milliseconds
  5. :Sending Key (ACTION_DOWN): 19 // KEYCODE_DPAD_UP
  6. :Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP
  7. Sleeping for 1000 milliseconds
  8. :Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
  9. :Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT
  10. Sleeping for 1000 milliseconds
  11. :Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
  12. Events injected: 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • –pct-majornav +百分比,调整“主要”导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:5-way键盘的中间按键、回退按键、菜单按键),adb shell monkey –pct-majornav 100 10
  1. 部分日志
  2. Sleeping for 1000 milliseconds
  3. :Sending Key (ACTION_DOWN): 23 // KEYCODE_DPAD_CENTER
  4. :Sending Key (ACTION_UP): 23 // KEYCODE_DPAD_CENTER
  5. Sleeping for 1000 milliseconds
  6. // activityResuming(com.bbk.appstore)
  7. // activityResuming(com.bbk.appstore)
  8. // activityResuming(com.bbk.appstore)
  9. :Sending Key (ACTION_DOWN): 82 // KEYCODE_MENU
  10. :Sending Key (ACTION_UP): 82 // KEYCODE_MENU
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • –pct-syskeys +百分比,调整“系统”按键事件的百分比(这些按键通常被保留,由系统使用,如Home、Back、Start Call、End Call及音量控制键),adb shell monkey –pct-syskeys 60 1000,注意被音量控制键坑
  1. 部分日志
  2. :Sending Key (ACTION_DOWN): 25 // KEYCODE_VOLUME_DOWN
  3. :Sending Key (ACTION_UP): 25 // KEYCODE_VOLUME_DOWN
  4. Sleeping for 1000 milliseconds
  5. :Sending Key (ACTION_DOWN): 24 // KEYCODE_VOLUME_UP
  6. :Sending Key (ACTION_UP): 24 // KEYCODE_VOLUME_UP
  7. Sleeping for 1000 milliseconds
  8. :Sending Key (ACTION_DOWN): 25 // KEYCODE_VOLUME_DOWN
  9. :Sending Key (ACTION_UP): 25 // KEYCODE_VOLUME_DOWN
  10. Sleeping for 1000 milliseconds
  11. :Sending Key (ACTION_DOWN): 4 // KEYCODE_BACK
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • –pct-appswitch +百分比,调整启动Activity的百分比。在随机间隔里,Monkey将执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法,adb shell monkey -p com.ddinfo.ddmall –pct-appswitch 70 1000,也就是保持当前app的几率
  1. 部分日志
  2. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  3. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  4. Sleeping for 10000 milliseconds
  5. // Allowing start of Intent { cmp=com.ddinfo.ddmall/.activity.menu.MenuActivity } in package com.ddinfo.ddmall
  6. // activityResuming(com.ddinfo.ddmall)
  7. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  8. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  9. Sleeping for 10000 milliseconds
  10. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  11. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  12. Sleeping for 10000 milliseconds
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • –pct-anyevent +百分比,调整其它类型事件的百分比。它包罗了所有其它类型的事件,如:按键、其它不常用的设备按钮、等等,不常用

三.停止monkey命令

  • adb shell ps | findstr com.android.commands.monkey 返回第一个数字即是monkey的pid
  • adb shell kill pid,结束进程

一、Monkey测试简介

Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕、滑动Trackball、按键等操作来对设备上的程序进行压力测试,检测程序多久的时间会发生异常。
  • Monkey程序由Android系统自带,使用Java语言写成,在Android文件系统中的存放路径是:/system/framework/monkey.jar;
  • Monkey.jar程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在Android文件系统中的存放路径是:/system/bin/ monkey;
  • 通过在CMD窗口中执行: adb shell monkey{+命令参数}来进行Monkey测试。(注意部分机型需要在开发者选项中勾选USB模拟点击,否则会不运行或报Kill问题)

二、Monkey参数

adb shell monkey –help可以查看详细命令

1) 参数 -p 指定一个或多个包 
指定包之后,Monkey将只允许系统启动指定的APP。如果不指定包,Monkey将允许系统启动设备中的所有APP。 
* 指定一个包: adb shell monkey -p com.htc.Weather 100 [100是事件计(即让Monkey程序模拟100次随机用户事件)]。 
* 指定多个包:adb shell monkey -p com.htc.Weather –p com.htc.pdfreader -p com.htc.photo.widgets 100 
* 不指定包:adb shell monkey 100 
2) 参数 -v 指定日志详细 
分为三级信息日志,-v -v -v三级日志最详细, -v一级日志缺省值信息量少 
日志级别 Level0 
* 示例 adb shell monkey -p com.ddinfo.ddmall –v 100,说明缺省值,仅提供启动提示、测试完成和最终结果等少量信息 
* 日志级别 Level 1 
示例 adb shell monkey -p com.ddinfo.ddmall –v -v 100,说明提供较为详细的日志,包括每个发送到Activity的事件信息 
* 日志级别 Level 2 
示例 adb shell monkey -p com.ddinfo.ddmall –v -v –v 100,说明最详细的日志,包括了测试中选中/未选中的Activity信息 
3) 参数 -s 用于指定伪随机数生成器的seed值 
如果seed相同,则两次Monkey测试所产生的事件序列也相同的。 
* Monkey测试1:adb shell monkey -p com.htc.Weather –s 10 100|| Monkey 测试2:adb shell monkey -p com.htc.Weather–s 10 100 运行展示的行为是完全一致的 
4) 参数 –throttle 模拟用户操作时间的延迟时间,单位是毫秒1000ms=1s 
* adb shell monkey -p com.htc.Weather –throttle 3000 100 
5) 参数 –ignore-crashes 
用于指定当应用程序崩溃时,Monkey是否停止运行。如果使用此参数,即使应用程序崩溃,Monkey依然会发送事件,直到事件计数完成。 
* 示例1:adb shellmonkey -p com.htc.Weather –ignore-crashes 1000 
测试过程中即使Weather程序崩溃,Monkey依然会继续发送事件直到事件数目达到1000为止; 
* 示例2:adb shellmonkey -p com.htc.Weather 1000 
测试过程中,如果Weather程序崩溃,Monkey将会停止运行。 
6) 参数 –ignore-timeouts 
用于指定当应用程序发生ANR(Application NoResponding)错误时,Monkey是否停止运行。如果使用此参数,即使应用程序发生ANR错误,Monkey依然会发送事件,直到事件计数完成。 
7) 参数 –ignore-security-exceptions 
用于指定当应用程序发生许可错误时(如证书许可,网络许可等),Monkey是否停止运行。如果使用此参数,即使应用程序发生许可错误,

8) 参数 –kill-process-after-error

用于指定当应用程序发生错误时,是否停止其运行。如果指定此参数,当应用程序发生错误时,应用程序停止运行并保持在当前状态(注意应用程序仅是静止在发生错误时的状态,系统并不会结束该应用程序的进程)。 
9) 参数 –monitor-native-crashes 
用于指定是否监视并报告应用程序发生崩溃的本地代码。 
10) 参数 –pct-{+事件类别}{+事件类别百分比} 
用于指定每种类别事件的数目百分比(在Monkey事件序列中,该类事件数目占总事件数目的百分比)

详细说明参数–pct-,并且主要分析log日志来说明monkey运行过程
  • –pct-touch+百分比 调整触摸事件的百分比,仅限于屏幕上某个点的down-up事件,adb shell monkey –pct-touch 100 -v -v -v 10 (为了说明–pct-touch参数,故意把百分比写满 100来分析问题,)
  1. 运行日志 备注{**内容}为个人后追加解释
  2. C:\Users\hahah>adb shell monkey --throttle 1000 --pct-touch 100 -v -v -v 10
  3. :Monkey: seed=1510815654118 count=10 {**未定义monkeyseed时随机定义一个seed值,count是事件综合10}
  4. :IncludeCategory: android.intent.category.LAUNCHER {**要运行的package内活动名}
  5. :IncludeCategory: android.intent.category.MONKEY {**要运行的package内活动名}
  6. // Selecting main activities from category android.intent.category.LAUNCHER {**选择主要activities,未定义包名则所有包活动都作为main activity}
  7. // + Using main activity com.android.gallery3d.vivo.GalleryTabActivity (from package com.vivo.gallery)
  8. // + Using main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  9. // + Using main activity com.android.contacts.DialtactsContactsEntryActivity (from package com.android.contacts)
  10. // + Using main activity com.android.dialer.TwelveKeyDialer (from package com.android.dialer)
  11. // + Using main activity com.vivo.email.activity.Welcome (from package com.vivo.email)
  12. // + Using main activity com.android.mms.ui.ConversationList (from package com.android.mms)
  13. // + Using main activity com.android.settings.Settings (from package com.android.settings)
  14. // + Using main activity com.android.bbksoundrecorder.SoundRecorder (from package com.android.bbksoundrecorder)
  15. // + Using main activity com.android.VideoPlayer.VideoPlayer (from package com.android.VideoPlayer)
  16. // + Using main activity com.bbk.calendar.MainActivity (from package com.bbk.calendar)
  17. // + Using main activity com.android.camera.CameraActivity (from package com.android.camera)
  18. // + Using main activity com.android.bbkmusic.WidgetToTrackActivity (from package com.android.bbkmusic)
  19. // + Using main activity com.chaozh.iReader.ui.activity.WelcomeActivity (from package com.chaozh.iReader)
  20. // + Using main activity com.bbk.theme.Theme (from package com.bbk.theme)
  21. // + Using main activity com.baidu.baidumaps.WelcomeScreen (from package com.baidu.BaiduMap)
  22. // + Using main activity com.tencent.assistant.activity.SplashActivity (from package com.tencent.android.qqdownloader)
  23. // + Using main activity com.android.bbkcalculator.Calculator (from package com.android.bbkcalculator)
  24. // + Using main activity com.bbk.cloud.activities.BBKCloudHomeScreen (from package com.bbk.cloud)
  25. // + Using main activity com.vivo.FMRadio.FMRadio (from package com.vivo.FMRadio)
  26. // + Using main activity com.android.filemanager.FileManagerActivity (from package com.android.filemanager)
  27. // + Using main activity com.android.notes.Notes (from package com.android.notes)
  28. // + Using main activity com.android.BBKClock.Timer (from package com.android.BBKClock)
  29. // + Using main activity com.vivo.weather.WeatherMain (from package com.vivo.weather)
  30. // + Using main activity com.vivo.compass.CalibrationActivity (from package com.vivo.compass)
  31. // + Using main activity com.iqoo.secure.MainGuideActivity (from package com.iqoo.secure)
  32. // + Using main activity com.vivo.Tips.MainActivity (from package com.vivo.Tips)
  33. // + Using main activity com.vivo.space.ui.LogoActivity (from package com.vivo.space)
  34. // + Using main activity com.bbk.appstore.ui.AppStore (from package com.bbk.appstore)
  35. // + Using main activity com.vivo.game.ui.LogoActivity (from package com.vivo.game)
  36. // + Using main activity com.vivo.browser.BrowserActivity (from package com.vivo.browser)
  37. // + Using main activity com.wuba.activity.launch.LaunchActivity (from package com.wuba)
  38. // + Using main activity com.ddinfo.ddmall.activity.menu.HelloActivity (from package com.ddinfo.ddmall)
  39. // + Using main activity com.sankuai.meituan.activity.Welcome (from package com.sankuai.meituan)
  40. // + Using main activity com.android.bbk.lockscreen3.LockScreenActivity (from package com.android.bbk.lockscreen3)
  41. // + Using main activity com.vivo.easyshare.activity.SplashScreenActivity (from package com.vivo.easyshare)
  42. // + Using main activity com.youku.phone.ActivityWelcome (from package com.youku.phone)
  43. // + Using main activity com.sina.weibo.SplashActivity (from package com.sina.weibo)
  44. // + Using main activity com.ss.android.article.news.activity.SplashBadgeActivity (from package com.ss.android.article.news)
  45. // + Using main activity com.tencent.mm.ui.LauncherUI (from package com.tencent.mm)
  46. // + Using main activity com.ddinfo.salesman.activity.LaunchActivity (from package com.ddinfo.salesman)
  47. // + Using main activity io.appium.settings.Settings (from package io.appium.settings)
  48. // + Using main activity com.sh.gj.MainActivity (from package com.sh.gj)
  49. // + Using main activity io.appium.unlock.Unlock (from package io.appium.unlock)
  50. // + Using main activity com.bbk.iqoo.feedback.activities.UserFeedBackActivity (from package com.bbk.iqoo.feedback)
  51. // + Using main activity com.jingdong.app.mall.main.MainActivity (from package com.jingdong.app.mall)
  52. // + Using main activity com.taobao.tao.welcome.Welcome (from package com.taobao.taobao)
  53. // + Using main activity com.tencent.mobileqq.activity.SplashActivity (from package com.tencent.mobileqq)
  54. // + Using main activity com.tencent.qqlive.ona.activity.WelcomeActivity (from package com.tencent.qqlive)
  55. // + Using main activity ctrip.business.splash.CtripSplashActivity (from package ctrip.android.view)
  56. // Selecting main activities from category android.intent.category.MONKEY
  57. // + Using main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  58. // + Using main activity com.android.settings.Settings$RunningServicesActivity (from package com.android.settings)
  59. // + Using main activity com.android.settings.Settings$StorageUseActivity (from package com.android.settings)
  60. // + Using main activity com.bbk.launcher2.Launcher (from package com.bbk.launcher2)
  61. // + Using main activity com.bbk.scene.launcher.theme.SceneLauncherThemeMainActivity (from package com.bbk.scene.launcher.theme)
  62. // + Using main activity com.iqoo.engineermode.EngineerMode (from package com.iqoo.engineermode)
  63. // + Using main activity com.android.systemui.vivo.common.monkeytest.MonkeyTestActivity (from package com.android.systemui)
  64. // Seeded: 1510815654118 {**seeded 种子同初始化一致}
  65. // Event percentages: {**事件百分比,可以都看到--pct-touch默认event类型为0,所有事件总和必为100%}
  66. // 0: 100.0%
  67. // 1: 0.0%
  68. // 2: 0.0%
  69. // 3: 0.0%
  70. // 4: -0.0%
  71. // 5: -0.0%
  72. // 6: 0.0%
  73. // 7: 0.0%
  74. // 8: 0.0%
  75. // 9: 0.0%
  76. // 10: 0.0%
  77. // 11: 0.0%
  78. {**跳转到主事件,未定义包则随机选中了com.bbk.iqoo.feedback,并且启动了.activities.UserFeedBackActivity}
  79. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.bbk.iqoo.feedback/.activities.UserFeedBackActivity;end
  80. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.bbk.iqoo.feedback/.activities.UserFeedBackActivity } in package com.bbk.iqoo.feedback {**代表允许此跳转}
  81. Sleeping for 1000 milliseconds
  82. :Sending Touch (ACTION_DOWN): 0:(167.0,734.0)
  83. :Sending Touch (ACTION_UP): 0:(178.81384,737.14557) {**sleep 1秒可以看出--pct-touchdown-up事件是两个步骤,但是作为一个整体动作,执行完毕然后进入延迟等待}
  84. Sleeping for 1000 milliseconds
  85. :Sending Touch (ACTION_DOWN): 0:(453.0,1107.0)
  86. :Sending Touch (ACTION_UP): 0:(440.52118,1109.9523)
  87. Sleeping for 1000 milliseconds
  88. :Sending Touch (ACTION_DOWN): 0:(56.0,500.0)
  89. :Sending Touch (ACTION_UP): 0:(53.049572,499.63184)
  90. Sleeping for 1000 milliseconds
  91. :Sending Touch (ACTION_DOWN): 0:(500.0,420.0)
  92. :Sending Touch (ACTION_UP): 0:(487.34482,410.93445)
  93. Sleeping for 1000 milliseconds
  94. :Sending Touch (ACTION_DOWN): 0:(170.0,1209.0)
  95. Events injected: 10 {**注入事件10,数一下动作只有9个,其实还有switch的一个启动动作,则共10个}
  96. :Sending rotation degree=0, persist=false {**发送屏幕翻转 度=0,存留=假}
  97. :Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0 {**丢弃:键=0,指针=0,轨迹球=0,键盘轻弹=0,屏幕翻转=0}
  98. ## Network stats: elapsed time=5064ms (0ms mobile, 0ms wifi, 5064ms not connected) {**网络状态:占用时间=5064ms(手机0ms,wifi0ms,未连接5064ms}
  99. // Monkey finished {**测试完成}
  100. C:\Users\hahah>
  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • –pct-motion+百分比 调整动作事件的百分比(动作事件由屏幕上某处的一个down事件、一系列的伪随机事件和一个up事件组成), 
    adb shell monkey -p com.ddinfo.ddmall –pct-motion 100 -v -v -v 10,如下新加package运行日志不相同点
  1. 运行日志 备注{**内容}为个人后追加解释
  2. C:\Users\hahah>adb shell monkey -p com.ddinfo.ddmall --pct-motion 100 -v -v -v 10
  3. :Monkey: seed=1510817506766 count=10
  4. :AllowPackage: com.ddinfo.ddmall {**定义了包,则只允许这个包运行}
  5. :IncludeCategory: android.intent.category.LAUNCHER
  6. :IncludeCategory: android.intent.category.MONKEY
  7. // Selecting main activities from category android.intent.category.LAUNCHER {**如下可以看到主活动除了定义的包的活动,其他都是not using不可用}
  8. // - NOT USING main activity com.android.gallery3d.vivo.GalleryTabActivity (from package com.vivo.gallery)
  9. // - NOT USING main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  10. // - NOT USING main activity com.android.contacts.DialtactsContactsEntryActivity (from package com.android.contacts)
  11. // - NOT USING main activity com.android.dialer.TwelveKeyDialer (from package com.android.dialer)
  12. // - NOT USING main activity com.vivo.email.activity.Welcome (from package com.vivo.email)
  13. // - NOT USING main activity com.android.mms.ui.ConversationList (from package com.android.mms)
  14. // - NOT USING main activity com.android.settings.Settings (from package com.android.settings)
  15. // - NOT USING main activity com.android.bbksoundrecorder.SoundRecorder (from package com.android.bbksoundrecorder)
  16. // - NOT USING main activity com.android.VideoPlayer.VideoPlayer (from package com.android.VideoPlayer)
  17. // - NOT USING main activity com.bbk.calendar.MainActivity (from package com.bbk.calendar)
  18. // - NOT USING main activity com.android.camera.CameraActivity (from package com.android.camera)
  19. // - NOT USING main activity com.android.bbkmusic.WidgetToTrackActivity (from package com.android.bbkmusic)
  20. // - NOT USING main activity com.chaozh.iReader.ui.activity.WelcomeActivity (from package com.chaozh.iReader)
  21. // - NOT USING main activity com.bbk.theme.Theme (from package com.bbk.theme)
  22. // - NOT USING main activity com.baidu.baidumaps.WelcomeScreen (from package com.baidu.BaiduMap)
  23. // - NOT USING main activity com.tencent.assistant.activity.SplashActivity (from package com.tencent.android.qqdownloader)
  24. // - NOT USING main activity com.android.bbkcalculator.Calculator (from package com.android.bbkcalculator)
  25. // - NOT USING main activity com.bbk.cloud.activities.BBKCloudHomeScreen (from package com.bbk.cloud)
  26. // - NOT USING main activity com.vivo.FMRadio.FMRadio (from package com.vivo.FMRadio)
  27. // - NOT USING main activity com.android.filemanager.FileManagerActivity (from package com.android.filemanager)
  28. // - NOT USING main activity com.android.notes.Notes (from package com.android.notes)
  29. // - NOT USING main activity com.android.BBKClock.Timer (from package com.android.BBKClock)
  30. // - NOT USING main activity com.vivo.weather.WeatherMain (from package com.vivo.weather)
  31. // - NOT USING main activity com.vivo.compass.CalibrationActivity (from package com.vivo.compass)
  32. // - NOT USING main activity com.iqoo.secure.MainGuideActivity (from package com.iqoo.secure)
  33. // - NOT USING main activity com.vivo.Tips.MainActivity (from package com.vivo.Tips)
  34. // - NOT USING main activity com.vivo.space.ui.LogoActivity (from package com.vivo.space)
  35. // - NOT USING main activity com.bbk.appstore.ui.AppStore (from package com.bbk.appstore)
  36. // - NOT USING main activity com.vivo.game.ui.LogoActivity (from package com.vivo.game)
  37. // - NOT USING main activity com.vivo.browser.BrowserActivity (from package com.vivo.browser)
  38. // - NOT USING main activity com.wuba.activity.launch.LaunchActivity (from package com.wuba)
  39. // + Using main activity com.ddinfo.ddmall.activity.menu.HelloActivity (from package com.ddinfo.ddmall) {** 可以看到定义的主活动名可以被使用}
  40. // - NOT USING main activity com.sankuai.meituan.activity.Welcome (from package com.sankuai.meituan)
  41. // - NOT USING main activity com.android.bbk.lockscreen3.LockScreenActivity (from package com.android.bbk.lockscreen3)
  42. // - NOT USING main activity com.vivo.easyshare.activity.SplashScreenActivity (from package com.vivo.easyshare)
  43. // - NOT USING main activity com.youku.phone.ActivityWelcome (from package com.youku.phone)
  44. // - NOT USING main activity com.sina.weibo.SplashActivity (from package com.sina.weibo)
  45. // - NOT USING main activity com.ss.android.article.news.activity.SplashBadgeActivity (from package com.ss.android.article.news)
  46. // - NOT USING main activity com.tencent.mm.ui.LauncherUI (from package com.tencent.mm)
  47. // - NOT USING main activity com.ddinfo.salesman.activity.LaunchActivity (from package com.ddinfo.salesman)
  48. // - NOT USING main activity io.appium.settings.Settings (from package io.appium.settings)
  49. // - NOT USING main activity com.sh.gj.MainActivity (from package com.sh.gj)
  50. // - NOT USING main activity io.appium.unlock.Unlock (from package io.appium.unlock)
  51. // - NOT USING main activity com.bbk.iqoo.feedback.activities.UserFeedBackActivity (from package com.bbk.iqoo.feedback)
  52. // - NOT USING main activity com.jingdong.app.mall.main.MainActivity (from package com.jingdong.app.mall)
  53. // - NOT USING main activity com.taobao.tao.welcome.Welcome (from package com.taobao.taobao)
  54. // - NOT USING main activity com.tencent.mobileqq.activity.SplashActivity (from package com.tencent.mobileqq)
  55. // - NOT USING main activity com.tencent.qqlive.ona.activity.WelcomeActivity (from package com.tencent.qqlive)
  56. // - NOT USING main activity ctrip.business.splash.CtripSplashActivity (from package ctrip.android.view)
  57. // Selecting main activities from category android.intent.category.MONKEY
  58. // - NOT USING main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
  59. // - NOT USING main activity com.android.settings.Settings$RunningServicesActivity (from package com.android.settings)
  60. // - NOT USING main activity com.android.settings.Settings$StorageUseActivity (from package com.android.settings)
  61. // - NOT USING main activity com.bbk.launcher2.Launcher (from package com.bbk.launcher2)
  62. // - NOT USING main activity com.bbk.scene.launcher.theme.SceneLauncherThemeMainActivity (from package com.bbk.scene.launcher.theme)
  63. // - NOT USING main activity com.iqoo.engineermode.EngineerMode (from package com.iqoo.engineermode)
  64. // - NOT USING main activity com.android.systemui.vivo.common.monkeytest.MonkeyTestActivity (from package com.android.systemui)
  65. // Seeded: 1510817506766
  66. // Event percentages: {** 可以看到--pct-motion的event类型为1}
  67. // 0: 0.0%
  68. // 1: 100.0%
  69. // 2: 0.0%
  70. // 3: 0.0%
  71. // 4: -0.0%
  72. // 5: -0.0%
  73. // 6: 0.0%
  74. // 7: 0.0%
  75. // 8: 0.0%
  76. // 9: 0.0%
  77. // 10: 0.0%
  78. // 11: 0.0%
  79. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  80. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  81. Sleeping for 0 milliseconds
  82. :Sending Touch (ACTION_DOWN): 0:(244.0,931.0)
  83. :Sending Touch (ACTION_MOVE): 0:(257.84354,936.4823)
  84. :Sending Touch (ACTION_MOVE): 0:(271.68744,940.2001)
  85. :Sending Touch (ACTION_MOVE): 0:(281.8605,941.76605)
  86. :Sending Touch (ACTION_MOVE): 0:(287.41925,943.70874)
  87. :Sending Touch (ACTION_MOVE): 0:(295.70917,954.2028)
  88. :Sending Touch (ACTION_MOVE): 0:(298.17896,958.79175)
  89. :Sending Touch (ACTION_MOVE): 0:(304.72922,965.4881)
  90. :Sending Touch (ACTION_MOVE): 0:(306.156,970.51776)
  91. Events injected: 10
  92. :Sending rotation degree=0, persist=false
  93. :Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
  94. ## Network stats: elapsed time=48ms (0ms mobile, 0ms wifi, 48ms not connected)
  95. // Monkey finished
  96. C:\Users\hahah>
  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • –pct-trackball+百分比,调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击),adb shell monkey -p com.ddinfo.ddmall –pct-trackball 30 1000
  1. 部分日志
  2. :Sending Trackball (ACTION_MOVE): 0:(1.0,3.0)
  3. :Sending Trackball (ACTION_MOVE): 0:(-3.0,4.0)
  4. :Sending Trackball (ACTION_MOVE): 0:(1.0,2.0)
  5. :Sending Trackball (ACTION_MOVE): 0:(-1.0,-1.0)
  6. :Sending Trackball (ACTION_MOVE): 0:(-2.0,-4.0)
  7. :Sending Trackball (ACTION_MOVE): 0:(-5.0,0.0)
  8. :Sending Trackball (ACTION_MOVE): 0:(3.0,-4.0)
  9. :Sending Trackball (ACTION_MOVE): 0:(2.0,-4.0)
  10. :Sending Trackball (ACTION_MOVE): 0:(2.0,-2.0)
  11. :Sending Trackball (ACTION_MOVE): 0:(0.0,0.0)
  12. :Sending Trackball (ACTION_MOVE): 0:(-5.0,-3.0)
  13. :Sending Trackball (ACTION_MOVE): 0:(-5.0,-1.0)
  14. :Sending Trackball (ACTION_MOVE): 0:(0.0,-3.0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • –pct-nav+百分比,调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成),adb shell monkey –pct-nav 40 1000,类似于上下左右滑动
  1. 部分日志
  2. :Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
  3. :Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT
  4. Sleeping for 1000 milliseconds
  5. :Sending Key (ACTION_DOWN): 19 // KEYCODE_DPAD_UP
  6. :Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP
  7. Sleeping for 1000 milliseconds
  8. :Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
  9. :Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT
  10. Sleeping for 1000 milliseconds
  11. :Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
  12. Events injected: 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • –pct-majornav +百分比,调整“主要”导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:5-way键盘的中间按键、回退按键、菜单按键),adb shell monkey –pct-majornav 100 10
  1. 部分日志
  2. Sleeping for 1000 milliseconds
  3. :Sending Key (ACTION_DOWN): 23 // KEYCODE_DPAD_CENTER
  4. :Sending Key (ACTION_UP): 23 // KEYCODE_DPAD_CENTER
  5. Sleeping for 1000 milliseconds
  6. // activityResuming(com.bbk.appstore)
  7. // activityResuming(com.bbk.appstore)
  8. // activityResuming(com.bbk.appstore)
  9. :Sending Key (ACTION_DOWN): 82 // KEYCODE_MENU
  10. :Sending Key (ACTION_UP): 82 // KEYCODE_MENU
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • –pct-syskeys +百分比,调整“系统”按键事件的百分比(这些按键通常被保留,由系统使用,如Home、Back、Start Call、End Call及音量控制键),adb shell monkey –pct-syskeys 60 1000,注意被音量控制键坑
  1. 部分日志
  2. :Sending Key (ACTION_DOWN): 25 // KEYCODE_VOLUME_DOWN
  3. :Sending Key (ACTION_UP): 25 // KEYCODE_VOLUME_DOWN
  4. Sleeping for 1000 milliseconds
  5. :Sending Key (ACTION_DOWN): 24 // KEYCODE_VOLUME_UP
  6. :Sending Key (ACTION_UP): 24 // KEYCODE_VOLUME_UP
  7. Sleeping for 1000 milliseconds
  8. :Sending Key (ACTION_DOWN): 25 // KEYCODE_VOLUME_DOWN
  9. :Sending Key (ACTION_UP): 25 // KEYCODE_VOLUME_DOWN
  10. Sleeping for 1000 milliseconds
  11. :Sending Key (ACTION_DOWN): 4 // KEYCODE_BACK
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • –pct-appswitch +百分比,调整启动Activity的百分比。在随机间隔里,Monkey将执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法,adb shell monkey -p com.ddinfo.ddmall –pct-appswitch 70 1000,也就是保持当前app的几率
  1. 部分日志
  2. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  3. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  4. Sleeping for 10000 milliseconds
  5. // Allowing start of Intent { cmp=com.ddinfo.ddmall/.activity.menu.MenuActivity } in package com.ddinfo.ddmall
  6. // activityResuming(com.ddinfo.ddmall)
  7. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  8. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  9. Sleeping for 10000 milliseconds
  10. :Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ddinfo.ddmall/.activity.menu.HelloActivity;end
  11. // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ddinfo.ddmall/.activity.menu.HelloActivity } in package com.ddinfo.ddmall
  12. Sleeping for 10000 milliseconds
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • –pct-anyevent +百分比,调整其它类型事件的百分比。它包罗了所有其它类型的事件,如:按键、其它不常用的设备按钮、等等,不常用

三.停止monkey命令

  • adb shell ps | findstr com.android.commands.monkey 返回第一个数字即是monkey的pid
  • adb shell kill pid,结束进程

monkey基础学习的更多相关文章

  1. salesforce 零基础学习(五十二)Trigger使用篇(二)

    第十七篇的Trigger用法为通过Handler方式实现Trigger的封装,此种好处是一个Handler对应一个sObject,使本该在Trigger中写的代码分到Handler中,代码更加清晰. ...

  2. 如何从零基础学习VR

    转载请声明转载地址:http://www.cnblogs.com/Rodolfo/,违者必究. 近期很多搞技术的朋友问我,如何步入VR的圈子?如何从零基础系统性的学习VR技术? 本人将于2017年1月 ...

  3. IOS基础学习-2: UIButton

    IOS基础学习-2: UIButton   UIButton是一个标准的UIControl控件,UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedContro ...

  4. HTML5零基础学习Web前端需要知道哪些?

    HTML零基础学习Web前端网页制作,首先是要掌握一些常用标签的使用和他们的各个属性,常用的标签我总结了一下有以下这些: html:页面的根元素. head:页面的头部标签,是所有头部元素的容器. b ...

  5. python入门到精通[三]:基础学习(2)

    摘要:Python基础学习:列表.元组.字典.函数.序列化.正则.模块. 上一节学习了字符串.流程控制.文件及目录操作,这节介绍下列表.元组.字典.函数.序列化.正则.模块. 1.列表 python中 ...

  6. python入门到精通[二]:基础学习(1)

    摘要:Python基础学习: 注释.字符串操作.用户交互.流程控制.导入模块.文件操作.目录操作. 上一节讲了分别在windows下和linux下的环境配置,这节以linux为例学习基本语法.代码部分 ...

  7. CSS零基础学习笔记.

    酸菜记 之 CSS的零基础. 这篇是我自己从零基础学习CSS的笔记加理解总结归纳的,如有不对的地方,请留言指教, 学前了解: CSS中字母是不分大小写的; CSS文件可以使用在各种程序文件中(如:PH ...

  8. Yaf零基础学习总结5-Yaf类的自动加载

    Yaf零基础学习总结5-Yaf类的自动加载 框架的一个重要功能就是类的自动加载了,在第一个demo的时候我们就约定自己的项目的目录结构,框架就基于这个目录结构来自动加载需要的类文件. Yaf在自启动的 ...

  9. Yaf零基础学习总结4-Yaf的配置文件

    在上一节的hello yaf当中我们已经接触过了yaf的配置文件了, Yaf和用户共用一个配置空间, 也就是在Yaf_Application初始化时刻给出的配置文件中的配置. 作为区别, Yaf的配置 ...

随机推荐

  1. ubuntu zip解压

    您好,zip xx.zip压缩,unzip xx.zip 解压,tar zcvf xx.tar.gz压缩tar zxvf xx.tar.gz解压

  2. Credential

    https://www.cnblogs.com/Hawk-Hong/p/4293651.html 在项目开发,我们经常会使用WebService,但在使用WebService时我们经常会考虑以下问题: ...

  3. C#设计模式系列:抽象工厂模式(AbstractFactory)

    出自:http://www.cnblogs.com/libingql/archive/2012/12/09/2809754.html 1. 抽象工厂模式简介 1.1 定义 抽象工厂(Abstract ...

  4. swift swift学习笔记--函数和闭包

    使用 func来声明一个函数.通过在名字之后在圆括号内添加一系列参数来调用这个方法.使用 ->来分隔形式参数名字类型和函数返回的类型 func greet(person: String, day ...

  5. mysql 中实现行变列

    前言: mysql行列变化,最难的就是将多个列变成多行,使用的比较多的是统计学中行变列,列变行,没有找到现成的函数或者语句,所以自己写了存储过程,使用动态sql来实现,应用业务场景,用户每个月都有使用 ...

  6. 利用maven将jar包添加到本地仓库中

    mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar ...

  7. mybatis-spring-1.2.1 jar下载、源码下载

    http://www.everycoding.com/maven2/org/mybatis/mybatis-spring/1.2.1.html

  8. 演示PostgreSQL的详细安装及配置图解

    右击文件选择以管理员身份运行 2 开始执行程序的安装 3 设置安装目录 4 设置数据的保存目录 5 设置数据库管理员密码,请牢记此密码. 6 设置端口号,选择默认的端口号即可 7 根据自己选择设置地区 ...

  9. mysql使用笔记(一)

    一.安装 使用免安装的版本进行安装: 1. 解压到安装目录 2. 拷贝目录下的 my-default.ini 文件为 my.ini 文件 3. 修改my.ini 文件内容为 [client] port ...

  10. java基础---->多线程之interrupt(九)

    这里我们通过实例来学习一下java多线程中关于interrupt方法的一些知识.执者失之.我想当一个诗人的时候,我就失去了诗,我想当一个人的时候,我就失去了我自己.在你什么也不想要的时候,一切如期而来 ...