Appium启动关闭App过程的adb命令

从日志分析Appium启动、关闭Android App过程中调用的adb命令,如下:

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
adb shell pm list packages com.tracenote.test
检查目标App有没有安装

adb wait-for-device
阻塞,等待目标设备连接成功

adb shell echo ping
测试 adb shell?

adb install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk
安装Appium输入法App

adb shell settings get secure default_input_method
获取当前默认输入法

adb shell ime enable io.appium.android.ime/.UnicodeIME
使Appium输入法可用

adb shell ime set io.appium.android.ime/.UnicodeIME
设置输入法为Appium输入法

adb shell pm list packages io.appium.settings
检查Appium Settings App是否安装

adb shell dumpsys package io.appium.settings
获取Appium Settings App包信息(这里是为取版本号)

adb shell getprop ro.build.version.sdk
获取Android系统API版本号,比如返回23表明是Android 6.0

adb shell dumpsys package io.appium.settings
获取Appium Settings App包信息(这里是为取权限?)

adb shell pm dump io.appium.settings
获取Appium Settings App包系统状态信息

adb shell pm grant io.appium.settings android.permission.CHANGE_NETWORK_STATE ; pm grant io.appium.settings android.permission.WRITE_SETTINGS ; pm grant io.appium.settings android.permission.ACCESS_MOCK_LOCATION ;
设置相应权限

adb install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk
安装 unlock app

adb shell appops set io.appium.settings android:mock_location allow
允许 mock location

adb shell getprop ro.build.version.release
获取系统版本,如返回:6.0

adb shell wm size
获取屏幕分辨率,如返回:Physical size: 1080x1920

adb shell getprop ro.product.model
获取设备产品型号,如返回:HUAWEI MT7-TL00

adb shell getprop ro.product.manufacturer
获取设备厂商,如返回:HUAWEI

adb forward tcp:4724 tcp:4724
重定向tcp端口(由于使用的默认端口,这里实际没有变化)

adb push /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/
上传AppiumBootstrap.jar到手机data目录(Appium Bootstrap在手机上会启动一个socket server, 接受PC命令并解析给UiAutomator)

adb shell ps
用来检查uiautomator process,有则kill

adb shell dumpsys window
此处是appium用来判断是否锁屏的,检查返回的mShowingLockscreen(mShowingLockscreen=true,锁屏,需要解锁)

adb shell am force-stop io.appium.unlock
强制关闭unlock App

adb shell am start -W -n io.appium.unlock/.Unlock -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000
解锁屏幕

adb shell dumpsys window
确认解锁成功

adb shell am start -W -n com.tracenote.test/com.tracenote.test.activity.GuideActivity -S
启动目标App的目标Activity





adb shell ime set com.nuance.swype.emui/com.nuance.swype.input.HuaweiIME
恢复设备输入法

adb shell am force-stop com.tracenote.test
停止目标App

adb shell input keyevent 3
按home键(4是back键)

adb shell ps
用来检查是否有uiautomator process需要kill

adb shell am force-stop io.appium.unlock
强制关闭unlock App

备注:

  • 省略”-P”,5037,”-s”,”P4M7N15411025011”端口号和设备等信息
  • Appium版本号:Version 1.2.0-beta.3 (1.2.0-beta.3)
    Server: v1.6.5