目录
- 1. Android Maxim介绍
- 2. Android Maxim使用方法
- 3.Android Maxim运行命令
- 4.Android Maxim的策略
- 5.实例演示——Windows系统,使用AVD模拟器,系统 Android6.0
1. Android Maxim介绍
Android Maxim是基于遍历规则的高性能Android Monkey,适用于真机/模拟器的APP UI压力测试。对以下内容进行改进:
- Android Maxim有自己的遍历规则,可以使用几个变量规则去优化Monkey 的操作。
- Android Maxim的性能高,而且还支持Monkey的相关命令。
2. Android Maxim使用方法
-
第一步:去官方clone Maxim的github:http://github.com/zhangzhao4444/Maxim
注意:Maxim不是所有都开源的
-
第二步:将 framework.jar , monkey.jar push 到手机上某个目录中,建议
/sdcard
-
adb push framework.jar /sdcard
-
adb push monkey.jar /sdcard
-
3.Android Maxim运行命令
adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p [App包名] --uiautomatormix`` --running-minutes [执行时间] -v -v
-
CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar
:设置两个jar包的路径 -
exec app_process /system/bin tv.panda.test.monkey.Monkey
:固定写法。执行app_process,/system/bin tv.panda.test.monkey.Monkey
是Monke的入口函数。 -
-p [App包名]
:指定要运行的包名,例如:-p com.xueqiu.android
表示运行雪球app -
--uiautomatormix
:遍历策略,表名使用Mix模式,uiautomator和monkey混合使用策略。 -
--running-minutes [运行时长]
:设置运行时长,单位分钟。例如:--running-minutes 60
表示运行时长为60分钟 -
-v -v
:详细日志
4.Android Maxim的策略
-
模式 Mix
- 基于事件概率的压力测试
- 参数:
--uiautomatormix
- 说明:
- 直接使用底层accessibiltyserver获取界面接口解析各控件
- 随机选取一个控件执行touch操作。
- 同时与原monkey 其他操作按比例混合使用
- 默认:accessibilityserver action占比50%,其余各action分剩余的50%
- 参数:
--pct-uiautomatormix [百分比]
- 使用此参数可设置accessibilityserver action占比。
- 例如
--pct-uiautomatormix 80
,是将accessibilityserver action占比提高到80%
-
模式 DFS
- 深度遍历算法
- 参数:
--uiautomatordfs
- 注意:Android5 不支持 dfs
-
模式Troy:
-
控件选择策略按max.xpath.selector配置的高低优先级来进行深度遍历
-
参数:
--uiautomatortroy
-
5.实例演示——Windows系统,使用AVD模拟器,系统 Android6.0
- 第一步:克隆Maxim项目
-
进入要放置Maxim项目的文件夹中,选择空白处右击然后选择GitBash,输入命令:
git clone https://github.com/zhangzhao4444/Maxim.git
- Maxim已经成功clone下来:
- 第二步:启动AVD,运行命令,将两个重要jar包(framework.jar和monkey.jar)push到模拟器中
注意:
push的时候不要使用Git Bash,因为Git Bash会把命令中的"/"当做系统的C盘(Windows)。使用Windows自带的Powershell进行push操作即可。
push的时候先进入Maxim文件夹下,或者可以在push的时候写全framework.jar和monkey.jar的路径
- 使用
adb push .\framework.jar /sdcard
和adb push .\monkey.jar /sdcard
命令将两个jar包push到模拟器中:
-
验证模拟器中是否存在两个jar包:
查看后可发现两个jar已经被成功push到模拟器中:
- 运行执行Maxim的命令
adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p com.xueqiu.android --uiautomatormix --running-minutes 60 -v -v
- 执行运行命令,把包名修改成我们要测试的软件:雪球。可以根据自己需求添加参数,或修改其他参数。
-
运行日志展示(部分):
version:1.0.21.0612.2259.. ..:...t.. Maxim .h....i.. . ....... . ..sisandroidmonkeystreste.sttoolMaxim.thistool..helpyoutofoundappcrash.thi..stooluserandomordfsalgorithm:..smonkeyMaxim machine gunmonkey....monkey,..,monkeymonkeym,..,onkeym..onkeymon..keymon.keymonke..ymonkeym.,onkeymonkeymonkeymonkeymonkeymon.key..monkeymonkeymonkeymonkeymonkeymonkeym..onkeymonkeymonkeythxforphdguxiaotian.:.anythingUcancontactpanda_zzaqq77227005. .. .[Maxim] // Monkey: seed=1668811682454 count=1000[Maxim] // Selecting main activities from category android.intent.category.LAUNCHER [Maxim] // - Not Using main activity com.android.contacts.activities.PeopleActivity (from package com.android.contacts [Maxim] // - Not Using main activity com.android.dialer.DialtactsActivity (from package com.android.dialer [Maxim] // - Not Using main activity com.android.settings.Settings (from package com.android.settings[Maxim] // - Not Using main activity com.android.browser.BrowserActivity (from package com.android.browser [Maxim] // - Not Using main activity com.android.calendar.AllInOneActivity (from package com.android.calendar [Maxim] // - Not Using main activity com.android.deskclock.DeskClock (from package com.android.deskclock [Maxim] // - Not Using main activity com.android.email.activity.Welcome (from package com.android.email [Maxim] // - Not Using main activity com.android.camera.GalleryPicker (from package com.android.gallery [Maxim] // - Not Using main activity com.android.camera.Camera (from package com.android.camera [Maxim] // - Not Using main activity com.android.music.MusicBrowserActivity (from package com.android.music [Maxim] // - Not Using main activity com.android.messaging.ui.conversationlist.ConversationListActivity (from package com.android.messaging [Maxim] // - Not Using main activity com.example.android.apis.ApiDemos (from package com.example.android.apis [Maxim] // - Not Using main activity com.android.gesture.builder.GestureBuilderActivity (from package com.android.gesture.builder [Maxim] // - Not Using main activity com.android.widgetpreview.WidgetPreviewActivity (from package com.android.widgetpreview [Maxim] // - Not Using main activity com.android.backuptester.MainActivity (from package com.android.backuptester [Maxim] // - Not Using main activity com.android.calculator2.Calculator (from package com.android.calculator2 [Maxim] // - Not Using main activity com.android.customlocale2.CustomLocaleActivity (from package com.android.customlocale2 [Maxim] // - Not Using main activity com.android.development.Development (from package com.android.development [Maxim] // - Not Using main activity android.app.AliasActivity (from package com.android.development_settings [Maxim] // - Not Using main activity com.android.providers.downloads.ui.DownloadList (from package com.android.providers.downloads.ui [Maxim] // - Not Using main activity com.android.quicksearchbox.SearchActivity (from package com.android.quicksearchbox [Maxim] // - Not Using main activity io.appium.settings.Settings (from package io.appium.settings [Maxim] // + Using main activity com.xueqiu.android.view.WelcomeActivityAlias (from package com.xueqiu.android) [Maxim] // Selecting main activities from category android.intent.category.MONKEY [Maxim] // - Not Using main activity com.android.launcher3.Launcher (from package com.android.launcher3 [Maxim] // - Not Using main activity com.android.settings.Settings$RunningServicesActivity (from package com.android.settings [Maxim] // - Not Using main activity com.android.settings.Settings$StorageUseActivity (from package com.android.settings [Maxim] // Add Package To PackageWhiteList : com.oppo.camera [Maxim] // Add Package To PackageWhiteList : com.android.packageinstaller [Maxim] // Add Package To PackageWhiteList : com.android.documentsui [Maxim] // AllowPackage: com.xueqiu.android [Maxim] // AllowPackage: com.oppo.camera [Maxim] // AllowPackage: com.android.packageinstaller [Maxim] // AllowPackage: com.android.documentsui [Maxim] // IncludeCategory: android.intent.category.LAUNCHER [Maxim] // IncludeCategory: android.intent.category.MONKEY [Maxim] // Special Event: [Maxim] // Black Widget List: [Maxim] // InputMethod ID: InputMethodInfo{com.android.inputmethod.latin/.LatinIME, settings: com.android.inputmethod.latin.settings.SettingsActivity}.id [Maxim] // Device Info: unknown-Android SDK built for x86_64, Android Version: 6.0 [Maxim] strategy : uiautomator-Mix.[Maxim] // Targeted packages and permissions: [Maxim] // [Maxim] // Fuzz Null Intent: [Maxim] // com.xueqiu.android.common.splash.SplashActivity [Maxim] // com.xueqiu.android.view.WelcomeActivityAlias [Maxim] // com.xueqiu.android.community.PostStatusActivity [Maxim] // com.xueqiu.android.community.AccountBindingActivity [Maxim] // com.xueqiu.android.message.SelectTalkActivity [Maxim] // com.xueqiu.android.common.account.LoginActivity [Maxim] // com.xueqiu.android.wxapi.WXEntryActivity [Maxim] // com.xueqiu.android.wxapi.WXPayEntryActivity [Maxim] // com.xueqiu.android.stock.stockdetail.StockDetailShortcutActivity [Maxim] // com.xueqiu.android.base.push.PushIntentActivity [Maxim] // com.xueqiu.fund.commonlib.FundMainActivity [Maxim] // com.sina.weibo.sdk.share.WbShareTransActivity [Maxim] // com.sina.weibo.sdk.share.WbShareToStoryActivity [Maxim] // com.alipay.sdk.app.PayResultActivity // Event percentages: // TOUCH : 62.5% // MOTION : 10.0% // PINCHZOOM : 4.0% // TRACKBALL : 5.0% // ROTATION : 5.0% // PERMISSION : -0.0% // NAV : -0.0% // MAJORNAV : -0.0% // SYSOPS : -0.0% // APPSWITCH : 1.0% // FLIP : 1.0% // ANYTHING : -0.0% // BACK : 10.0% // MUTE : 1.0% // SCHEMA : -0.0% // NULLINTENT : 0.2% // RESET : 0.3% [Maxim] // event0, 2022-11-17 03:16:35.732 [Maxim] // Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.xueqiu.android/.view.WelcomeActivityAlias;end [Maxim] // the top activity is com.xueqiu.android.view.WelcomeActivityAlias, phone launcher activity is com.android.launcher3.Launcher [Maxim] // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xueqiu.android/.view.WelcomeActivityAlias } in package com.xueqiu.android [Maxim] // : debug, currentActivity is com.xueqiu.android.common.MainActivity [Maxim] // event1, 2022-11-17 03:16:35.754 [Maxim] // Sleeping for 0 milliseconds [Maxim] // event1, 2022-11-17 03:16:35.755 [Maxim] // Sleeping for 6000 milliseconds [Maxim] // event1, 2022-11-17 03:16:41.758 [Maxim] // Sleeping for 0 milliseconds [Maxim] Random Number = 0.80452955 [Maxim] random hit trackball [Maxim] // event1, 2022-11-17 03:16:41.787 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(3.0,64.0) [Maxim] // event2, 2022-11-17 03:16:41.797 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(-5.0,64.0) [Maxim] // event3, 2022-11-17 03:16:41.799 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(-3.0,64.0) [Maxim] // event4, 2022-11-17 03:16:41.802 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(-3.0,64.0) [Maxim] // event5, 2022-11-17 03:16:41.803 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(-3.0,64.0) [Maxim] // event6, 2022-11-17 03:16:41.808 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(3.0,64.0) [Maxim] // event7, 2022-11-17 03:16:41.810 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(4.0,64.0) [Maxim] // event8, 2022-11-17 03:16:41.816 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(-2.0,64.0) [Maxim] // event9, 2022-11-17 03:16:41.818 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(-3.0,64.0) [Maxim] // event10, 2022-11-17 03:16:41.822 [Maxim] :Sending Trackball (ACTION_MOVE): 0:(3.0,64.0) [Maxim] Random Number = 0.6914952