一篇文章带你入门adb自动化测试

前言

测试初期使用功能测试可灵活的发现软件中所存在的bug,但当测试进入中后期,偶发问题和性能需求便成为了主流,而对于测试中的偶发问题和软件性能问题,若只以人工的方法继续进行压测,将会导致极大的人力损耗,因而掌握基本的自动化测试知识,对后期的软件测试具有非常重大的意义,而adb则是最基本的自动化测试工具。


一、什么是adb

1、adb的原理的应用场景

(1)安卓设备的云控制
(2)多台设备的统一控制
(3)adb自动化测试

2、(adb)Android debug bridge用于调试使用安卓系统的设备

(1)安卓平板
(2)安卓手机
(3)智慧大屏

3、adb基本原理

adb全称为Android debug bridge,PC电脑可利用adb命令对安卓设备进行操作


二、adb环境的配置

1.JDK环境安装(JAVA)

(1)JDK包下载网址如下:https://www.oracle.com/java/technologies/downloads/#java18,由于原网址下载过慢,也可考虑使用开源软件镜像站下载
(2)下载版本:目前有17、18、8、11等版本的,选合适的就行,这边下载的是8的
(3)安装:网上教程一堆,安装JDK和配置好环境变量便可

2.SDK环境安装(安卓)

(1)SDK包下载网址如下:https://developer.android.google.cn/studio/releases/platform-tools,同样可考虑使用开源软件镜像站下载
(2)下载版本:选择最新的就可以
(3)安装:网上教程一堆,安装SDK和配置好环境变量便可


三、adb基本操作

1.连接-连接安卓模拟器

(1)可下载以下安卓模拟器来学习操作:Android Studio emulator(官方)、genymotion、mumu、雷电、夜神、逍遥等。
(2)不同的模拟器有不同的连接方式,要找到对于的模拟器连接方式,比如mumu模拟器则可以通过以下指令进行连接:win+R->输入“cmd”进入终端命令行输入:adb connect IP+端口号(如mumu模拟器是:adb connect 127.0.0.1:7555)

2.连接-连接真机

(1)USB线连接:让安卓设备进入调试模式:关于->版本号连点击7下->开发者模式->打开USB调试;window端看实际情况看是否需要安装相关驱动(我这没特地安装也可正常使用),PC通过USB线连接安卓设备,进入window终端,输入adb devices。

C:\Users\24637>adb devices
List of devices attached
192.168.28.160:5555     device

(2)网络连接:是PC与设备处于同一个局域网,执行adb connect IP:端口号(若提示目标用户拒绝(一般是由于端口占用导致),则先使用USB数据线连接手机和电脑,在PC端打开cmd命令窗口,输入adb devices ,可以看到已经连接的设备,输入“adb tcpip 端口号(想要重置成的端口号)”后拔掉USB线,连接上同一个局域网重新connect连接便可)

C:\Users\24637>adb devices
List of devices attached
80f8cc84        device
C:\Users\24637>adb tcpip 5037
restarting in TCP mode port: 5037

拔掉USB线后重新通过局域网连接后进入终端重新连接:
C:\Users\24637>adb connect 192.168.28.160:5037
connected to 192.168.28.160:5037
C:\Users\24637>adb devices
List of devices attached
192.168.28.160:5037     device

3.连接-基本连接指令

(1)连接设备:adb connect IP:端口号(-s:可指定连接设别)
(2)查询adb设备和查看状态:adb devices

C:\Users\24637>adb devices
List of devices attached
192.168.28.160:5037     device

(3)查询adb状态:adb get-state

C:\Users\24637>adb get-state
device

device:正常
Offline:连接退出
Unauthorized:未授权
(4)杀死adb服务:adb kill-server

C:\Users\24637>adb kill-server

C:\Users\24637>adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached

4.adb命令格式

(1)adb /-e/-s/-s/ serialNumber command
-d:指定当前唯一通过USB连接的安卓设备作为命令目标
-e:指定当前唯一运行的模拟器为命令坐标
-s:指定相应的设备作为命令目标(重点)

adb -s 192.168.28.160:5037 shell dumpsys cpuinfo
Load: 5.47 / 4.4 / 4.28
CPU usage from 9743ms to 108ms ago (2022-04-05 22:09:18.727 to 2022-04-05 22:14:40.072) with 2% awake:
  21% 1510/system_server: 5.4% user + 16% kernel / faults: 1611 minor
  ......

四、adb指令

1.安装指令

(1)adb install <apk路径>(普通安装)
(2)adb install -r <apk路径>(覆盖安装)
(3)adb -s <设备名字> install -r <apk路径>(指定设备覆盖安装)

adb install C:\Users\24637>adb install C:\Users\24637\Desktop\weixin8021android2120_arm64.apk
Performing Streamed Install
...

2.卸载指令

(1)卸载所有,包括存储数据:adb uninstall 包名(有唯一的包名)
(2)卸载应用(不删除配置文件,保存数据缓存信息):adb uninstall -k 包名
(3)adb shell进入手机的内环境#,可查看缓存数据
cd /data/data(所有应用的数据文件夹)-> ls

C:\Users\24637>adb uninstall com.tencent.mm
Success

3.启动指令

(1)原理:每个安卓都有对应的包名,进入APP的每个页面也对应着各个活动页,每个活动页都有特定的标签
(2)adb shell “dumpsys window | grep CurrentFocus”(获取当前活动页的标签)

C:\Users\24637>adb shell "dumpsys window | grep mCurrentFocus"
  mCurrentFocus=Window{
    
    43100 u0 com.tencent.mobileqq/com.tencent.mobileqq.activity.SplashActivity}

(3)adb shell pm list packages -3(获取系统安装的APK的包名标签)

C:\Users\24637>adb shell pm list packages
package:com.miui.screenrecorder
package:com.quark.browser
package:com.crc.hrt
package:com.sony.playmemories.mobile
...

(4)adb logcat ActivityManager:I | findstr “cmp”(使用adb打印命令,打印对应标签的信息,可找到对应活动页的标签名称)

C:\Users\24637>adb logcat ActivityManager:I | findstr "cmp"
04-05 12:10:58.298  1510  1668 W ActivityManager: Unable to start service Intent {
    
     act=action.com.heytap.openid.OPEN_ID_SERVICE cmp=com.heytap.openid/.IdentifyService } U=0: not found
04-05 12:28:11.426  1510  1905 W ActivityManager: Unable to start service Intent {
    
     act=action.com.heytap.openid.OPEN_ID_SERVICE cmp=com.heytap.openid/.IdentifyService } U=0: not found
...

(5)adb shell am start -n <apk包名/活动页>(启动对应的应用或页面,输入后便可打开对应APK的活动页面)

C:\Users\24637>adb shell "dumpsys window | grep mCurrentFocus"
  mCurrentFocus=Window{
    
    deca79 u0 com.miui.home/com.miui.home.launcher.Launcher}

C:\Users\24637>adb shell am start -n com.tencent.mobileqq/com.tencent.mobileqq.activity.SplashActivity
Starting: Intent {
    
     cmp=com.tencent.mobileqq/.activity.SplashActivity }
Warning: Activity not started, its current task has been brought to the front

4.查看指令

(1)adb shell ls(查看当前路径文件)

C:\Users\24637>adb shell ls
acct
bt_firmware
bugreports
...

(2)adb shell date(查看日期)

C:\Users\24637>adb shell date
Tue Apr  5 23:25:28 CST 2022

(3)adb shell cat /proc/cpuinfo(打开CPU信息文件)

C:\Users\24637>adb shell cat /proc/cpuinfo
Processor       : AArch64 Processor rev 4 (aarch64)
processor       : 0
BogoMIPS        : 38.40
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x51
CPU architecture: 8
CPU variant     : 0xa
CPU part        : 0x801
CPU revision    : 4
...

(4)adb shell cat /proc/meminfo

C:\Users\24637>adb shell cat /proc/meminfo
MemTotal:        3832048 kB
MemFree:          288900 kB
MemAvailable:    1563108 kB
Buffers:           73528 kB
Cached:          1321356 kB
SwapCached:         8500 kB
Active:          1530472 kB
...

5.包管理器(pm)指令

(1)adb shell pm list packages(列举所有的应用包)

C:\Users\24637>adb shell pm list packages
package:com.miui.screenrecorder
package:com.qualcomm.qti.haven.telemetry.service
package:com.android.cts.priv.ctsshim
...

(2)adb shell pm list packages -s(列出系统应用包)

C:\Users\24637>adb shell pm list packages -s
package:com.qualcomm.qti.haven.telemetry.service
package:com.android.cts.priv.ctsshim
...

(3)adb shell pm list packages -3(列举用户自行安装的包)

C:\Users\24637>adb shell pm list packages -3
package:com.miui.screenrecorder
package:com.quark.browser
...

(4)adb shell pm clear <应用包名>(清楚对应应用的数据,让其处于刚安装状态)

C:\Users\24637>adb shell pm clear cn.wps.moffice_eng
Success

adb shell进入内环境,进入文件夹data/data可查看对应应用的数据文件

6.文件传输指令

(1)adb push <电脑路径> <设备路径>(把文件从电脑推到安卓设备)

C:\Users\24637>adb push C:\Users\24637\Desktop\test.txt /sdcard
C:\Users\24637\Desktop\test.txt: 1 file pushed, 0 skipped. 0.0 MB/s (19 bytes in 0.043s)

C:\Users\24637>adb shell
clover:/ $ cd sdcard/
clover:/sdcard $ cat test.txt
hello world!!

(2)adb pull <设备路径> <电脑路径>(把文件从安卓设备推到电脑)

C:\Users\24637>adb pull /sdcard/test.txt C:\Users\24637\Desktop\
/sdcard/test.txt: 1 file pulled, 0 skipped. 0.0 MB/s (19 bytes in 0.025s)

(3)cd data/data(系统路径,不能随意操作)cd sdcard(内存卡路径,可操作)

7.日志指令

(1)adb logcat 级别
V-明细verbose(最低优先级)
D-调试debug
I-信息info
W-警告warn
E-错误error
F-严重错误fatal
S-无记载silent(最高优先级,绝不会输出任何内容)
以上的优先级从低到高,设定这个打印优先级主要是为了能更好的抓到对应的打印信息,屏蔽不必要的信息,便于排查问题。
(2)adb logcat 参数
adb logcat --help(可查看关于logcat使用的帮助信息)

C:\Users\24637>adb logcat --help
Usage: logcat [options] [filterspecs]
options include:
  -s              Set default filter to silent. Equivalent to filterspec '*:S'
  ...

adb logcat -v time(显示事件)

显示打印的时间,但目前一般都是默认打印信息带时间的,所以可忽略

adb logcat -v color(显示打印的颜色)

加上此参数的打印信息,获取到的打印信息会根据优先级的不同,
而让打印的文字显示不同的颜色从而便于观察

adb logcat -f <sdcard/log.lo>(保存日志到当前安卓设备)

C:\Users\24637>adb logcat -f /sdcard/test.logcat
^C
C:\Users\24637>adb shell
1|clover:/ $ cat /sdcard/test.logcat
--------- beginning of system
04-05 11:51:37.079  1510  1785 W ActivityManager: Scheduling restart of crashed service com.qualcomm.qti.callenhancement/.CallEnhancementService in 1000ms
04-05 11:51:37.186  1510  2599 W ActivityManager: Scheduling restart of crashed service com.android.statementservice/.DirectStatementService in 10893ms
...

adb logcat > <电脑路径>(保存日志到电脑)

C:\Users\24637>adb logcat -v color > C:\Users\24637\Desktop\test.logcat
^C

adb logcat -c(清理日志缓存,清理后,logcat会重新从头开始打印,而不会打印之前的缓存打印信息)

C:\Users\24637>adb logcat -c

C:\Users\24637>adb logcat
--------- beginning of main
04-06 12:44:11.586  1510  1528 I WifiService: requestActivityInfo uid=1000
04-06 12:44:11.586  1510  1528 I WifiService: reportActivityInfo uid=1000
04-06 12:44:11.586  1510  1528 I WifiService: getSupportedFeatures uid=1000
...

adb logcat “*:w”(打印warn及以上级别的日志,可设定打印特定优先级的打印信息)

C:\Users\24637>adb logcat "*:w"
--------- beginning of main
04-06 12:44:19.110 22440 23162 E memtrack: Couldn't load memtrack module
04-06 12:44:19.111 22440 23162 W android.os.Debug: failed to get memory consumption info: -1
04-06 12:44:19.150   762   762 E FIDOCA : : get_fp_vendor property_get : none
04-06 12:44:32.593   762   762 E FIDOCA : : get_fp_vendor property_get : none
04-06 12:45:18.168   762   762 E FIDOCA : : get_fp_vendor property_get : none
04-06 12:45:19.061 22440 22477 E memtrack: Couldn't load memtrack module
...

adb logcat ActivityManager:D “*:S”(过滤tag为Activitymanager,level为debug及以上级别的日志)

C:\Users\24637>adb logcat ActivityManager:D "*:S"
--------- beginning of main
04-06 12:47:27.011  1510  1510 W ActivityManager: Sending non-protected broadcast miui.intent.action.SMART_COVER from system 1510:system/1000 pkg android. Callers=com.android.server.am.ActivityManagerService.broadcastIntentLocked:20211 com.android.server.am.ActivityManagerService.broadcastIntent:20520 android.app.ContextImpl.sendBroadcastAsUser:1140 miui.util.SmartCoverManager.handleLidSwitchChanged:197 miui.util.SmartCoverManager.notifyLidSwitchChanged:100
04-06 12:47:27.011  1510  1510 W ActivityManager: Sending non-protected broadcast miui.intent.action.SMART_COVER from system 1510:system/1000 pkg android. Callers=com.android.server.am.ActivityManagerService.broadcastIntentLocked:20333 com.android.server.am.ActivityManagerService.broadcastIntent:20520 android.app.ContextImpl.sendBroadcastAsUser:1140 miui.util.SmartCoverManager.handleLidSwitchChanged:197 miui.util.SmartCoverManager.notifyLidSwitchChanged:100
--------- beginning of system
04-06 12:47:34.092  1510  1532 I ActivityManager: Displayed com.tencent.mobileqq/.activity.SplashActivity: +218ms


日志常见错误可参考网上日志分析:
crash闪退
Exception异常
Force closed 强制退出
Anr (application no response)程序无响应
我们可对抓取到的打印,根据以上关键字来获取到对应的打印信息


8.输入指令

打开开发者模式的USB调试模式后->找到输入栏目,打开指针位置设置的开关,打开后,我们使用鼠标或触控点击设备大屏,设备上方都会显示每次点击对应的坐标,根据显示的dx,dy坐标,我们便可定位到当前点击的位置信息,进而可使用以下指令进行各种输入事件模拟。
在这里插入图片描述(1)adb shell input --help

C:\Users\24637>adb shell input --help
Error: Unknown command: --help
Usage: input [<source>] <command> [<arg>...]

The sources are:
      dpad
      keyboard
      mouse
      touchpad
      gamepad
      touchnavigation
      joystick
      touchscreen
      stylus
      trackball

The commands and default sources are:
      text <string> (Default: touchscreen)
      keyevent [--longpress] <key code number or name> ... (Default: keyboard)
      tap <x> <y> (Default: touchscreen)
      swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
      draganddrop <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
      press (Default: trackball)
      roll <dx> <dy> (Default: trackball)
      tmode <tmode>

(2)adb shell input tap x y(点击对应坐标)

C:\Users\24637>adb shell input tap 717.4 899.5

(3)adb shell input test 文本(光标放在输入框里面)

C:\Users\24637>adb shell input text 1234567890

(4)adb input shell swipe 起点x 起点y 终点x 终点y 滑动时常(毫秒)

C:\Users\24637>adb shell input swipe 587 1601 520 323 1000

(5)adb shell input keyevent <编号>(模拟手机按键)

此处的编号是固定的键值
不同的键值可对应安卓设备的一个功能按键

(6)adb shell input keyevent 4(点击手机的返回)

C:\Users\24637>adb shell input keyevent 4

(7)adb shell input keyevent 3(回home,置于后台运行)

C:\Users\24637>adb shell input keyevent 3

(8)adb shell input keyevent 24(volume +)

C:\Users\24637>adb shell input keyevent 24

(9)adb shell input keyevent 25(volume -)

C:\Users\24637>adb shell input keyevent 25

(10)除以上键值外,还有很多对应的键值可以参照下面网址找到:
https://developer.android.google.cn/reference/kotlin/android/view/KeyEvent(查看对应的按键数值)
(11)adb shell input draganddrop x1 y1 x2 y2 <毫秒>(拖动)

C:\Users\24637>adb shell input draganddrop 995 890 862 1424 1000

(12)adb shell input press(不懂,暂未找到具体的应用场景)
(13)adb shell input roll(不懂,暂未找到具体的应用场景)
(14)adb shell input tmode(不懂,暂未找到具体的应用场景)

9.性能指令

(1)adb shell dumpsys cpuinfo(查看当前系统CPU使用情况)

C:\Users\24637>adb shell dumpsys cpuinfo
Load: 4.53 / 4.71 / 4.71
CPU usage from 61745ms to 17835ms ago (2022-04-06 21:20:30.177 to 2022-04-06 21:21:14.086):
  3.9% 31550/com.tencent.mobileqq: 1.1% user + 2.7% kernel / faults: 75 minor
  1.7% 1510/system_server: 0.9% user + 0.8% kernel / faults: 214 minor
  1.6% 2355/com.miui.daemon: 0.7% user + 0.8% kernel / faults: 93 minor
  ...

(2)adb shell dumpsys meminfo(查看当前系统内存的使用情况)

C:\Users\24637>adb shell dumpsys meminfo
Applications Memory Usage (in Kilobytes):
Uptime: 55255567 Realtime: 519976278
Total PSS by process:
    233,353K: com.tencent.mobileqq (pid 31550)
    226,479K: com.android.systemui (pid 1651 / activities)
    223,112K: system (pid 1510)
    ...

(3)adb shell dumpsys meminfo + 包名(查看当前应用内存的使用情况)

C:\Users\24637>adb shell dumpsys meminfo com.tencent.mobileqq
Applications Memory Usage (in Kilobytes):
Uptime: 55354761 Realtime: 520113614

** MEMINFO in pid 31550 [com.tencent.mobileqq] **
...

(4)adb shell dumpsys battry(查看电池状态)

C:\Users\24637>adb shell dumpsys battery
Current Battery Service state:
  AC powered: false
  USB powered: false
  Wireless powered: false
  Max charging current: 0
  Max charging voltage: 0
  Charge counter: 1863418
  status: 3
  health: 2
  present: true
  level: 71
  scale: 100
  voltage: 3987
  temperature: 300
  technology: Li-poly

AC powered: true
USB powered: false
Wireless powered: false
Max charging current: 2000000(最大充电电流)
status: 2(充电状态,其他数字为非充电状态)
health: 2(只有数字2表示good)
present: true(电池是否安装在机身)
level: 89(电池百分比)
scale: 100
voltage: 4172(电池电压)
temperature: 377(温度37.7)
technology: Li-poly(电池种类)
(5)adb shell top(当前系统的进程使用情况(类似任务管理器))

Tasks: 678 total,   2 running, 671 sleeping,   0 stopped,   0 zombie
Mem:   3832048k total,  3702832k used,   129216k free,    55404k buffers
Swap:  2306044k total,   296776k used,  2009268k free,  1328704k cached
800%cpu   3%user   0%nice  44%sys 740%idle   6%iow   2%irq   5%sirq   0%host
  PID USER         PR  NI VIRT  RES  SHR S[%CPU] %MEM     TIME+ ARGS
 1510 system       18  -2 4.5G 275M 174M S 23.8   7.3  75:54.44 system_server
 ...

(6)adb shell top | findstr 包名(对应应用的占用)

C:\Users\24637>adb shell top | findstr  com.tencent.mob+
[H[JTasks: 675 total,   1 running, 668 sleeping,   0 stopped,   0 zombie
[H[JTasks: 675 total,   1 running, 668 sleeping,   0 stopped,   0 zombie
31550 u0_a188      20   0 5.2G 449M 213M S  0.6  12.0   2:03.75 com.tencent.mob+
...

(7)Adb shell top -d 1|grep 包名(打印时间和对应应用的占用)

C:\Users\24637>adb shell top -d 1| findstr com.xunmeng.pin+
21100 u0_a150      20   0 4.3G 126M  54M S 10.7   3.3   2:58.72 com.xunmeng.pin+
21100 u0_a150      20   0 4.3G 126M  54M S 10.7   3.3   2:58.72 com.xunmeng.pin+
...

(6)除以上性能指令外,还有很多对应的性能指令可以参照下面网址找到https://developer.android.google.cn/studio/command-line/dumpsys?hl=en


五、adb monkey

1.Google提供的一个用于稳定性与压力测试的命令行工具:具有随机性、完整性、持续性的特点,monkey可自动模拟一些随机事件,从而达成自动化压测需求。

2.monkey基本命令

(1)Adb shell monkey <参数> (随机发送事件数)
adb shell monkey -v <参数> (随机发送事件数)
adb shell monkey -vv <参数> (随机发送事件数)
adb shell monkey -vvv <参数> (随机发送事件数)
-v指在跑monkey时同时输出事件的信息,-vvv表示输出的信息更多。

C:\Users\24637>adb shell monkey -vvv 100
  bash arg: -vvv
  bash arg: 100
args: [-vvv, 100]
 arg: "-vvv"
 arg: "100"
:Monkey: seed=1649380636258 count=100
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 15.0%
...

(2)停止monkey:1.指令执行完成、2.遇到奔溃或者异常、3.杀掉进程:
adb shell
ps | grep monkey
kill -9 进程号
(3)指定包名压力测试 adb shell monkey -p 包名 事件数

C:\Users\24637>adb shell monkey -p com.tencent.mobileqq 10
  bash arg: -p
  bash arg: com.tencent.mobileqq
  bash arg: 10
args: [-p, com.tencent.mobileqq, 10]
 arg: "-p"
 arg: "com.tencent.mobileqq"
 arg: "10"
data="com.tencent.mobileqq"
Events injected: 10
## Network stats: elapsed time=162ms (0ms mobile, 0ms wifi, 162ms not connected)

(4)adb shell monkey -p 包名 -p 包名 -vvv 10(多个包随机事件)(adb shell monkey -p com.tencent.mobileqq -p com.aligames.sgzzlb.aligames -vvv 10)

C:\Users\24637>adb shell monkey -p com.tencent.mobileqq -p com.aligames.sgzzlb.aligames -vvv 10
  bash arg: -p
  bash arg: com.tencent.mobileqq
  bash arg: -p
  bash arg: com.aligames.sgzzlb.aligames
  bash arg: -vvv
  bash arg: 10
  ...

(5)adb shell monkey -p 包名 -p 包名 --throttle 时长 -vvv 1000(加入每次事件的执行时间)

C:\Users\24637>adb shell monkey -p com.tencent.mobileqq --throttle 1000 10
  bash arg: -p
  bash arg: com.tencent.mobileqq
  bash arg: --throttle
  bash arg: 1000
  bash arg: 10
args: [-p, com.tencent.mobileqq, --throttle, 1000, 10]
 arg: "-p"
 arg: "com.tencent.mobileqq"
 arg: "--throttle"
 arg: "1000"
 arg: "10"
...

(6)adb shell monkey -p 包名 -p 包名 --throttle 时长 -s 种子号 -vvv 1000(加入事件的种子号,种子号代表一个标签,若这次运行出现错误后,可继续借用这个种子号来继续运行相同的事件来复现问题)

C:\Users\24637>adb shell monkey -p com.tencent.mobileqq --throttle 1000 -s 123 -vvv 10
  bash arg: -p
  bash arg: com.tencent.mobileqq
  bash arg: --throttle
  bash arg: 1000
...

(7)adb shell monkey -p 包名 -p 包名 --pct-touch --throttle 时长 -s 种子号 -vvv 1000(加入随机事件比例)
–pct-touch(触摸事件)
–pct-motion(滑动事件)
–pct-trackball(轨迹球事件)
–pct-nav(基本导航事件)
–pct-majornav(主要导航事件)
–pct-syskeys(系统按键事件)
–pct-appswitch(设定启动Activity事件百分比)
–pct-pinchzoom(缩放事件)
–pct-rotation(屏幕旋转事件)
–pct-flip(键盘事件)
–pct-anyevent(任意事件,设定不常用事件的百分比)

可手动设置以上事件所占monkey程序的比例数

(8)忽略异常
adb shell monkey -p 包名 -p 包名 --pct-touch 比例数 --throttle 时长 -s 种子号 --ignore-crashes -vvv 1000(加入忽略异常指令,可使程序报错后继续运行,从而达到长时间运行monkey压测的功能)
–ignore-crashes(忽略奔溃)
–ignore-timeouts(忽略超时)
–ignore-security-exceptions(忽略安全异常)
–kill-process-after-error(发生错误后直接杀掉进程)
–dbg-no-events(初始化启动的activity,但是不产生任何事件)
–hprof(指定该项后在事件序列发送前后会立即生成分析报告)
–monitor-native-crashes(跟踪本地方法的奔溃问题)
–wait-dbg(知道连接了调试器才执行monkey测试)
–bugreport(但ANR,系统无响应,Crash的时候获得bugreport)
(9)保存日志
方法一:adb shell monkey -p com.xueqiu.android -vvv --pct-touch 70 --pct-motion 10 --pct-syskeys 10 -s 1234567 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --throttle 300 96000 > 电脑路径
方法二:运行monkey后,另开一个终端执行 adb logcat “*:E” > 电脑路径
(10)日志常见错误可参考网上日志分析,存在异常大概有以下四种:
crash闪退
Exception异常
Force closed 强制退出
Anr (application no response)程序无响应


总结

在这里插入图片描述
以上就是今天要讲的内容,本文仅仅简单介绍了adb的使用,而adb提供了大量能使我们快速便捷地控制安卓系统的指令,从而使我们可实现基本的自动化测试。
ps:此文章的大纲流程图如图所示,具体的扩展流程可参照资料adb自动化测试入门流程图:https://download.csdn.net/download/qq_46166916/85080689
(可用作复习笔记进行温习)

猜你喜欢

转载自blog.csdn.net/qq_46166916/article/details/123977343