adb 命令速查(下)

ADB 关于APP安装、调试和monkey压力测试

作者:炭烤毛蛋 ,查看博主了解更多。


提示:承接上篇《adb 命令速查(中)》,本文简述adb 关于APP相关操作以及Monkey测试。


7 adb 关于 apk 的相关操作

7.1 安装 apk

普通安装

adb install [option] <apkflile>
ex: adb install baidu.apk

带有命令行的安装

-l(关于forward lock)

adb install -l test.apk #forward lock application

-r 替换已存在应用,保留数据和缓存文件

adb install -r test.apk #replace existing application

-t 测试package标志

adb install -t test.apk #allow test packages

-s 将应用安装到sdcard

adb install -s test.apk #install application on sdcard

-d 忽略版本号安装apk

adb install -d test.apk #allow version code downgrade

-p 部分安装apk标志

adb install -p test.apk #partial application install

7.2 卸载 apk

adb uninstall <packageName>

adb uninstall com.baidu.search

卸载app 但保留数据和缓存文件

adb uninstall -k <packageName>

adb uninstall -k com.baidu.search

7.3 查看已经安装的APK

查看已经安装的包名

adb shell pm list packages
#根据包名查找
adb shell pm list packages | grep -i "package_name"

查看APK安装路径

adb shell pm path \[APK name\]
adb shell pm /odm/

7.4 把安卓系统中的APK拖到本地

# 没有最后参数,默认会拖到当前目录
adb pull \[APK-path\] \[saving apk path\]
 **remote couldn\'t create file: Read-only file system**

 解决方法:adb push path\\file /path (原来为 \\path)

7.5 启动activity

adb shell am start -n 包名/包名+类名(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据,等)

adb shell am start -n com.android.camera2/com.android.camera.CameraLauncher

adb shell启动APK方法

am 包名+活动名启动 APP

  • am start -n 包(package)名/包名.活动(activity)名称

  • adb shell “am start -n 包(package)名/包名.活动(activity)名称”

  1. 计算器(calculator)的启动方法为:
am start -n com.android.calculator2/com.android.calculator2.Calculator
2) **calendar(日历)的启动方法为:**
am start -n
 com.android.calendar/com.android.calendar.LaunchActivity
  1. AlarmClock(闹钟)的启动方法为:
am start -n
com.android.alarmclock/com.android.alarmclock.AlarmClock

启动APP对应服务

启动的方法可以从每个应用的AndroidManifest.xml的文件中得到

Music 和 Video(音乐和视频)的启动方法为例:

  1. 启动 Music
am start -n
com.android.music/com.android.music.MusicBrowserActivity
  1. 启动 Video
am start -n
com.android.music/com.android.music.VideoBrowserActivity
  1. 启动 Media
am start -n
com.android.music/com.android.music.MediaPlaybackActivity

其它应用启动方法

  1. Camera(照相机)的启动方法为:\
am start -n com.android.camera/com.android.camera.Camera
  1. Browser(浏览器)的启动方法为:\
am start -n com.android.browser/com.android.browser.BrowserActivity
  1. 启动浏览器 :\
am start -a android.intent.action.VIEW
-d  [[http://www.google.cn/]{
    
    .underline}](http://www.google.cn/)
  1. 拨打电话 :\
am start -a android.intent.action.CALL -d
 [[tel:10086]{
    
    .underline}](tel:10086)
  1. 启动 google map 直接定位到北京 :\
am start -a android.intent.action.VIEW geo:0,0?q=beijing

am 命令详细参数

usage: am \[subcommand\] \[options\]

start an Activity: am start \[-D\]

-D: enable debugging

send a broadcast Intent: am broadcast

start an Instrumentation: am instrument \[flags\]

-r: print raw results (otherwise decode REPORT\_KEY\_STREAMRESULT)

-e : set argument to

-p : write profiling data to

-w: wait for instrumentation to finish before returning

start profiling: am profile start

stop profiling: am profile stop

specifications include these flags:

\[-a \] \[-d \] \[-t \]

\[-c \[-c \] \...\]

\[-e\|\--es \...\]

\[\--ez \...\]

\[-e\|\--ei \...\]

\[-n \] \[-f \] \[\]

8 monkey 测试

  • 1)Monkey程序由Android系统自带,使用Java诧言写成,在Android文件系统中的存放路径是:
    /system/framework/monkey.jar;

  • 2)Monkey.jar程序是由一个名为"monkey"的Shell脚本来启动执行,shell脚本在Android文件系统中
    的存放路径是:/system/bin/monkey;

  • 3)Monkey 命令启动方式:

a)可以通过PC机CMD窗口中执行:

adb shell monkey{+命令参数}来进行Monkey测试

b)在PC上adb shell 进入Android系统,通过执行 monkey {+命令参数}

来进行Monkey 测试

c ) 在Android机或者模拟器上直接执行monkey

命令,可以在Android机上安装Android终端模拟器

monkey 参数
在这里插入图片描述

8.1 Monkey 命令 基本参数介绍

-p <允许的包名列表>

用此参数指定一个或多个包。指定包之后,monkey将只允许系统启动指定的app。如果丌指定包,
monkey将允许系统启动设备中的所有app。

指定一个包:

adb shell monkey -p com.shjt.map 100

指定多个包:

adb shell monkey -p fishjoy.control.menu  --p com.shjt.map 
100 

-v 用亍指定反馈信息级别(信息级别就是日志的详细程度),总共分3个级别,分别对应的参数如下
表所示:
Level 0 : adb shell monkey -p com.shjt.map -v 100 //
缺省值,仅提供启动提示、测试完成和最终结果等少量信息
Level 1 : adb shell monkey -p com.shjt.map -v -v 100 //
提供较为详细的日志,包括每个发送到Activity的事件信息
Level 2 : adb shell monkey -p com.shjt.map -v -v -v 100 //
最详细的日志,包括了测试中选中/未选中的Activity信息

-s(随机数种子)
用亍指定伪随机数生成器的seed值,如果seed相同,则两次Monkey测试所产生的事件序列也相同的。

monkey测试1:adb shell monkey -p com.shjt.map --s 10 100 #\--throttle \<毫秒\>            

用亍指定用户操作(即事件)间的时延,单位是毫秒;如果丌指定这个参数,monkey会尽可能快的生成和发送消息。

adb shell monkey -p com.shjt.map \--throttle 3000 100

Monkey 实例用monkey 命令 对 app进行 性能测试

adb shell monkey --p com.shjt.map ---throttle 100 ---pct-touch 50 ---pct-motion 50 --v --v 1000 \>c:\\monkey.txt

结语

好工具提升工作效率。不枉博主一片辛苦,欢迎订阅博主–炭烤毛蛋

猜你喜欢

转载自blog.csdn.net/weixin_35723192/article/details/130877164