In this article, QA Team Leader at ISSTA, Nir Tal, reviews useful ADB commands for tests of Android mobile devices. Android Debug Bridge is a multi-purpose command-line interface that allows you to communicate with your mobile device by running a variety of commands.
- First, when installing Chocolatey, log into PowerShell.
- Fast installation for Windows users using Chocolatey, apart from installing ADB, also makes it an environment variable, as well as saves valuable time manually configuring this variable, which can also lead to errors.
- Verify that the tool has been installed successfully by writing “adb” in the command line, and verifying that all the options of the tool appear.
- Connect the device with a USB cable into the computer and activate “Developer mode” on the device.
- Mark the option “Enabling USB Debugging”.
- Alow USB Debugging to be performed in the security panel.
- Make sure that the device is successfully connected by typing “adb devices”
To save following example scripts in files with an extension of “bat”, for example, “test.bat”, so that you do not have to write the commands repeatedly in the command line, but run the commands by executing this script file to achieve your testing goals.
Screenshots are mandatory for bug reports related to user experience.
The following script makes screenshots of your mobile phone with the timestamp of the current date and saves them to your desktop (or where you choose by changing the first command).
set SAVESTAMP=%SAVESTAMP: =%
adb shell screencap -p /sdcard/%SAVESTAMP%.png
adb pull /sdcard/%SAVESTAMP%.png
adb shell rm /sdcard/%SAVESTAMP%.png
Saving logs via logcat
Logcat is a CLI tool that receives crash reports of applications and prints to the log that the application printed with the log class. Logs are very useful for development teams. When we find a bug that causes the application to crash, to reproduce and understand this issue.
Attached is the script – as in the previous script the logs are saved on the desktop with the timestamp of the current date.
set SAVESTAMP=%SAVESTAMP: =%
adb logcat -v threadtime > %SAVESTAMP%.txt
Video helps greatly understand the flow that the user has performed and can help the developer to easily reproduce the error by viewing the steps performed in the recording beside from the textual description of the issue, screenshot or the log that we attach to it.
The following script is divided into 2. First, run the following command to start the recording:
adb shell screenrecord/sdcard /test.mp4
Then finish the recording with Ctrl + C. To pull the recording from the machine we run the following script:
adb pull /sdcard/test.mp4
adb shell rm /sdcard/test.mp4
Running ADB commands using WI-FI
To disconnect a physical connection between your device and your computer, run adb commands to your device using a Wi-Fi connection. Use an app from Google Play called “ADB wireless” and following the instructions.
In this article ABD was reviewed:
- ADB commands are useful for mobile testing: screenshot, logcat logging, video capture, and ADB using Wi-Fi.