当前位置:网站首页>The simple use of ADB command combined with monkey is super detailed
The simple use of ADB command combined with monkey is super detailed
2022-07-23 21:55:00 【Code Xiaoyi】
One :ADB brief introduction
1, What is? adb:
ADB Its full name is Android Debug Bridge, Play the role of debugging bridge , It's a client - Server side program . The client is the computer used to operate , The server is Android equipment .ADB It's also Android SDK One of the tools in , It can be operated and managed directly Android Simulator or real Android equipment .
2, Why use adb:
Operating equipment shell( Command line )
Manage port mapping for emulators or devices
Upload between computer and device / Download the file
You can uninstall and install the application of the device
stay App encounter ANR/Crash etc. bug when , Can pass ADB To grab logs
In short ,ADB It's the connection Android Mobile phone and PC End bridge , therefore ADB Also known as Android debugging Bridge ( Be careful : It's Android , No iOS), Can let the user carry on the comprehensive operation to the mobile phone on the computer !
Two : Preparation conditions
1, Download and install ADB
link :
https://pan.baidu.com/s/18pIS1QtvqR3td34pMsCJ2Q
Extraction code :2e34
2, Configure environment variables
After decompression and installation , Put the decompression path into the system variable (Path),
How environment variables are configured , For example, my configuration is shown in the figure below :
3, Connect
You can connect through the simulator , It can also be connected through data cable . When connected through data cable , Cell phone access “ Developer options ”, open “usb debugging ”.
Android models of different brands , Open for the first time “ Developer options ” In a different way , Most of them double-click the mobile phone version number 3~5 Time , Meeting toast remind “ Developer mode is turned on ”, The specific opening method can be queried by Baidu according to the mobile phone brand .
4, Turn on the computer cmd window

3、 ... and :ADB Detailed command
1, Basic commands
adb version : Show adb edition 
adb help: Help information , see adb All commands supported 
adb devices: View currently connected devices , Connected devices will be displayed 
adb get-serialno: You can also check the device number 
2, Authority order
adb root: obtain Android Administrators (root user ) Authority .
Be careful : General testing machines can be used root jurisdiction .
Android edition 9 above , It does not support the use of commercial machines root jurisdiction , But you can modify some of the underlying configurations :https://www.cnblogs.com/jeason1997/p/12410537.html
adb shell: Log in to the device shell, This command will log in to the shell( kernel ), Sign in shell after , have access to cd,ls,rm etc. Linux command 
adb remount: obtain System Partition writable permissions , need root Before you can have this permission
3, Establishing a connection
adb -d: If connected at the same time usb, Open the simulator again , The connection is currently only through usb Connected Android devices
adb -e shell: Specify the only emulator currently connected to this computer
adb -s < Device number > shell: When the computer is plugged into multiple mobile phones or simulators , Specify a device number to connect 
exit: sign out 
adb kill-server: Kill the current adb service , If the device cannot be connected , Kill and restart .( Don't use it if you have nothing )
adb start-server: Kill and restart ,
5037:adb Default port , If the port is occupied , You can specify a port number , Following commands ↓
adb -p 6666 start-server: Specify any adb shell The port of 
4,apk Operating instructions
adb shell pm list packages: List current devices / mobile phone , All package names 
adb shell pm list packages -f: Display the package and the files associated with the package ( The installation path )
adb shell pm list packages -d: Display disabled package names
adb shell pm list packages -e: Displays the currently enabled package name
adb shell pm list packages -s: Display the system application package name
adb shell pm list packages -3: Display the package name of the installed third party
adb shell pm list packages xxxx: Add the package name that needs to be filtered , Such as :xxx = taobao
adb install < File path \apk>: Local apk Install the software to the device ( mobile phone ) On . For example, password is required for external installation of mobile phone , Remember to input the password on your mobile phone .
adb install -r < File path \apk>: Overlay installation 
adb install -d < File path \apk>: Allow demotion to override installation
adb install -g < File path \apk>: to grant authorization / Access permissions , Open all permissions when installing the software
adb uninstall < Package name >: Uninstall the software /app.
Be careful : When installing, install apk, When uninstalling, it is the package name , Can pass adb shell pm list packages Check the package name that needs to be uninstalled .
adb shell pm uninstall -k < Package name >: Although uninstall this app , But still save the data and cache of this application
adb shell am force-stop < Package name >: Force the application to exit /app
5, File operation instructions
adb push < The local path \ Documents or folders > < Mobile end path >: The local (pc machine ) Copy files or folders of to the device ( mobile phone )
Be careful 1:pc Machine path and Android Machine path , The separator is different .
Be careful 2: copy failed , The probability is no authority . You can first use the two commands described above :adb root;adb remount. In the use of adb push command
adb pull < Mobile end path / Documents or folders > <pc Machine path >: Put the equipment ( mobile phone ) Copy your files or folders to local . Note the same as above 
6, Log operation instructions
adb shell logcat -c: Clean up existing logs
adb shell logcat -v time : Output log , The information is output on the console
adb shell logcat -v time > < Storage path \log.txt>: Output the log and save it in a local file
Ctrl+C: Stop log fetching
adb shell logcat -v time *:E > < Storage path \log.txt>: The printing level is Error Information about
The level of the Journal :
-v:Verbse( Detailed )
-d:Debug( debugging )
-i:Info( Information )
-w:Warn( Warning )
-e:Error( error )
-f:Fatal( Serious mistakes )
To grab the log, first enter the command to start the log , Then operate App, Reappear bug, Again ctrl+c Stop logging , Analyze locally saved files .
: The log is to record the operation of the mobile phone system app When there are any abnormal events
EXCEPTION
You can also make it more detailed Anr Pull out the log :adb shell pull /data/anr/traces.txt < Storage path >
7, System operating instructions
adb shell getprop ro.product.model: Get the device model 
adb shell getprop ro.build.version.release: obtain Android System version 
adb get-serialno: Get the serial number of the device ( Device number )
adb shell wm size: Get the device screen resolution 
adb shell screencap -p /sdcard/mms.png: Screen capture
adb shell screencap -p /sdcard/screenshot.png: Screen capture 

adb pull /sdcard/mms.png < Storage path >: Export screenshots to local
adb pull /sdcard/screenshot.png < Storage path >: Export screenshots to local 

adb shell dumpsys activity |find “mResumedActivity”: View the foreground application package name , Must be started first app, Apply to Android 8.0 above 
adb shell cat /proc/meminfo: Get mobile phone memory information 
adb shell df: Get the information stored in the phone 
adb shell screenrecord < Storage path /xxx.mp4>: Recording screen , Name with .mp4 ending
adb shell screenrecord --time-limit 10 < Storage path /xxx.mp4>: The screen recording time is 10 second
Four ,ADB Combination of orders monkey Use
1, What is? monkey
Monkey yes Android SDK A command line tool provided , It is simple and convenient to send pseudo-random user event streams , Yes Android APP Do pressure ( stability ) test . Mainly for testing app Whether there is non response and crash .
2,adb combination monkey Common commands
adb shell monkey 100: Under this equipment , Random application , perform 100 Random operation of times .( Pseudorandom )
adb shell monkey -p < Package name > 100: Specify the application ( package ) Random operation 100 Time . The package shown here is named :com.dfcyc.app.dffs
adb shell monkey -p < Package name > -v -v -v 100 >D:\log.txt: Specify to apply random operations 100 And print the log to the specified path / file
-v: The log level , altogether 3 level
D:\log.txt: Specify a path to store logs , File name customization .
adb shell monkey -s <seed value > -p < Package name > -v -v -v 100 >D:\log.txt: according to seed value Specify to apply random operations 100 And print the log to the specified path / file
seed value : Output log After the log file , View in the file .
adb shell monkey -p < Package name > -v -v -v --throttle 1000 200 >D:\log.txt: Specify to apply random operations 200 Time , Every time 1000 Click once in milliseconds , And print the log to the specified path / file .
–throttle: Followed by milliseconds 
During command execution , Press Ctrl+C You can quit , But it does not represent. monkey stop it ( Including running monkey Unplug the data cable , Still not stopped ), If you need to stop monkey You can kill the process id, Following commands :
adb shell ps | findstr monkey: Check the current system before stopping ,monkey Running process id
adb shell kill < process pid>: Forcibly kill the running monkey process 
3,monkey Log analysis of
Use Monkey After the test , We are concerned about whether the application crashes or does not respond in the test . The test results can be judged by the following methods :
normal :
monkey The test was successfully completed , stay log Last , The number of times the current execution time and the time spent will be printed .Monkey finished On behalf of the executive
abnormal : Search for abnormal keywords in the log
a. No response -Anr problem : Search the log for “ANR”
b. : Search the log for “CRASH”
c. Other questions : Search the log for ”Exception”
For more log related information, please visit Baidu
Students with strength can write a gadget , Automatic log analysis .
Knowledge point :adb logcat 's logs and monkey The difference between command logs
adb monkey Logs are records monkey The command is on the mobile phone APP Operational events .
adb logcat The log is to record the operation of the mobile phone system app When there are any abnormal events .
PS: more / More systematic use , You can learn online by yourself according to your personal needs .
Finally, thank everyone who reads my article carefully , The following online link is also a very comprehensive one that I spent a few days sorting out , I hope it can also help you in need !

These materials , For those who want to change careers 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful ……
If you don't want to grow up alone , Unable to find the information of the system , The problem is not helped , If you insist on giving up after a few days , You can click the small card below to join our group , We can discuss and exchange , There will be various software testing materials and technical exchanges .
Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .
Self study recommendation B Stop video :
Zero basis transition software testing : Self taught software testing , Got the byte test post offer, Is the B The best video station !
Advanced automation testing : Huawei has landed , Salary increase 20K,2022 Most suitable for self-study python Automated test tutorial , Spend it yourself 16800 Bought , Free sharing 
边栏推荐
- PCL error: error c2589 "(": "::" illegal mark on the right)
- MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
- -2021 sorting and sharing of the latest required papers related to comparative learning
- 10道面试基础笔试题,你能对几题?
- DBSCAN点云聚类
- [arXiv] notes on uploading papers for the first time
- 给定一个以数字组成的数组,实现输出id为数字,并且从小到大排序的name
- Detailed explanation of cesium events (mouse events, camera events, keyboard events, scene trigger events)
- 性能测试知识应用于实战
- Customer exit variable in query
猜你喜欢
![[create birthday card application]](/img/56/e04a9a20e181ad7b68b0f2d1d118bc.png)
[create birthday card application]

How to add an operator in ONEFLOW

Cluster chat server: cluster and distributed theory

Cmake learning

大学数据库创建与查询实战——数据库表设计

Jmeter性能综合实战——签到及批量签到

experimental design

&9 nodemon自动重启工具

U++ events

Practice data Lake iceberg lesson 37 kakfa write the enfour, not enfour test of iceberg's icberg table
随机推荐
DBSCAN点云聚类
Golang invalid argument to INTN
Distributed transaction scheme: best effort notification scheme
Deep learning - NLP classic papers, courses, papers and other resources sorting and sharing
C - documents
Still have 1 requests outstanding when connection from slaveX/X.X.X.X:33202 is closed
[hiflow] Tencent cloud's new generation of automation assistant, which I used to complete the enterprise epidemic prompt (no code)
Is it safe to open a securities account online?
如何在 pyqt 中实现桌面歌词
U++学习笔记 TSubclassOf()
Openlayers instance advanced view positioning advanced view positioning
Cluster chat server: cluster and distributed theory
10道面试基础笔试题,你能对几题?
Preliminary discussion on POC compilation
Neo4j应用
性能测试知识应用于实战
experimental design
University database creation and query practice -- database table design
HANA SQL 的Union和Union All
产品生命周期,常见的项目职能,信息流 都是什么