Airtest IDE 自动化测试11 - 查看手机上app的包名 几种方式
前言
启动指定的app,需知道app的包名,app已经安装到手机上了,如何查看安装的包名呢?
adb shell
查看手机上所有app的包名
备注:airtest 连接上手机,则adb 会查不到这个手机设备;
1
|
adb shell pm list packages |
查询结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
C:\Users\Administrator>adb shell pm list packages package:com.android.cts.priv.ctsshim package:com.android.providers.telephony package:com.android.providers.calendar package:com.android.providers.media package:com.android.documentsui package:com.android.externalstorage package:com.android.htmlviewer package:com.android.mms.service package:com.android.providers.downloads package:com.android.browser package:com.netease.edu.study package:com.android.inputmethod.pinyin package:com.android.defcontainer package:com.android.providers.downloads.ui package:com.android.pacprocessor package:com.netease.nie.yosemite package:com.android.certinstaller package:com.android.carrierconfig package:android package:com.android.contacts package:com.android.mtp package:com.android.launcher3 package:com.android.statementservice package:com.android.providers.settings package:com.android.sharedstoragebackup package:com.android.printspooler package:com.android.webview package:android.ext.shared package:com.android.server.telecom package:com.android.keychain package:com.android.gallery3d package:com.android.flysilkworm package:android.ext.services package:com.android.packageinstaller package:com.android.basicsmsreceiver package:com.android.proxyhandler package:com.gotokeep.keep package:com.cyanogenmod.filemanager package:com.android.googleinstaller package:com.netease. open .pocoservice package:com.android.storagemanager package:com.android.bookmarkprovider package:com.android.settings package:com.android.cts.ctsshim package:com.android.vpndialogs package:com.android.phone package:com.android.shell package:com.android.wallpaperbackup package:com.android.providers.blockednumber package:com.android.providers.userdictionary package:com.android.location.fused package:com.android.systemui package:com.android.providers.contacts package:com.android.captiveportallogin package:com.android.coreservice C:\Users\Administrator> |
这个命令能列出所有的 app 包名,但你要找到自己想启动的app,比如网易云课程app,那就只能靠猜才知道。
查看正在运行 app 的包名
可以在手机上打开 app,windows 系统用findstr 过滤,cmd 输入
1
|
adb shell dumpsys window | findstr mCurrentFocus |
运行结果
1
2
3
|
C:\Users\Administrator>adb shell dumpsys window | findstr mCurrentFocus mCurrentFocus = Window{ 6b1a4a u0 com.netease.edu.study / com.netease.edu.study.mai n.activity.ActivityMain} |
于是可以查到包名:com.netease.edu.study
当前正在启动的activity名称:com.netease.edu.study.main.activity.ActivityMain
查看启动activity
appium自动化的时候,需获取启动名 launcherActivity。在手机上安装app、打开app出现启动页的时候,在cmd中输入
1
|
adb shell dumpsys activity activities | findstr "Run" |
于是可以看到带‘main’的就是启动名 launcherActivity
1
2
3
4
5
6
7
8
|
C:\Users\Administrator>adb shell dumpsys activity activities | findstr "Run" Running activities (most recent first): Run #0: ActivityRecord{ddd2e54 u0 com.netease.edu.study/.main.activity.A ctivityMain t4} Running activities (most recent first): Run #0: ActivityRecord{70ccef0 u0 com.android.launcher3/.Launcher t2} C:\Users\Administrator> |
查看到启动名:com.netease.edu.study.main.activity.activityMain