App automation: adb command summary


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.
Please add image description
Please add image description
Please add image description
Please add image description

3. Start the software
  1. Click the corresponding apk coordinates
adb shell input tap x y

For example
Insert image description here
, enter the command, adb shell input tap 235 744

Insert image description here

  1. Find the corresponding apk startup class
adb shell pm list package -3
# 找到当前使用过的apk包名称
adb shell dumpsys package 包名称 | findstr "SplashActivity"
# 找对应包启动类
adb shell am start 包启动类 
# 启动apk

Please add image description
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)

Please add image description

adb shell dumpsys window | findstr mCurrentFocus

Find out the software class of the running window
Please add image description

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

Please add image description
Filter warning logs:

adb logcat *:E

Export log information to local computer

adb logcat *:E  >>  日志文件路径

Please add image description
Please add image description

5. Simulate click
adb  shell   input   tap   x  y

Please add image description
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
Insert image description here

7. Enter text
adb shell input text "文字"

If you input English
Insert image description here
or Chinese, you will be unable to input, use the following command:

adb shell am broadcast -a ADB_INPUT_TEXT --es msg "深圳技术"

Please add image description
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
# 重置电量信息

Please add image description
Please add image description

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 本地文件路径 模拟器存储路径

Please add image description
Please add image description
Copy files from the emulator to your local computer

adb pull 文件路径 本地电脑目录

Please add image description

Guess you like

Origin blog.csdn.net/qq_45404396/article/details/135077318