Powerful ADB commands for Android Tester

If you are working as mobile tester in an Android development team you are probably familiar with adb commands (Android Debug Bridge). The tool offers plenty of useful commands that help you to pull logs from the Android device or emulator. Besides pulling log files from the test device there are plenty of other useful commands that every mobile tester in an Android environment must know. Before using adb make sure the Android SDK is installed, a device is connected to your computer or an Android emulator has been started. Note: In order to use the adb commands on your test devices make sure that on every device the developer options and USB debugging are enabled.

Both options are hidden by default. On Android 4.2 and higher you can enable them by tapping seven times the build number in the Settings > About phone section. Once the developer options are enabled open them and enable USB debugging.

ADB commands

Start/ Stop ADB server

If a device is connected start the adb server to be able to interact with the device.

adb start-server

adb kill-server

List connected devices

adb devices
Will list all connected devices.

Reading log files

adb logcat
Print the current device log to the console.

adb logcat -d > [path_to_file]
Save the logcat output to a file on the local system.

adb logcat -c
The parameter -c will clear the current logs on the device.

adb logcat packagename:[priority level: V, D, I, W, E, F, S]
Filter log files by priority e.g. adb logcat com.myapp:E which prints all error logs of the given app.

adb bugreport > [path_to_file]
Will dump the whole device information like dumpstate, dumpsys and logcat output.

Pull files from device

adb pull [device file location] [local file location]
Will pull the given file from the device to the local computer system.

Write files to device

adb push [local file location] [device file location]
Will push a file to the connected device.

Create a screenshot

adb shell screencap -p /sdcard/screenshot.png
Will create a screenshot of the current screen on the given file location.

Create screen recordings

adb shell screenrecord /sdcard/NotAbleToLogin.mp4
Will start a recording of the current screen. With crtl+c the current recording can be stopped.

Un-/ Install apps

adb install com.myAppPackage
Install the app with the given package name on the connected device.

adb -s [device serial] install com.myAppPackage
Install the app to a specific device. Useful if more than one device is connected to your computer.

adb -r install com.myAppPackage
Very important command! The parameter -r means re-install the app and keep its data on the device. Executing this command is simulating the app update process from an older to the latest version of your app. Make sure the current live version is installed on the test device and then install the release candidate with the option -r. Check for problems after simulating the update process.

adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X install -r com.myAppPackage
Install the given app on all connected devices.

adb uninstall com.myAppPackage
Remove the given app from the device.

adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X uninstall com.myAppPackage
Uninstall the given app from all connected devices

Monkey

adb shell monkey -p com.myAppPackage -v 10000 -s 100
With the help of this command the monkey tool is generating 10.000 random events on the real device. Note: Use the parameter -s (seed) to execute the same commands over and over again in order to reproduce any crashes that happen during the monkey run.

More useful adb shell commands can be found here.

If you have any other adb commands that you are using during your coding or testing time at work add them to the comments.

#HappyTesting