准备测试环境
准备Android SDK环境 下载 AndroidSDK
准备python环境 下载 python
APP的压测实践一
压测过程step1:手机调试到开发者选项,将USB调试选上。(【设置】-【关于手机】-【点击版本号5/6次】进入开发者选项,点击【开发人员选项】-【勾选USB调试】)
压测过程step2:确认手机和电脑已经成功连接,确认连接命令:adb devices
压测过程step3:安装测试APP 命令行 adb install package.apk
压测过程step4:发送压力指令:adb shell monkey 1000
压测过程setp5:获取app包名 adb logcat | grep START
cmp=包名/ 魔镜包名:com.cmiot.magicmirror
压测过程step6:给指定包打压力
adb shell monkey -p package 1000
Monkey高级参数的应用
1.throttle参数 指定事件之间的间隔
adb shell monkey --throttle < milliseconds >
adb shell monkey -p package --throttle 1000 10
2.seed参数 指定随机生成树的seed值
adb shell monkey -s < seed> < event-count>
adb shell monkey -p package -s 100 50
3.触摸事件
设定触摸事件百分比
adb shell monkey --pct-touch < percent>
adb shell monkey -p package --pct-touch 100 100
adb shell monkey -v -p package --pct-touch 100 100
4.动作事件
设定动作事件百分比
adb shell monkey --pct-motion < percent>
adb shell monkey -v -p package --pct-motion 100 100
5,轨迹球事件
设定轨迹球事件百分比
adb shell monkey --pct-trackball < percent>
6,基本导航事件
设定基本导航事件百分比,输入设备的上,下,左,右
adb shell monkey --pct-nav < percent>
7,主要导航事件
设定主要导航事件百分比,兼容中间键,返回键,菜单键
adb shell monkey --pct-majornav < percent>
8,系统导航事件
设定系统导航事件百分比,HOME,BACK,拨号及音量键
adb shell monkey --pct-syskeys < percent>
9,启动Activity事件
设定启动Activity的事件百分比
adb shell monkey --pct-appswitch < percent>
10,不常用事件
设定不常用事件的百分比
adb shell monkey --pct-anyevent < percent>
11,崩溃事件
忽略崩溃和异常 继续运行
adb shell monkey --ignore-crashes < event-count>
12,超时事件
忽略超时事件
adb shell monkey --ignore-timeouts < event-count>
adb shell monkey -v -p package --ignore-carshes --ignore-timeouts 100
Monkey Script常用命令介绍
执行Monkey脚本的命令:
adb shell monkey -f < scriptfile> < event-count>
scriptfile 是个脚本文件
1,DispatchTrackball 命令
2,DispatchPointer命令
3,DispatchString 命令
4,LaunchActivity 命令
5,UserWait命令
6,DispatchPress 命令
MonkeyScript实战
MonkeyScript脚本的编写
通过android-sdk 下面的uiautomatorviewer 中获取坐标点
adb push 脚本文件 /data/local/tmp/ 脚本复制到手机里面命令
monkey -f 脚本名 次数 在手机中执行脚本
比如我把脚本文件导入手机里的命令
adb push C:\Users\Administrator\Desktop\mook.script /data/local/tmp/
执行脚本的命令
adb shell monkey -f /data/local/tmp/mook.script 2
脚本文件内容
type=usercount=10speed=1.0start data >>LaunchActivity (com.test.demo,com.test.demo.MainActivity)UserWait(2000)DispatchPointer (10,10,0,100,50,1,1,-1,1,1,0,0)DispatchPointer (10,10,1,100,50,1,1,-1,1,1,0,0)DispatchString(test)UserWait(1000)DispatchPress(66)UserWait(1000)DispatchPointer (10,10,0,400,150,1,1,-1,1,1,0,0)DispatchPointer (10,10,1,400,150,1,1,-1,1,1,0,0)UserWait(6000) |
---|
Monkey Script常用命令介绍
monkeyrunner demo.py
#!/usr/bin/python#-*- UTF-8 -*-from com.android.monkeyrunner import MonkeyRunnerMonkeyRunner.alert ('Hello mook friends','This is title','Ok') |
---|
monkeyrunner编写的脚本截图
————————————————————
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有