移动测试【命令与实战】

一、adb

abd:Andorid debug bridge

开发人员的调试工具与测试人员的测试工具

二、调试手机的流程

1、手机与电脑通过USB链接;

2、开放手机root权限步骤,此处以vivo 为例(如何搜索:关键词手机型号加开发者权限):

1)进入设置,搜索关于手机;

2)进入版本信息,找到软件版本号,连续点击7次后就会开启开发者权限(不同手机操作不同,可以进行搜索);

3)进入开发者选项,打开usb调试,然后打开电脑控制台输入adb devices,手机会弹出是否允许这台电脑调试该手机的提示,选择允许即可,这样就连接成功了。

三、常用命令

1、adb shell:进入手机的环境

通过此命令进入手机的环境,然后就可以通过linux命令进行相关查询,由于手机也是linux环境下的,所以linux命令也同样适用。最后输入exit就可以退出。

C:\Users\EDY>adb shell
* daemon not running; starting now at tcp:5037
* daemon started successfully
a: no devices/emulators found

2、adb logcat:查看实时日志

直接在控制台输入adb logcat可以查看实时日志,当我们APP程序出问题时,程序员要错误信息时,我们就可以用这个命令来查看错误日志,由于这样查看日志一直在更新无法找出错误,因此我们可以先在电脑本地储存盘,新建一个log.txt记事本,然后输入命令:

adb logcat > 储存盘:/log.txt

然后操作出问题的程序,这个时候我们就把程序的错误日志写入到我们创建的记事本中了,然后点击CTRL+C退出,最后打开这个记事本就可以查看到这个程序的错误信息。

C:\Users\EDY>adb logcat >D:\安卓环境搭建/log.txt
- waiting for device -
//以下为log.txt中的部分文件
--------- beginning of system
03-01 16:11:20.488   514  6175 D vold    : Added key 777928249 (f2fs:a926dc7de4754049) to keyring 222296254 in process 514
03-01 16:11:20.488   514  6175 D vold    : Added key 584545504 (fscrypt:a926dc7de4754049) to keyring 222296254 in process 514
03-01 16:11:20.488   514  6175 D vold    : 0 enter InstallEceSeceToHwsdpTa
03-01 16:11:20.488   514  6175 E vold    : 0 hwsdp is unloaded
03-01 16:11:20.488   514  6175 D vold    : Created keys for user 0
03-01 16:11:20.488   514  6175 D vold    : unlock user screen success,begin to reset flag
03-01 16:11:20.526 11443 11443 I RtgSchedEvent: current pid:11443 AppType:0
03-01 16:11:20.542 11443 11443 D ActivityThread: Won't deliver top position change in state=2

四、安装&卸载被测试APP的的流程

1、安装流程

程序员发送.apk包给测试,测试把包下载到本地,然后打开控制台,通过命令adb install 储存.apk包位置/.apk包的名称就可以安装这个APP,注意安装的时候需要在手机上允许安装。

如安装储存在d盘的tcw_146187.apk,命令如下:

adb install D:/tcw_146187.apk

C:\Users\EDY>adb install D:/安卓环境搭建/tcw_146187.apk
Performing Streamed Install
Success

2、查找package包

1)获取到package包(adb shell am monitor)

打开控制台输入adb shell am monitor,然后打开手机中你需要获取package包的APP,就可以找到该APP的package包;

C:\Users\EDY>adb shell am monitor
Monitoring activity manager...  available commands:
(q)uit: finish monitoring
** Activity starting: com.parkingwang.app
** Activity starting: com.parkingwang.app
** Activity resuming: com.parkingwang.app

2)找到package包(adb shell dumpsys window | findstr mCurrentFocus)

先打开手机中你需要获取package包的APP,然后输入命令:adb shell dumpsys window | findstr mCurrentFocus就可以找到这个APP的package包;

C:\Users\EDY>adb shell dumpsys window | findstr mCurrentFocus
  mCurrentFocus=Window{1128e51 u0 com.parkingwang.app/com.parkingwang.app.ui.home.MainHomeActivity}

3)找到所有的APP包(pm list package)

先输入adb shell然后再输入命令:pm list package就可以查看所有APP的包,然后就可以找到所需APP的包;

//进入手机环境
C:\Users\EDY>adb shell
//查看所有APP目录
HWYAL:/ $ pm list package
//部分信息
package:com.huawei.scenepack
package:com.huawei.hifolder
package:com.android.cts.priv.ctsshim
package:com.huawei.camera
package:com.hpbr.bosszhipin
package:com.huawei.android.tips
package:com.huawei.camerakit.impl
package:com.huawei.synergy

4)找到除了系统应用的第三方应用包(adb shell pm list packages -3)

打开控制台,输入命令:adb shell pm list packages -3,就可以找到除了系统应用的第三方应用包;

//直接查找,不用先进入手机环境
C:\Users\EDY>adb shell pm list packages -3
//部分目录
package:com.hpbr.bosszhipin
package:com.camerasideas.instashot
package:com.qiyi.video
package:com.tmri.app.main
package:com.sankuai.meituan
package:com.netease.edu.ucmooc
package:com.lemon.lv
package:com.zhy.qianyan
package:com.tencent.androidqqmail
package:com.coderpage.mine
package:cmb.pb
package:com.dm
package:cn.gov.tax.its
package:com.MobileTicket

3、卸载流程

打开控制台输入adb shell am monitor,然找到该APP的package包;输入adb uninstall # 卸载软件名,即可卸载软件

C:\Users\EDY>adb shell am monitor
Monitoring activity manager...  available commands:
(q)uit: finish monitoring
** Activity starting: com.parkingwang.app
** Activity starting: com.parkingwang.app
** Activity resuming: com.parkingwang.app

C:\Users\EDY>adb uninstall com.parkingwang.app
Success

五、错误类型

崩溃

crash,即崩溃,anr是crash的一种。在程序中可能会出现你未捕获到的异常,这就造成了崩溃。

错误日志关键词:crash、ANR。

造成崩溃的原因:

空指针:nullpointException

数组越界:ArrayIndexoutof boundsException

多次启动线程:illegalThreadstateException

数字格式化问题 :java.lang.NumberFormatException

内存溢出(OOM):java.lang.OutOfMemoryError

六、操作命令

查看命令

adb shell pm list packages # 显示设备里面所有应用的包名

adb shell service list # 显示当前运行的系统服务

adb shell dumpsys activity top # 显示当前最前端的 Activity

adb shell cat /proc/cpuinfo # 显示设备的CPU信息

adb shell cat /proc/meminfo # 显示设备的内存使用情况

adb shell wm size # 查看屏幕分辨率

//# 显示设备里面所有应用的包名【adb shell pm list packages】
C:\Users\EDY>adb shell pm list packages
package:com.huawei.scenepack
package:com.huawei.hifolder
package:com.android.cts.priv.ctsshim
package:com.huawei.camera
package:com.hpbr.bosszhipin
package:com.huawei.android.tips
package:com.huawei.camerakit.impl
package:com.huawei.synergy
package:com.huawei.android.launcher
package:com.huawei.hms.dupdateengine
package:com.huawei.easygo
package:com.android.mediacenter
package:com.huawei.ohos.smarthome
package:com.android.providers.telephony
//# 显示当前运行的系统服务【adb shell service list】 
C:\Users\EDY>adb shell service list
Found 259 services:
0       ions: [com.android.internal.telephony.IOns]
1       fusion_search: [com.huawei.searchservice.service.IHOSPSearchServiceCall]
2       secure_element: [android.se.omapi.ISecureElementService]
3       hwthermal: [com.huawei.thermal.adapter.IThermalService]
4       com.huawei.iconnect.ConnectService: [com.huawei.iconnect.wearable.IWearableDetectHelper]
5       chr_service: [com.huawei.chr.IHwChrService]
6       nfc: [android.nfc.INfcAdapter]
7       com.huawei.mdfs.DistributedFileService: []
8       ims_ut: [com.android.ims.internal.IImsUt]
9       ims_config: []
10      IAwareSdkService: [com.huawei.iaware.sdk.ISDKManager]
//# 显示当前最前端的 Activity【adb shell dumpsys activity top】
C:\Users\EDY>adb shell dumpsys activity top
TASK 1000:com.android.settings id=8385 userId=0
  ACTIVITY com.android.settings/.HWSettings 1a426c6 pid=10616
    Local Activity 505b517 State:
      mResumed=false mStopped=true mFinished=false
      mChangingConfigurations=false
      mCurrentConfig={1.0 460mcc11mnc [zh_CN_#Hans] ldltr sw360dp w360dp h744dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2340) mAppBounds=Rect(0, 108 - 1080, 2340) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} suim:1 fontWeightScale:100 s.1}
//# 显示设备的内存使用情况【adb shell cat /proc/meminfo】
C:\Users\EDY>adb shell cat /proc/cpuinfo
Processor       : AArch64 Processor rev 0 (aarch64)
processor       : 0
BogoMIPS        : 3.84
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x1
CPU part        : 0xd05
CPU revision    : 0
//# 查看屏幕分辨率【adb shell wm size】 
C:\Users\EDY>adb shell wm size
Physical size: 1080x2340

安装与卸载命令

adb install # 安装软件名

adb uninstall # 卸载软件名

C:\Users\EDY>adb install D:\安卓环境搭建\tcw_146187.apk
* daemon not running; starting now at tcp:5037
* daemon started successfully
Performing Streamed Install
Success
C:\Users\EDY>adb uninstall com.parkingwang.app
Success

进程命令

adb shell monkey -v 数字: # 运行进程多次

adb shell ps | findstr monkey # 查看正在运行的进程

adb shell kill PID # 停止正在运行的进程

adb shell ps | findstr 包名 # 查找特定进程

adb shell dumpsys meminfo PID # 获取内存信息

//#运行多次进程【adb shell monkey -v 数字】
C:\Users\EDY>adb shell monkey -v 1000000
  bash arg: -v
  bash arg: 1000000
args: [-v, 1000000]
 arg: "-v"
 arg: "1000000"
:Monkey: seed=1646326983582 count=1000000
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 15.0%
//   1: 10.0%
//   2: 2.0%
//   3: 15.0%
//   4: -0.0%
//   5: -0.0%
//   6: 25.0%
//   7: 15.0%
//   8: 2.0%
//   9: 2.0%
//   10: 1.0%
//   11: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.example.android.notepad/.NotePadActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.android.notepad/.NotePadActivity } in package com.example.android.notepad
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-1.0)
:Sending Touch (ACTION_DOWN): 0:(793.0,1757.0)
:Sending Touch (ACTION_UP): 0:(778.12445,1710.9473)
:Sending Touch (ACTION_DOWN): 0:(930.0,677.0)
:Sending Touch (ACTION_UP): 0:(898.08356,678.8933)
:Sending Trackball (ACTION_MOVE): 0:(2.0,3.0)
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=cn.gov.tax.its/.MainActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=cn.gov.tax.its/.MainActivity } in package cn.gov.tax.its
:Sending Touch (ACTION_DOWN): 0:(215.0,1323.0)
:Sending Touch (ACTION_UP): 0:(204.63362,1326.1484)
:Sending Touch (ACTION_DOWN): 0:(865.0,1415.0)
:Sending Touch (ACTION_UP): 0:(866.55786,1417.4951)
:Sending Touch (ACTION_DOWN): 0:(1076.0,1391.0)
:Sending Touch (ACTION_UP): 0:(1077.2103,1392.5365)

//【shift】+【c】退出
^C

//#查看正在运行的进程【adb shell ps | findstr monkey】
C:\Users\EDY>adb shell ps | findstr monkey
shell        25242 30287 4419260 115140 binder_ioctl_write_read 0 S com.android.commands.monkey
shell        26840 30287 4419260 115580 binder_ioctl_write_read 0 S com.android.commands.monkey

//#停止正在运行的进程【adb shell kill PID】
C:\Users\EDY>adb shell kill  25242
/system/bin/sh: kill: 25242: No such process

C:\Users\EDY>adb shell kill  26840
/system/bin/sh: kill: 26840: No such process
//# 查找特定进程【adb shell ps | findstr 包名】 
C:\Users\EDY>adb shell ps | findstr com.parkingwang.app
adb server version (32) doesn't match this client (41); killing...
* daemon started successfully
u0_a795       5682   692 7946680 312608 0                   0 S com.parkingwang.app
u0_a795       5864   692 6039540 209132 0                   0 S com.parkingwang.app:pushcore
//#获取内存信息【adb shell dumpsys meminfo 进程名】
C:\Users\EDY>adb shell dumpsys meminfo 5682
Applications Memory Usage (in Kilobytes):
Uptime: 57014549 Realtime: 72579098

** MEMINFO in pid 5682 [com.parkingwang.app] **
                   Pss  Private  Private  SwapPss     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap    78202    78136        0       21   122880    87336    35543
  Dalvik Heap     8857     8836        0       20    10356     7767     2589
 Dalvik Other     4465     4464        0        1
        Stack       56       56        0        0
       Ashmem      162      160        0        0
    Other dev      100       24       76        0
     .so mmap     3559      292     1148       23
    .jar mmap      553        0       20        0
    .apk mmap     4620      276       44        0
    .ttf mmap     2054        0     1420        0
    .dex mmap    11384     9632        8        0
    .oat mmap      264        0        0        0
    .art mmap     3002     2664        0       55
   Other mmap      856      176       60        0
    GL mtrack    10588    10588        0        0
      Unknown    20617    20592        0        0
        TOTAL   149459   135896     2776      120   133236    95103    38132

 App Summary
                       Pss(KB)
                        ------
           Java Heap:    11500
         Native Heap:    78136
                Code:    12840
               Stack:       56
            Graphics:    10588
       Private Other:    25552
              System:    10787

               TOTAL:   149459       TOTAL SWAP PSS:      120

 Objects
               Views:      258         ViewRootImpl:        1
         AppContexts:        7           Activities:        2
              Assets:        9        AssetManagers:        0
       Local Binders:       44        Proxy Binders:       53
       Parcel memory:       19         Parcel count:       78
    Death Recipients:        7      OpenSSL Sockets:        8
            WebViews:        0

 SQL
         MEMORY_USED:      728
  PAGECACHE_OVERFLOW:      148          MALLOC_SIZE:      117

 DATABASES
      pgsz     dbsz   Lookaside(b)          cache  Dbname
         4       40             54        12/26/7  /data/user/0/com.parkingwang.app/databases/pri_tencent_analysis.db_com.parkingwang.app
         4       56             90       37/53/12  /data/user/0/com.parkingwang.app/databases/tencent_analysis.db_com.parkingwang.app
         4       52            109       43/29/14  /data/user/0/com.parkingwang.app/databases/bugly_db_
         4       28             18         0/16/1  /data/user/0/com.parkingwang.app/databases/parkingwang.db

 获取CPU信息

//#获取CPU信息【adb shell top -n 1 | findstr 进程名】
C:\Users\EDY>adb shell top -n 1 | findstr u0_a795
 5682 u0_a795      10 -10 7.3G 270M 127M S 50.0   3.5   1:10.71 com.parkingwang+

获取电量信息

C:\Users\EDY>adb shell dumpsys  battery
Current Battery Service state:
  AC powered: false
  USB powered: true
  Wireless powered: false
  Max charging current: 500000
  Max charging voltage: 5026000
  Charge counter: 20000
  status: 5
  health: 2
  present: true
  level: 100
  scale: 100
  voltage: 4328
  temperature: 280
  technology: Li-poly

获取uid

C:\Users\EDY>adb shell cat /proc/5682/status
Name:   parkingwang.app
Umask:  0077
State:  S (sleeping)
Tgid:   5682
Ngid:   0
Pid:    5682
PPid:   692
TracerPid:      0
Uid:    10795   10795   10795   10795
Gid:    10795   10795   10795   10795
FDSize: 256
Groups: 3003 9997 20795 50795 12801023 12809997
VmPeak:  7964172 kB
VmSize:  7598220 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:    335424 kB
VmRSS:    267128 kB
RssAnon:          138672 kB
RssFile:          126884 kB
RssShmem:           1572 kB
VmData:  1642556 kB
VmStk:      8192 kB
VmExe:        28 kB
VmLib:    249152 kB
VmPTE:      2044 kB
VmPMD:        44 kB
VmSwap:    12160 kB
Threads:        82
SigQ:   0/26238
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000080001200
SigIgn: 0000000000001001
SigCgt: 0000000e400084fc
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000
CapAmb: 0000000000000000
NoNewPrivs:     0
Seccomp:        2
Speculation_Store_Bypass:       thread vulnerable
Cpus_allowed:   0f
Cpus_allowed_list:      0-3
Mems_allowed:   1
Mems_allowed_list:      0
voluntary_ctxt_switches:        39834
nonvoluntary_ctxt_switches:     14795

 

posted @ 2022-03-01 17:22  无耿  阅读(673)  评论(0编辑  收藏  举报