安卓自动化测试monkey

monkey–稳定性测试

因为实体机要root权限,所以我用模拟器来测试

操作步骤

  1. 先打开模拟器(之前的文章有介绍)
  2. 先安装被测软件到模拟器(adb install -r 安装包)
  3. 查看包名(adb shell 进入shell界面 --> ls data/data 查看应用程序包)
  4. 输入命令
  • monkey -p 程序包名 -v 1000 (shell界面命令)
    如:monkey -p com.android.calculator -v 1000 (-p是指定包,-v是日志级别,1000是指注入多少次事件)
    -v:可以有1–3个,越多打印的信息越详细
  • adb shell monkey -p com.android.calculator -s 10 -v 1000 (window命令)
    -s 指定seed值 -v 反馈信息级别 -p 指定包
  • adb shell monkey -p com.android.calculator -s 10 -v 1000 > C:\monkey\test1.txt 保存日志

常用的命令

  • 指定包测试
    adb shell monkey -p 包名 --throttle 500 -s 100 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -vvv 10000 > C:\monkey\test1.txt
  • 指定activity执行
  • 启动APP
    adb shell am start com.android.calendar
  • 查看包有哪些activity
    adb shell dumpsys package 包名 >C:\monkey\test1.txt
    如:adb shell dumpsys package com.android.calendar >C:\monkey\test21.txt
    在这里插入图片描述
  • 启动activity
    adb shell am start 包名/Activity名
    在这里插入图片描述
  • 指定activity执行
    adb shell monkey -p 包名/Activity名 --throttle 500 -s 100 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -vvv 10000 > C:\monkey\test221.txt

常用命令参数

  1. -p 可以指定一个/多个包(如:adb shell monkey -p 包名1 -p 包名2 100)
  2. –throttle 设置随机事件之间的延,单位为毫秒(如:adb shell monkey -p 包名 --throttle 3000 100)
  3. -s 指定伪随机数生成器的seed数,如果seed值相同,则测试的随机事件序列相同(重现问题用这个)
  4. –pct-touch --触屏事件占比 (如:adb shell monkey --pct-touch 50 -p 包名 100 随机事件中触屏占比50%)
  5. –pct-motion --滑动事件占比
  6. –pct-trackball --随机移动和单击事件占比
  7. –pct-nav --向上、向下、向左、向右事件占比
  8. –pct-majornav --主要导航事件占比 (如:Back键、Menu键)
  9. –pct-syskeys --设备系统按键占比
  10. –pct-appswitch --启动活动(activity)占比,控制测试涉及到多少的活动
  11. –pct-anyevent --普通按键消息、不常用的按钮消息占比
  12. –ignore-crashes --不管应用是否奔溃
  13. –ignore-timeouts --测试过程出现ANR(Application not responding),也不管
  14. –ignore-security-exceptions —不管证书/网络许可错误
  15. –kill-process-after-error --出错停止
  16. –monitor-native-crashes --报告安卓的奔溃事件

不记得摘自哪里的了,放在这里学习学习
Monkey:Android SDK自带的一个命令行工具,使用adb来运行它,向系统发送伪随机的用户事件流,如按键、触屏、输入等;实现对正在开发的应用程序进行压力测试,伴随着日志输出。实际上该工具只能做程序做一些压力测试,由于测试事件和数据都是随机的,不能自定义,所以有很大的局限性。

MonkeyRunner:Android SDK提供的测试工具,位于tools目录下,比Monkey强大,可以编写脚本来自定义数据,事件;但是脚本是采用python语言编写的,其实就是对python进行了封装,对测试人员要求较高。

Appium:这应该是最近很火的一个测试框架,支持Native APP,Hybird APP,Web APP;可以跨平台在Windows,Mac,Linux使用,支持Android,ios;支持java,js,php,Python等语言编写测试脚本

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章