adb与monkey必备命令

一、adb原理

全称:Android Debug Bridge
adb clientadb serveradb demon
包含三部分,adb客户端,adb服务端,守护进程(终端–手机),默认端口为5037
客户端发送命令给服务端,服务端接收后发送给手机,手机执行后通过服务端反馈给客户端

二、adb常用命令

adb devices:检查电脑连接的设备
adb install 包的路径:安装应用程序
adb uninstall 包名:卸载应用程序
adb pull 手机路径 电脑路径:从手机上拉取文件到电脑上(手机路径一定要包含文件名)
adb push 电脑路径 手机路径:从电脑上推送文件到手机上(电脑路径一定要包含文件名)
adb start-server :启动服务器
adb kill-server :停止服务器
adb shell am force-stop 包名 :强制关闭应用程序
adb shell :进入linux系统
adb shell dumpsys activity | findstr "mResume" :获取当前包名/界面名
adb logcat | findstr Displayed :获取当前包名/界面名
adb shell input top x y :点击APP,x和y为坐标
adb shell input text 文本信息:输入文本信息,不支持中文
adb shell am start -W 包名/界面名:启动APP
adb shell am start -n 包名/界面名 -S :启动APP,-S是启动前先杀掉这个进程
adb shell pm clear 包名:清除应用程序缓存数据
adb shell pm list package:获取手机上所有的应用程序
package后面参数:
-f :所有应用程序包名,跟不加效果是一样的
-s:获取系统的应用程序报名包名
-3:获取第三方应用程序包名
adb shell am start -W 包名/界面名 :获取APP启动时间
This time–>activity
Total time–>Application+activity
wait time–>系统+Application+activity
启动时间看Total time,Application一般不会有,
无标准时启动时间应不超同类软件启动时间1倍
adb logcat -v time > 路径 :获取日志并输出到指定的文件中,-v time是给日志加时间戳
日志中开头字母含义:
V:常规
D:debug
I:info
W:警告
E:错误
日志中查找崩溃信息:在文中搜索FATAL EXCEPTION
日志中查找ANR信息:在文中搜索anr in

三、monkey常用命令

日志必须写在倒数第二,事件数写在倒数第一,其他命令不分顺序
-p : 指定包名
adb shell monkey -p 包名 1000 :-p是指定一个包或多个包,1000是事件次数
adb shell monkey -p 包名 -p 包名 500 :对每个包进行500次事件

-v 日志级别
三个级别,三个V级别最高,信息最全
adb shell monkey -p 包名 -v -v -v 500

-s 伪随机生成器,两次执行顺序是一致,便于问题复现
adb shell -s 200 100
adb shell -s 200 100

–throttle(毫秒),延时操作
延时1000毫秒,事件10
adb shell monkey -p 包名 --throttle 1000 10

–randomize-throttle 事件之间随机延时
100次事件中,每次事件间隔在0-1000毫秒之间不固定
adb shell monkey -p 包名 --throttle 1000 --randomize 100

–pkg-whitelist-file 将多个包名写到一个文件中,并运行这个文件,事件数1000
adb shell monkey --pkg-whitelist-file 文件路径 1000

–ignore-crashes 程序崩溃后继续执行(crash)

–ignore-timeouts 不管在何时发生超时错误都继续执行(ANR)

–ignore-security-exceptions 发生权限错误时继续执行

–pct-touch 50 touch操作占比50%

你可能感兴趣的:(工具使用)