每次面试总是会问一些adb,monkey命令,并且每次都要去搜索,过于麻烦,干脆自己整理出来,方便以后直接使用:
1.查看非系统安装的包名:$ adb shell pm list packages -3
2.查看包含指定信息的包名:$ grep ×××
3.查看指定打开的包名:$ adb shell monkey --port 1080 -v
待出现:IncludeCategory: android.intent.category.MONKEY后,点击手机上的应用,命令提示符中,便会出现相应的包名
4.查看当前打开的包名:$ adb shell dumpsys window |grep mCurrent
4.1:指定包名启动: adb shell monkey -p 包名 100
5.对此包进行300 次无规律点击测试在adb shell环境中:adb shell monkey -p 包名字 -v 300 > 电脑某一位置
6. 测试所有模块 monkey -s 23 --ignore-crashes --ignore-timeouts -v-v -v 100000> /data/local/tmp/log.txt 2>&1 & 或
monkey –p com.tencent.mtaexample -s 23 --throttle 2000 --ignore-crashes --ignore-timeouts -v -v -v 100000>/data/local/tmp/log.txt 2>&1 &
7.指定一个包:adb shell monkey -p com.htc.Weather 100 (即让Monkey程序模拟100次随机用户事件)
8.(1)日志级别 Level0:示例 adb shell monkey -p com.htc.Weather –v 100 说明缺省值,仅提供启动提示,测试完成和最终结果等少量信息
(2)日志级别 Level 1:示例 adb shell monkey -p com.htc.Weather –v -v 100 说明提供较为详细的日志,包括每个发送到Activity的事件信息
(3)日志级别 Level 2:示例 adb shell monkey -p com.htc.Weather –v -v –v 100 说明最详细的日志,包括了测试中选中/未选中的Activity信息
9.用于指定伪随机数生成器的seed值,如果seed相同,则两次Monkey测试所产生的事件序列也相同的。
* 示例:Monkey测试1:adb shell monkey -p com.htc.Weather –s 10 100
Monkey 测试2:adb shell monkey -p com.htc.Weather–s 10 100
10.用于指定用户操作(即事件)间的时延,单位是毫秒;
* 示例:adb shell monkey -p com.htc.Weather --throttle 3000 100
11.用于指定当应用程序崩溃时(Force& Close错误),Monkey是否停止运行。如果使用此参数,即使应用程序崩溃,Monkey依然会发送事件,直到事件计数完成。
*示例1:adb shell monkey -p com.htc.Weather --ignore-crashes 1000 (测试过程中即使Weather程序崩溃,Monkey依然会继续发送事件直到事件数目达到1000为止)
*示例2:adb shell monkey -p com.htc.Weather 1000 (测试过程中,如果Weather程序崩溃,Monkey将会停止运行)
12.如果想中断运行中的monkey CTRL+C
adb shell ps | grep monkey 返回进程号
adb shell kill [刚才查到的进程号]
13.adb logcat抓取当前Android机运行的app的包名命令行输入adb logcat > e:\bag.txt(手机操控app,ctrl+c停止,去e:\bag.txt这个文件下搜索关键字如Displayed ,一般都能找到!)
14. --ignore-security-exceptions:在设置此选项后,当应用程序发生任何权限错误(如启动需要某些权限的activity)时,monkey将继续运行直到计数完成。如果不设置此选项,monkey遇到此类权限错误将停止运行。
adb shell monkey --ignore-security-exceptions <event-count>
15.停止monkey测试:adb shell top | grep monkey(这时候只要kill掉这个id 就能停止)
16.日志分析
将log信息写到文档中:adb shell monkey 100 >c:/log/b.txt
正常情况, 如果Monkey测试顺利执行完成, 在log的最后, 会打印出当前执行事件的次数和所花费的时间; // Monkey finished 代表执行完成
随机数种子
用亍指定伪随机数生成器的seed值,如果seed相同,则两次Monkey测试所产生的事件序列也相同的。 示例:
monkey测试1:adb shell monkey -p com.shjt.map –s 10 100
monkey测试2:adb shell monkey -p com.shjt.map –s 10 100
Adb常用命令:
1、adb devices 查看手机设备
2、adb install packsge(包路径)安装包
3、adb install -r packages(保留数据及缓存文件安装新包)
4、adb uninstall package (卸载包)
5、adb kill-server 关闭adb服务
6、adb start-server 启动adb服务
7、adb shell pm list packages 查看手机里面所有包名
8、adb shell pm list packages -3查看手机里面所有第三方包名
9、adb shell /system/bin/screencap -p /sdcard/xx.png 截频并保存文件在手机上为xx.Png
10、adb pull /sdcard/xx.png D:/xx.png 将手机xx.png文件保存到D盘文件下
11、adb push D:/xx.text /adcard/xx.text 将电脑文件导入手机
12、adb shell pm clear com.ablesky.ui.activity 清除缓存数据
13、adb shell am start -n com.ablesky.ui.activity/com.ablesky.activity.SplashActivity 启动程序
14、adb shell am force-stop com.ablesky.simpleness.activity 强制停止运行程序
15、adb logcat 查看日志
16、adb logcat > D:\log.txt 将日志打印到电脑上
17、netstat -aon|findstr “5037” 查看被占用端口对应的PID
18、 tasklist /fi “PID eq PID号” 查看端口号对应的进程
19、 taskkill /pid 2027 /f 杀掉某进程
20、adb shell monkey -p 包名 100 指定APP产生随机事件100次
21、adb shell monkey -p 包名 -v -v 100 指定APP产生随机事件100次并发送详细的activity信息
进阶命令
1、获取手机系统信息( CPU,厂商名称等)
adb shell “cat /system/build.prop | grep “product””
2、获取手机系统版本
adb shell getprop ro.build.version.release
3、获取手机系统api版本
adb shell getprop ro.build.version.sdk
4、获取手机设备型号
adb -d shell getprop ro.product.model
5、获取手机厂商名称
adb -d shell getprop ro.product.brand
6、获取手机的序列号
有两种方式
1、 adb get-serialno
2、 adb shell getprop ro.serialno
7、获取手机的IMEI
有三种方式,由于手机和系统的限制,不一定获取到
1、 adb shell dumpsys iphonesubinfo其中Device ID即为IMEI号
2、 adb shell getprop gsm.baseband.imei
3、 service call iphonesubinfo 1
此种方式,需要自己处理获取的信息得到
8、获取手机mac地址
adb shell cat /sys/class/net/wlan0/address
9、获取手机内存信息
adb shell cat /proc/meminfo
10、获取手机存储信息
adb shell df
获取手机内部存储信息:
魅族手机: adb shell df /mnt/shell/emulated
其他: adb shell df /data
获取sdcard存储信息:
adb shell df /storage/sdcard
11、获取手机分辨率
adb shell “dumpsys window | grep mUnrestrictedScreen”
12、获取手机物理密度
adb shell wm density
13、获取手机包名
1.查看指定apk的包名:aapt dump badging +包的全路径
2.查看所有apk包名:adb shell pm list package -f