2021-07-05

App压力测试
环境:win10
安卓环境
python环境
雷电模拟器
安卓测试包
安装包 adb install package.apk
adb shell monkey 1000,1000个随机指令
获取包名:adb shell “logcat | grep START”
退出adb shell “logcat | grep START” 命令:ctrl+C

cls清除屏幕

adb shell monkey -p com.changmi.calculator 1000
三、Monkey的基本命令
1、标准monkey命令:adb shell monkey -p com.android.calculator2 -v 50

-p:packageName

-v:日志级别

50:事件数

monkey 高级
1、throttle参数指定事件之间的间隔
adb shell monkey --throttle
例:adb shell monkey -p com.changmi.calculator --throttle 1000 10(10个事件,1000毫秒=1秒)

2、seed参数
monkey seed值操作一样
adb shell monkey -s
adb shell monkey -s com.changmi.calculator --throttle 1000 10
adb shell monkey -p com.changmi.calculator -s 100 50
3、触摸事件
adb shell monkey --pct-touch
eg:adb shell monkey -p com.changmi.calculator --pct-touch 100 100
adb shell monkey -v -p com.changmi.calculator --pct-touch 100 100(-v列出所有操作,)

4、动作事件
adb shell monkey --pct -motion
adb shell monkey -v -p com.changmi.calculator --pct-touch 50 --pct-motion 30 100

5、轨迹球事件 设定轨迹球事件百分比
adb shell monkey --pct-trackball

6、基本导航事件 设定基本导航事件百分比,输入设备的上、下、左、右
adb shell monkey --pct-nav

7、主要导航事件
设定主要导航事件百分比,兼容中间件、返回键、菜单按键
adb shell monkey --pct-majornav

8、系统导航事件
设定系统导航事件百分比,Home、BACK、拨号及音量键
adb shell monkey --pct-syskeys

9、启动activity事件
设定启动Activity的事件百分比
adb shell monkey --pct-apswitch

10、不常用事件
设定不常用事件的百分比
adb shell monkey --pct-anyevent

11、崩溃事件 忽略崩溃和异常
adb shell monkey --ingore-crashes

12、超时事件
忽略超时事件
adb shell monkey --ingore-timeouts0

例:
adb shell monkey -v -p com.changmi.calculator --pct-touch 50 --pct-motion 50 --ignore-crashes --ignore-timeouts 100

ANR异常测试结果析取:Application Not Responding)应用程序无响应

monkey Script
执行Monkey脚本的命令
adb shell monkey -f
1、dispatch trackball命令
轨迹球事件
DispatchTrackball(long downtime,long eventide,int action,float x,float y,float pressure,float size,int metastate,float xprecision,float yprecision,int device,int edgeflages)
long downtime 按下键的时间
long eventide事件发生的时间
int action 具体是按下还是弹起的过程
float x,float y x,y坐标点
float pressure 压力的事件,大小(0-1)
float size触摸的一个,大小(0-1)
int matastate当前按下mate键的标识
float xprecision x坐标的精确值
float yprecision y坐标的精确值
int device 事件的来源,事件范围(0-X),0表示不来自物理设备
int edgeflags超出的屏幕的范围
action 0表示按下,1表示弹起 x和y代表的坐标点
配对使用,实现点击

2、DispatchPointer 点击事件
DispatchPointerl(long downtime,long eventide,int action,float x,float y,float pressure,float size,int metastate,float xprecision,float yprecision,int device,int edgeflages)
配对使用,实现点击

3、DisPatchString 输入字符串事件
DispatchString(String text)

4、LaunchActivity 启动应用
LaunchActivity(package,Activity)

5、UserWait 等待事件
UserWait(1000)

6、DispatchPress命令
按下键值
DispatchPress(int keycode)#keycode 66 回车键

monkeyscript 实践
1、启动App
2、点击输入框
3、输入查询词
5、点击搜索按钮
6、等待结果的出现
7、点击clear按钮

将脚本文件放e盘根目录下
将E盘中的脚本发送到安卓目录下adb push E:\aa.script /sdcard/

adb shell monkey -f/sdcard/aa.txt 1执行脚本

脚本内容
type=user
count = 10
speed = 1.0
start data >>

LaunchActivity(com.changmi.calculator,com.changmi.calculator.CalculatorNormal)

MonkeyRunner
1、monkeyrunner api -alert警告框
void alert(string message,stringtitle,string okTitle)

2、MonkeyRunner Api -waitForConnection
等待设备连接,有多个device id,需要指明具体哪个设备
WaitForConnection(float timeout,string deviceid)

3、MonkeyDevce API - drag
拖动
drag(突破了 start,tuple end,float duration,inteher steps)
start 起点位置 end终点位置 duration 手势持续的时间
steps插值点的步数,默认10

4、MonkeyDevice API-press
按键
press(string 可以冲的,dictionary type)
keycode名,Down、Up\Down_and_up
5、startActivity
启动应用
startActivity(package+‘/’+activity)

6、touch
点击
touch(integer x,integer y, integer type)
x坐标值,y坐标值
type:Down,Up,Down_AND_UP

7、type输入
type(string message)

8、takeSnapshot
截屏
MonkeyImage takeSnapshot()

9、sameAs图像对比
boolean sameas(MonkeyImage other,float percent)

10、writetoFile
保存图像文件
void writeToFile(string path,string format)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值