编辑推荐: |
本文主要介绍APP的压测实践,Monkey高级参数的应用,Monkey
Script常用命令介绍,MonkeyScript实战等内容。。
本文来自于博客园,由火龙果软件Alice编辑、推荐。 |
|
准备测试环境
准备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 命令
![](images/2020082521.png)
2,DispatchPointer命令
![](images/2020082522.png)
3,DispatchString 命令 ![](images/2020082523.png)
4,LaunchActivity 命令 ![](images/2020082524.png)
5,UserWait命令 ![](images/2020082525.png)
6,DispatchPress 命令 ![](images/2020082526.png)
MonkeyScript实战
MonkeyScript脚本的编写 ![](images/2020082527.png)
通过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=user
count=10
speed=1.0
start 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常用命令介绍 ![](images/2020082529.png)
monkeyrunner demo.py
#!/usr/bin/python
#-*- UTF-8 -*-
from com.android.monkeyrunner import MonkeyRunner
MonkeyRunner.alert ('Hello mook friends','This
is title','Ok') |
![](images/20200825210.png) ![](images/20200825211.png) ![](images/20200825212.png) ![](images/20200825213.png) ![](images/20200825214.png) ![](images/20200825215.png) ![](images/20200825216.png) ![](images/20200825217.png)
monkeyrunner编写的脚本截图 ![](images/20200825218.png)
![](images/20200825219.png)
|