android 轨迹球事件,Android压力测试

原标题:Android压力测试

来源:http://www.uml.org.cn

准备测试环境

准备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 常用命令介绍

执行Monkey脚本的命令:

adb shell monkey -f < file> < event-count>

file 是个脚本文件

1,DispatchTrackball 命令

74c3f28d0ccfd1ea22b9266c69f4cf9b.png

2,DispatchPointer命令

39d9220d8c4399bb36b4dab5b085661b.png

3,DispatchString 命令

ff3f58be25c79d557ced8a957de39e1f.png

4,LaunchActivity 命令

ce42fd154e307b34607275be4032a032.png

5,UserWait命令

3ebaf9cf3f920611db2fd95d6991d25d.png

6,DispatchPress 命令

72f12a379e2d58c407355481222d5bd0.png

Monkey实战

Monkey脚本的编写

fcf820e7f780a95954e659bf3749ab9e.png

通过android-sdk 下面的uiautomatorviewer 中获取坐标点

adb push 脚本文件 /data/local/tmp/ 脚本复制到手机里面命令

monkey -f 脚本名 次数 在手机中执行脚本

比如我把脚本文件导入手机里的命令

adb push C:UsersAdministratorDesktopmook. /data/local/tmp/

执行脚本的命令

adb shell monkey -f /data/local/tmp/mook. 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 常用命令介绍

98f1e86260761ad455e2e11c0ceeeb97.png

monkeyrunner demo.py

#!/usr/bin/python

#-*- UTF-8 -*-

from com.android.monkeyrunner import MonkeyRunner

MonkeyRunner.alert ('Hello mook friends','This is title','Ok')

cc5f3fb1dd0d952a9e14fef0facd6e9a.png

fd91cc145e68b73ee2578b5eec45bd28.png

f92384a610eb5f7a791505187d6fa555.png

4c7d1f094a2bcbbe992faae58e6f9dfb.png

f6e9512df28cc8bc11d6bbbd7b6d8ea1.png

27d5b88e9b97fcd857289aaaf6765191.png

323d9fe99edb5f49e635afe4f3113dca.png

ac9826a03cae25cce63fbf4a95751455.png

monkeyrunner编写的脚本截图

80887f77f41d0ab2c2958034ec41237f.png

责任编辑:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值