App automation: adb command summary
-
-
-
- 1. Connect to the local Night God simulator
- 2. Install apk to the emulator
- 3. Start the software
- 4. Monitor log information
- 5. Simulate click
- 6. Slide
- 7. Enter text
- 8 Modify battery information
- 9 Restart android
- 10 Upload files to the simulator and copy files from the simulator to the local computer
-
-
1. Connect to the local Night God simulator
Need to open the Yashen simulator:
adb connect 127.0.0.1:62001
If it is another emulator, just change the corresponding port number.
Thunderbolt: 5555
Xiaoyao Simulator: 21503
If you connect a real machine, turn on the developer mode of the real machine, connect it to the local computer with a data cable, and turn on USB debugging, you do not need to execute the above command, it will connect automatically (under normal circumstances)
If you cannot connect to the simulator, use the following two commands:
adb kill-server
adb start-server
Use kill-server when the device status is abnormal, and then run start-server to restart the service
or
these two commands
adb nodaemon server (重启守护进程)
adb start-server
Disconnect
adb disconnect
Disconnect everything
adb disconnect 127.0.0.1:62001
Disconnect from Yagami Simulator
2. Install apk to the emulator
Install
adb install 本地电脑apk文件路径
uninstall
adb uninstall apk包名称
View apk package name
adb shell pm list package
This command displays all apk package names
adb shell pm list package -3
This command checks the name of the installed apk application package (excluding the one that comes with the phone)
and uninstalls the Bilibili apk.
3. Start the software
- Click the corresponding apk coordinates
adb shell input tap x y
For example
, enter the command, adb shell input tap 235 744
- Find the corresponding apk startup class
adb shell pm list package -3
# 找到当前使用过的apk包名称
adb shell dumpsys package 包名称 | findstr "SplashActivity"
# 找对应包启动类
adb shell am start 包启动类
# 启动apk
In addition, the command to find the startup class of the application is as follows:
adb shell dumpsys activity |findstr "mFocuse"
The startup class of the currently opened apk application (the corresponding apk application needs to be opened)
adb shell dumpsys window | findstr mCurrentFocus
Find out the software class of the running window
4. Monitor log information
adb lgcat
Filter log information
adb logcat | findstr "字段"
The five major levels of logs
: debug (debug), error (error), info (message), warning (warning), and fatal (fatal)
respectively correspond to: D, E, I, W, and F
Filter warning logs:
adb logcat *:E
Export log information to local computer
adb logcat *:E >> 日志文件路径
5. Simulate click
adb shell input tap x y
Open the simulator developer options and turn on the pointer position option to obtain the corresponding pointer x and y coordinates.
6. Slide
adb shell input swipe x1 y1 x2 y2 500
500 represents sliding time, milliseconds
7. Enter text
adb shell input text "文字"
If you input English
or Chinese, you will be unable to input, use the following command:
adb shell am broadcast -a ADB_INPUT_TEXT --es msg "深圳技术"
But you need to install the input method ADBKeyBoard.apk on your mobile phone. You can read this tutorial: Solution to adb unable to input Chinese
8 Modify battery information
adb shell dumpsys battery set status 1
# 不充电
adb shell dumpsys battery set status 2
# 充电
adb shell dumpsys battery set level 电池容量
# 设置电量
adb shell dumpsys battery reset
# 重置电量信息
9 Restart android
adb reboot
10 Upload files to the simulator and copy files from the simulator to the local computer
Upload files to the simulator
adb push 本地文件路径 模拟器存储路径
Copy files from the emulator to your local computer
adb pull 文件路径 本地电脑目录