Android app的常见概念

Android app的常见概念

十月 29, 2019

Android自动化依赖前提


获取App的信息

  • App信息
    • 获取当前界面元素: adb shell dumpsys activity top
    • 获取任务列表: adb shell dumpsys activity activities
  • App入口
    • 过滤当前界面信息: adb logcat | grep displayed (可用来获取启动入口)
    • 过滤启动页activity: aapt dump badging mobike.apk | grep launchable-activity
  • 启动应用
    • adb shell am start -n com.xueqiu.android/.view.WelcomeActivityAlias -S (“com.xueqiu.android/.view.WelcomeActivityAlias”是通过adb logcat | grep displayed命令获取到的启动入口信息)

Android调试桥adb命令

  • Android常用命令
    • 查看设备: adb devices
    • 关闭adb后台进程: adb kill-server
    • 让Android 脱离USB线的TCP连接方式: adb tcpip
    • 连接开启TCP连接方式的手机: adb connect
    • 查看Android日志: adb logcat
    • 收集日志数据,用于后续的分析,比如耗电量: adb bugreport
  • adb shell
    adb shell本身就是一个Linux的shell,可以调用Android的内置命令,进入手机内部命令行。
    • adb shell : 进入手机或者模拟器的shell内核。
    • adb shell dumpsys : 用于打印出当前系统信息可以在命令后面加指定的service name(比如activity,location),如果不加则默认打印出设备中所有service的信息。
    • adb shell pm : 用于查询设备上应用包的相关信息,一般测试时大部分使用adb shell pm clear com.demo.android(“com.demo.android”为应用的包名)命令,可以快速清理应用的数据缓存。
    • adb shell am : 用于查询设备上所运行的activity。
    • adb shell ps : 用于查看手机运行的进程。
    • adb shell monkey : 进行Monkey测试,Monkey测试是Android自动化测试的一种手段,Monkey测试本身非常简单,就是模拟用户的按键输入,触摸屏输入,手势输入等,看设备多长时间会出异常。

Android 性能统计 dumpsys

  • 获取当前的activity: adb shell dumpsys activity top
  • 获取特定包基本信息: adb shell dumpsys package com.demo.android
  • 获取系统通知: adb shell dumpsys notification
  • 获得内存信息: adb shell dumpsys meminfo com.android.settings
  • 获取cpu信息: adb shell dumpsys cpuinfo
  • 获取gpu绘制分析: adb shell dumpsys gfxinfo com.android.settings

简单的自动化工具 input命令

  • 屏幕的点击: adb shell input tap x y (x,y为获取到的坐标,可以在模拟器中获取到)
  • 屏幕的滑动: adb shell input swipe x1 y1 x2 y2 (x1,y1为起点坐标,x2,y2为终点坐标)
  • 模拟输入字符串: adb shell input text “string”
  • 模拟键盘输入: adb shell input keyevent “what you want input”

以上就是有关Android app的一些常见的概念了。