Monkey测试使用指南
2019-04-28 本文已影响0人
ByteCarry
Monkey测试使用指南
环境准备
- JDK
- Android SDK
- Python
-
JDK-安装并配置好环境变量,测试JDK正常
$ java -version java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
-
Android Sdk-安装好SDK并配置环境变量,命令行工具位于:SDK_DIR/tools,monkeyrunner位于:SDK_DIR/tools/bin
$ monkeyrunner Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35) [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_151 >>>
-
Python
$ python Python 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
1. 交互式命令
- 基本语法
adb shell monkey -p your.package.name -v 500
更多参数参考:http://www.android-doc.com/tools/help/monkey.html
2. Monkey Script
Monkey script 是按照一定的语法规则编写有序的用户事件流并适用于monkey命令工具的脚本
首先编写脚本文件,保存为monkey_xxx.script,eg:
#Start Script
type = user
count = 49
speed = 1.0
start data >>
LaunchActivity(com.pull2me.cuckooweather,com.pull2me.cuckooweather.activity.MainActivity)
UserWait(5000)
#open cuckooweather
captureDispatchPointer(5109520,5109520,0,1150,330,0,0,0,0,0,0,0);
captureDispatchPointer(5109521,5109521,1,1150,330,0,0,0,0,0,0,0);
UserWait(3000)//1150,330 区域
#close browser
captureDispatchPointer(5109520,5109520,0,205,31,0,0,0,0,0,0,0);//0代表down
captureDispatchPointer(5109521,5109521,1,205,31,0,0,0,0,0,0,0);//1代表up
UserWait(2000)
然后将脚本上传到设备的sdcard中:
$ adb push /Users/xxx/Documents/monkeyscript/monkey_xxx.script /mnt/sdcard/myscript/monkey_xxx.script
通过adb shell monkey命令执行脚本,结果保存到/Users/xxx/Documents/monkeyscript/result/result_xxx.txt中:
$ adb shell monkey -v -v -f /mnt/sdcard/myscript/monkey_xxx.script --throttle 2000 5 > /Users/xxx/Documents/monkeyscript/result/result_xxx.txt
3. Monkeyrunner
monkeyrunner工具提供了Android代码之外的手段控制Android设备,你能够编写Python程序安装应用或者测试包,启动运行、发送按键事件、截取屏幕视图并保存。monkeyrunner工具主要被设计用来在方法和框架级别测试应用和设备,运行单元测试。
monkeyrunner具备以下特点:
- 多设备控制
- 功能测试
- 回归测试
- 可拓展的自动化测试