当前位置:网站首页>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 
边栏推荐
- 大淘营批量采集商品,如何将未上传的宝贝保存下来等后面再导入采集上传
- Day109. Shangyitong: integrate Nacos, hospital list, drop-down list query, hospital online function, hospital details query
- U++学习笔记 TSubclassOf()
- Interval DP chain stone merging
- CMake的学习
- Openlayers instance advanced view positioning advanced view positioning
- TreeMap
- Preliminary discussion on POC compilation
- PCL出错:error C2589“(“:“::“右边的非法标记)
- Customer exit variable in query
猜你喜欢

初探POC编写

Practice data Lake iceberg lesson 37 kakfa write the enfour, not enfour test of iceberg's icberg table

NLP field history most complete must read classic papers classification, sorting and sharing (with Chinese analysis)

存储结构和管理盘。有点像装win98要先分区格式化硬盘

CMake的学习

Kuberntes cloud native combat VI uses rook to build CEPH cluster

Summary of database stress testing methods

Cluster chat server: Design of database table

性能测试知识应用于实战

query中的customer exit客户出口变量
随机推荐
JS - event proxy and application scenarios
Interval DP chain stone merging
Programmer growth Article 26: how to hold a good daily morning meeting?
TreeMap
Sixty final review questions of software architecture
Basic principle of synchronized lock
[complex overloaded operator]
Postgraduate entrance examination | advanced mathematics Chapter4 indefinite integral
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
SQL injection attack
lambda學習(sort後面的Comparator的使用,collection後使用Collectors.groupingBy分組)
JS——事件代理和应用场景
Cesium keyboard and mouse control camera roaming (source code + principle explanation)
淘宝助理停用,用大淘营导入数据包上传宝贝提示“主图为必填项,不能为空”是什么原因?如何解决?
ESP32 的 I2C 原理 & 应用入门
Openlayers instance animated GIF GIF animation
Record the process of the first excavation and intersection
[hiflow] Tencent cloud's new generation of automation assistant, which I used to complete the enterprise epidemic prompt (no code)
Serveur de chat de Cluster: conception de la table de base de données
A stack of digital robots were selected in Gartner's China AI market guide