For mobile Android testing, the ADB command is a very important point, you must memorize the usual ADB commands in the heart, will be a great convenience for Android testing, many of the commands will be used in automated test scripts.
Android Debug Bridge
ADB is actually the abbreviation for Android Debug Bridge, Android Debug Bridges, Adb.exe in the installation of Anroid SDK Development Package Platform-tools directory, it is a C/S architecture command line consisting mainly of 3 parts:
1. Client running on PC: it can install, uninstall and debug Android application.
Tools such as ADT in Eclipse, DDMS in the SDK Tools directory, and Monitor are all equally used by ADB to interact with Android devices.
PC-side phone helper, such as 360 mobile phone helper, pea pod, app Bao, etc., in addition to the installation of third-party applications convenient, other functions, basically can be done through the ADB command, it is recommended to 测试人员
try not to install such mobile phone assistant on the computer, because its own ADB program may be with The ADB program under the Android SDK conflicts and the 5037
port is occupied, resulting in the inability to connect to the device when using the ADB command
2, running on the PC-side service: Its management client to the Android device on the ADB background process connection
After the ADB service starts, Windows can find the Adb.exe process in Task Manager
3. The ADB background process running on Android devices (adb daemon, daemon, a daemon that runs in the form of a background process on a simulator or physical mobile device (daemon))
Execute adb shell ps | grep adbd
, you can find the background process, Windows use findstr
alternative grep
[xuxu:~]$ adb Shell PS | grep adbdroot 23227 1 6672 832 ffffffff 00019bb4 s/sbin/adbd
Here is a place to note that the ADB uses the port number, 5037
it is necessary to remember
When a user launches an ADB client, the client first confirms that an ADB service process is already running. If not, the service process is started. When the server is running, the ADB server binds to the local TCP port 5037 and listens for commands from the ADB client, and all ADB clients use port 5037 to talk to the ADB server. The server then establishes a connection to all running emulators or device instances. It locates all simulators or devices by scanning all odd ports within the range of 5555 to 5585. Once the server has found the ADB daemon, it will establish a connection to that port. Note that any emulator or device instance will get two connected ports, an even-numbered port to control the connection to the console, and a technical port to control the connection to the ADB.
ADB command
In the process of development or testing, we can manage multiple devices through the ADB in the general format of:
adb [-e |-D |-s < device serial number;] < sub-command >
With the environment variables in place, enter ADB help in the command window or enter ADB directly, and the description and subcommands for all options will be listed.
Here are some of the commands inside the cicadas:
1, ADB devices, get equipment list and equipment status
[xuxu:~]$ adb deviceslist of devices attached 44c826a0 device
2, ADB get-state, get the status of the device
[xuxu:~]$ adb get-State device
There are 3 types of devices, Device,offline,unknown
Device: normal connection of devices
Offline: Indicates that the device or emulator is not connected to the ADB server or is not responding, the connection is abnormal, the device is unresponsive
Unknown: No device connected
3, adb install, installation application
Only one mobile device or one simulator device: adb install path
Specify device or Emulator installation: adb-s physical phone device serial number/Phone simulator device serial number install package path
Overwrite installation: Adb-s device serial number INSTALL-R installation package path
If you need to install the APK with Chinese name in Windows, you need to change the ADB, Baidu can find the ADB to make changes, support the Chinese command apk, please search by yourself
4, adb Uninstall, uninstall the application
ADB Uninstall Package Name
Specify device or emulator device uninstall: adb-s mobile device serial number/Phone simulator device serial number uninstall installed app Registration
Preserve configuration and cache file offload: Adb-s device serial number shell PM uninstall-k installed app package name
5, ADB pul, copy files or folders on Android device to local
For example, copy the Pull.txt file under SDcard to the D drive:
ADB pull Sdcard/pull.txt d:/
Specify device or emulator: Adb-s device serial number pull the path on the file path on your phone on your computer
If you need to rename to Rename.txt:
DB Pull Sdcard/pull.txt D:/rename.txt
Note the permissions, copy the system permissions in the directory of the file, requires root, and the general Android root can not use the command to copy, and need to use a similar to the RE-file browser on the phone, the system's file system is mounted to read and write, before the mobile system files on the phone copy , it is recommended to use the development version of Xiaomi Mobile phone, Iuni is also good drop ~ ~
6, ADB push, push local files or folders to Android device
For example, push the push.txt to SDcard under the D drive:
ADB push d:/push.txt/sdcard/
Push the "pass" folder under the D drive to SDcard:
Adb-s device number push d:/pass /sdcard/pass/
7. ADB shell command
Android system is based on Linux system development, support common LINXU commands, these commands are stored in the phone's "/system/bin/" folder, under which you can see some of our usual in the application of Linux systems, often operating instructions, such as "LS, cat, DF, Uptime, PS, kill "and so on. We can execute these instructions by using the ADB shell command directly with the relevant designations and their parameters.
For example, to view all the contents of the phone's current directory, you can enter the ADB Shell ls command to view
You can enter "exit" to exit the "adb shell" prompt. Back to the Windows command line console
Sometimes, we may be concerned about which apps are installed on the phone, and you can use the ADB shell command to access the/data/data directory of your phone system for viewing. Reminder that the root user needs to be switched during the operation
Here's how:
/data/datals
If there is no root, there is an access issue
8, adb shell Dumpsys Battery, see the battery charge information
The meaning of each parameter:
AC Powered:false Indicates whether to connect the power supply, false is not to use the power supply
USB Powered:true Indicates whether use power is used and true is USB powered
Status:2 indicates battery charge state, here 2 indicates battery charge
Health:2 indicates the health of the battery, 2 indicates that the battery is in good condition
Present:true indicates if there is a battery on the phone, true indicates that there is a battery
Level:66 represents the current remaining power information, 66 indicates the remaining charge is 66%
SCALE:100 indicates the maximum amount of battery power
VOLTAGE:4035 represents the current battery voltage, the voltage on the simulator is 0, here our cell phone battery voltage is 4035 MV
TEMPERATURE:310 represents the current battery temperature, it is an integer value, 310 means 31 degrees
Technology:li-ion represents the technology of battery use, Z reasonable li-ion means lithium battery
9, adb shell Dumpsys WiFi, view wireless network information
After running the command, the output is much more informative, so this adds "| More "parameter, so that when the output information on a full page to pause the output, if you need to see the subsequent output, you can press space to continue to display the next page content, or press Q to stop the display of subsequent output content
The meaning of the relevant output information:
Wi-Fi is enabled: Indicates the connection status information for WiFi, and Android contains 5 WiFi connection status
Wifi_state_disabled WiFi is off
Wifi_state_disbling WiFi is shutting down
Wifi_state_enabled WiFi is enabled
Wifi_state_enabling wif is starting up.
Wifi_state_unknown Unknown WiFi status
Internal state: In this section lists some information about WiFi device name, WiFi name, status, IP address, MAC address, network encryption method, etc.
If you need to see the following output information, the stand-alone spacebar can be viewed
10. ADB shell Dumpsys power to see information about your power management
In the mobile test automation test or after death, it is sometimes necessary to determine whether the phone is in the lock screen, and according to some of the phone's settings to determine its operation, such as the phone is set to 5 minutes to close the screen without action, we are in the automated scripting design, After a long pause, it is necessary to determine whether it exceeds the lock screen time, so as to take the following different operations, if not more than the change in time to enter the operation, and more than this time to activate the screen, lock lock the screen also need to unlock, and then respond to the input operation, here the " mscreenofftimeoutsetting=60000 ", whose value" 60000 "represents 1 minutes
" mscreenofftimeoutsetting " can only output the screen I saddle time setting information
11, adb shell Dumpsys telephony.registry, see phone-related information
Mcallstate=0 indicates the call status, 0 indicates standby, 1 indicates that the call has not been answered; 2 means the line is busy
Mcallincomingnumber= represents the phone number of the most recent call
Mservicestate indicates the status of the service, 0 indicates normal usage status
MSIGNALSTRENGT indicates signal strength
Mmessagewaiting Indicates whether the radio message is waiting
Mcallforwarding Indicates whether call forwarding is enabled
Mdataactivity represents the wireless data call situation, 0 means no call, 1 indicates that the IP PPP signal is being received, 2 indicates that the IP PPP signal is being sent, and 3 indicates that the IP PPP signal is being sent and received
Mdataconnectionstate represents a wireless data connection condition, 0 means no data connection, 1 means that a data connection is being created, 2 is connected, 3 is suspended, the connection is already established, but IP data traffic is temporarily unavailable
Mdataconnectionpossible Indicates whether there is a data connection
Mdataconnectionreason indicates the reason for the data connection
MDATACONNECTIONAPN means APN, which is the access point name
Mdataconnectionlinkproperties represents the link properties of a data connection
Mdataconnectionlinkcapabilities the ability to represent data link connections
Mcelllocation indicates base station related information
Registrations indicates the registration record count
12, adb shell CAT/PROC/CPUINFO,CPU hardware related information
The "/proc" Partition of the Android system stores various real-time information such as CPU, memory, etc.
13, adb shell Cat/proc/meminfo, see the memory of the relevant information
14. ADB Shell Cat/proc/iomem, view information about the I/O memory partition
ADB command (i)