0
点赞
收藏
分享

微信扫一扫

ADB Monkey的应用整理

霍华德 2022-04-21 阅读 55
功能测试

简介:

adb是安卓app开发工具,对软件测试而言主要用来查看安卓app的日志

环境:

  • 安装Java环境
  • 安装安卓sdk环境:android-sdk-windows(解压到没有中文和空的目录中:D:\android-sdk-windows)
  • 配置环境参考https://www.jianshu.com/p/4e00f725bf75
  • 雷电模拟器

常用命令

  • adb devices:查看已安装的安卓设备
  • adb kill-server:关闭adb
  • adb start-server:重启adb
  • adb install apk路径:安装安卓软件
  • adb install -r apk路径:-r 为强制覆盖安装;apk路径是apk文件所在的文件夹目录
  • adb shell:安卓会有shell,相当于控制台,使用linux命令。exit可退出shell;/sdcard/ 文件管理器
  • adb pull (文件路径) (文件存储路径):数据从手机推送至电脑
  • adb push (文件路径) (文件存储路径):数据从电脑拉取至手机
  • adb日志:获取安装或app的日志,查看崩溃的原因
1.获取app的包名:打开被测的app,再输入adb shell dumpsys activity | findstr 'mFocusedActivity',得到包名为com.liuyun.appiumtest

C:\Users\86156>adb shell dumpsys activity | findstr "mFocusedActivity"
  mFocusedActivity: ActivityRecord{bcf505d u0 com.liuyun.appiumtest/.MainActivity t4}

2.输入adb logcat保存日志:adb logcat > rizhi.log(日志的文件名)
如  C:\Users\86156>adb logcat > 123.log
文件保存在路径C:\Users\86156
3.复现崩溃的场景,按ctrl+C结束
4.搜索包名查找崩溃日志:beginning of crash / 找到对应包名com.liuyun.appiumtest
5.截图提交bug
ps:无响应ANR,卡住了
  • adb shell monkey -p 包名 次数:做app稳定性测试,通过产生随机事件来检查app是否存在潜在问题,崩溃/闪退/无响应,关键字CRASH
    用大量真机批量测试,安卓兼容性测试,没有大量真机可用云测testin平台租用真机,一分钟三块
C:\Users\86156>adb shell monkey -p com.liuyun.appiumtest 1000
    // activityResuming(com.liuyun.appiumtest)
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
    // Injection Failed
// CRASH: com.liuyun.appiumtest (pid 2349)
// Short Msg: java.lang.NumberFormatException
// Long Msg: java.lang.NumberFormatException
// Build Label: google/android_x86/x86:7.1.2/N2G47O/3636322:/release-keys
// Build Changelist: 3636322
// Build Time: 1636628140000
// java.lang.NumberFormatException
//      at com.liuyun.appiumtest.MainActivity$2.onClick(MainActivity.java:36)
//      at android.view.View.performClick(View.java:5637)
//      at android.view.View$PerformClick.run(View.java:22429)
//      at android.os.Handler.handleCallback(Handler.java:751)
//      at android.os.Handler.dispatchMessage(Handler.java:95)
//      at android.os.Looper.loop(Looper.java:154)
//      at android.app.ActivityThread.main(ActivityThread.java:6161)
//      at java.lang.reflect.Method.invoke(Native Method)
//      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
//      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
//
** Monkey aborted due to error.
Events injected: 399
## Network stats: elapsed time=3929ms (0ms mobile, 0ms wifi, 3929ms not connected)
** System appears to have crashed at event 399 of 1000 using seed 1650785514684
java.lang.Exception: call exit callstack! status=399
        at java.lang.System.exit(System.java:1418)
        at com.android.commands.monkey.Monkey.main(Monkey.java:486)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:290)
  • 关于monkey事件,如定位触摸事件百分比:adb shell monkey -p 包名 --pct-touch 百分比 次数
    adb shell monkey -p com.liuyun.appiumtest --pct-touch 50 1000

  • 日志级别:-vvv显示信息最详细,崩溃/闪退:CRASH;无响应:ANR

举报

相关推荐

0 条评论