[APP] basic black box testing direction: adb command

1, adb basic commands

1.1 Basic

  1. View adb version: Check the configuration and use adb information about the version
adb version
  1. View connected devices: Check the device using links
adb devices
  1. Remote Control & Exit Control Equipment: View device files
adb shell
exit
  1. Link device
adb connect [<host>[:<port>]](默认端口号是:5555)
  1. Execute remote shell command
adb shell <command>
  1. Copy the file to the device:
 adb push <local> <remote>
  1. Copy the files from the device:
 adb pull <remote> [<local>]
  1. View all devices:
 adb bugreport #包括 bug 报告
  1. View command help:
adb help 

1.2, apk related

  1. Install apk file
adb install <file>
  1. Uninstall app
# 参数-k 可选,用作卸载软件但保留配置文件和缓存
adb uninstall -k <package>
  1. View app all relevant information (including information action, codepath, verion, etc. need permission)
adb adb shell dumpsys package <package_name>
  1. View app path
adb shell pm path <package_name>
  1. View apk version information
adb shell dumpsys package <package_name> |grepversion

2, advanced command

2.1, adb logcat related

  1. View Log
adb logcat
  1. Save Log
adb logcat > <file>
  1. From the beginning of the current display
#logcat有缓存,先清空之前的再查看log即从当前开始显示
adb logcat -c && adb logcat
  1. grep filtration, using the same pipe command linux
adb logcat |grep MyLog #不忽略大小写
adb logcat |grep -i Mylog #忽略大小写
  1. Filter tag name
adb logcat -s <TAG_NAME>
adb logcat -s <TAG_NAME_1> <TAG_NAME_2>
  1. Log priority
priority Explanation
V Rule (lowest priority)
D debugging
I information
W caveat
E error
F fatal
S Silent (highest priority, will not print any information)
  1. Clear Log fast
adb logcat -c

2.2, service-related

  1. Adb start & terminate service
adb start-server
adb kill-server
  1. Restart adb as root
adb root
  1. The system partition is re-writable hanging partition (This command is very important when operating system directory)
adb remount
  1. Reboot (optional)
adb reboot [brootloader] # 刷机模式
adb reboot [recovery] # 恢复模式
  1. Memory usage of each process in detail ways to view memory usage and system
# Total PSS信息是应用真正占内存的大小,通过这个信息可以判断手机中那些程序占内存比较大
adb shell dumpsys meminfo
# 部分设备支持
# VSS -virtual Size虚拟好用内存(包括功效库占用内存)
# RSS -Resident Set Size 实际使用武力内存(包含共享库占用内存)
# PSS -proportianal Set Size 实际使用武力内存(比例分配共享库占用的内存)
# USS -Unique Set Size 进程独自占用的武力内存(不包含共享库占用的内存)
adb shell procrank
# 查看设备上进程的CPU和内存占用情况
adb shell top
  1. View alarm system settings
adb shell dumpsys alarm
  1. View system Wakelock: wakelock unreasonable use can lead to increased system power consumption
adb shell dumpsys power

2.3, apk related

  1. Start activity
adb shell dumpsys window | findstr mCurentFocus #查看当前运行的报名和Activity
adb shell am start -n <package_name>/<activity_class_name>
  1. Clear Package Dependencies
adb shell pm clear <package> # 清除应用数据、删除与包相关的所有数据:清楚数据缓存
  1. Obtain application start time: returns the result WaitTime subject returned to the application is the time from the first frame startActivity fully displayed.
adb sell am start -W <package_name>/<activity_class_name>
  1. Start server
# 参数-n 表示组件
# 参数-a 表示命令,后面参数为mainfrest中定义的sevice的action
adb shell am startservice -n <package_name>/<service_class_name>
# 举例
adb shell am startservice -a "android.intent.action.CALL"
  1. Send broadcast
# 参数-es 为String 参数类型
# 参数-ei 为int 参数类型
# 参数-ez 为boolean参数类型
adb shell am broadcast -a"android.intent.action.AdupsFata.WriteCommandReceiver"
  1. View an app's process-related information
# 两种方式分别在部分手机可用
adb shell ps <package_name|PID>
adb shell ps | grep <package_name>
  1. Kill a process: a simulation language bug reproducibility
adb shell kill pid Number
  1. View an app's memory footprint
# Heap size包括了Dalvik Heap和Native Heap
adb shell dumpsys meminfo <package_name|PID>
  1. Check the maximum memory limit of a single application
# 如果得到结果小于Dalvik Heap size,就很可能发生OOM
adb shell dumpsys memin
  1. Gets a single application of power consumption information
# Android5.0引入,可获得系统耗电信息原始数据
adb shell dumpsys batterystats > <pacage_name> > xx.txt
# 科通过google编写的histian.py,转化为列表数据
python historian.py xx.txt >xx.html

System-related

  1. Check the device name (device name is to get a third-party app by this method)
adb shell cat /system/build.prop/
  1. View phone resolution
# 方法1:使用grep过滤
adb shell dumpsys window | grep surface
# 方法2:直接查询
adb shell wmsize
  1. View phone model information
adb shell cat /system/build.prop/
  1. View phone model information
# product,brand,CPU等型号信息
adb shell getprop | grep product
  1. Obtain the serial number: serial number that is listed adb devices
adb get-serialno
  1. Connecting a plurality of devices, wherein a device operating
# 参数 -d 真机(多个设备中只有一个真机时使用)
# 参数 -s 序列号
# 参数 -e 模拟器(多个设备中只有一个是虚拟机时使用)
adb [-d|-e|-s <serial Number> ] <command>
  1. View wifi password (requires root privileges)
adb shell cat data/misc/wifi/*.conf
  1. View wifi mac address
adb shell cat /sys/chlass/net/wlan0/address
  1. View background information services
adb shell service list

10. Check the system memory usage

adb shell cat /proc/meminfo

File-related operations (basic operations with linux)

  1. Copy the file / directory to the device
adb push <local> <remote>
  1. Copy files from the device / directory
# 参数 -a 保留了文件的时间戳和模式
adb pull [-a] <remote> <local>
  1. View device log
# 同Android Studio/Eclipse的logcat
# 参数 -s 过滤置顶参数log
# 参数 -v time 保留日志时间
# >>追加写,>覆盖写
adb logcat
  1. Files in the directory are listed
# 参数 -al 可选,可查看文件和文件夹的详细信息
adb shell ls [-al]
  1. Into the folder
adb shell ce <folder>
  1. check the file
adb shell cat <filename>
  1. Rename the file
adb shell rename <file> <file>
  1. Delete files / folders
# 参数 -r 可选,同linux操作含义
adb shell rm path/filename -r 
  1. Moving Files
adb shell mv <源文件> <目标文件>
  1. Copy files
adb shell cp <源文件> <目标文件>
  1. Create a directory
adb shell mkdir <目录>
  1. Setting up file read and write permissions
adb shell chmod 777 <file>
  1. Not root the phone app to view certain file information
# 没有权限查看/data/data目录下的文件,运行后则可进入你的App下,再通过cp或者mv把需要的文件放在sdcard中进行操作
run -as package_name
  1. Database-related actions
# 无需将数据库pull出来再看,可直接查看db中的某个表或者字段
sqlit3 test.db

Monkey (subsequent supplementary detail)

adb shell monkey -v -p <package_name> 500 
# -p 对象包  -v 反馈信息级别
# :Monkey: seed=1493061025112 count=500 :AllowPackage:com.tencent.mm.app:push :IncludeCategory: android.intent.category.LAUNCHER:IncludeCategory: android.intent.category.MONKEY ** No activities found to run,monkey aborted.

Adb install

mac

brew cask install android-platform-tools

Content scenarios:

  1. No code permission, under conditions no black box development environment conditions, easy to view log
  2. automated test
  3. jeckens integration tests use
  4. Mobile Remote Access

References:

adb command Daquan

Released three original articles · won praise 0 · Views 37

Guess you like

Origin blog.csdn.net/tongqingshuo/article/details/104633894