What is ADB?
ADB (Android Debug Bridge) is a command-line tool that lets you communicate with an Android device from your computer. It is part of the Android SDK platform tools and is essential for mobile testers, developers, and anyone working with Android devices professionally.
ADB enables you to install apps, capture logs, take screenshots, control device settings, and run shell commands — all from your terminal. In my work at Amazon and Virtusa testing Android, Fire OS, and IoT devices, ADB was a daily tool.
brew install android-platform-tools. On Windows, download from the Android developer site. Then enable USB Debugging on your device (steps below).
Steps to Enable USB Debugging
Before using ADB, you must enable Developer Options and USB Debugging on your Android device:
- Connect your device to the computer via USB cable.
- On your device, open the Settings app.
- Search for Build Number (usually under About Phone).
- Tap Build Number 7 times — you'll see "You are now a developer!"
- Enter your PIN or password if prompted.
- Go back to Settings and search for USB Debugging.
- Toggle USB Debugging ON.
- A pop-up will ask "Allow USB Debugging?" — tap OK.
Basic ADB Commands
These are the foundational commands every mobile tester should know.
| Command | Description |
|---|---|
adb devices | Lists all Android devices currently connected to the computer via USB |
adb devices -l | Lists attached devices with detailed information |
adb shell | Opens an interactive shell on the device — gives you a command-line interface to interact with the Android OS |
adb start-server | Starts the ADB server |
adb kill-server | Stops the ADB server — useful when the device is not detected |
adb reboot | Restarts the connected Android device |
Device Info Commands
These commands retrieve key information about the device — useful at the start of any test session to confirm the build and environment.
# Get Android OS version
adb shell getprop ro.build.version.release
# Get SDK version
adb shell getprop ro.build.version.sdk
# Get device serial number
adb shell getprop ro.serialno
# Get all device properties (useful for full device fingerprint)
adb shell getprop
Network Commands
These commands help you test and manage network connectivity on the device — essential for IoT and connectivity testing.
| Command | Description |
|---|---|
ping 8.8.8.8 | Tests network stability and connectivity to Google's DNS server (8.8.8.8) |
ping google.com | Tests connectivity and DNS resolution to Google's web server |
wpa_cli | Command-line interface for connecting to and managing wireless networks |
adb shell svc wifi enable | Enables Wi-Fi on the device |
adb shell svc wifi disable | Disables Wi-Fi on the device |
adb shell svc bluetooth enable | Enables Bluetooth on the device |
adb shell svc bluetooth disable | Disables Bluetooth on the device |
adb shell settings get global mobile_data | Retrieves whether mobile data is enabled (1) or disabled (0) |
Wireless ADB via TCP/IP
You can connect to your device wirelessly over Wi-Fi without a USB cable — very useful when testing in environments where USB access is restricted.
Steps to connect via TCP/IP
- Make sure the device and computer are on the same Wi-Fi network.
- Connect the device to the computer via USB cable first.
- Verify connection:
adb devices - Set the device to listen on a TCP/IP port:
adb tcpip 2211(any 4-digit port number works) - Hit Enter — you'll see "restarting in TCP mode port: 2211"
- Remove the USB cable.
- Find the device's IP address (Settings → Wi-Fi → tap your network → IP Address).
- Connect wirelessly:
adb connect 192.168.1.X:2211 - Verify the wireless connection:
adb devices
# Full TCP/IP workflow
adb tcpip 2211
# Remove USB cable, then:
adb connect 192.168.1.100:2211
adb devices
# Output: 192.168.1.100:2211 device
Screen Commands
ADB lets you capture screenshots and screen recordings directly from the terminal — essential for documenting bugs and test evidence.
| Command | Description |
|---|---|
adb shell screencap /sdcard/screenshot.png | Captures a screenshot and saves it to the device's storage as a PNG file |
adb pull /sdcard/screenshot.png | Pulls the screenshot from the device to your computer |
adb shell screenrecord --verbose /sdcard/recording.mp4 | Records the device screen and saves it as an MP4 file on the device |
adb pull /sdcard/recording.mp4 | Pulls the screen recording from the device to your computer |
adb shell wm size | Retrieves the display resolution of the device screen |
adb shell wm density | Retrieves the screen density (DPI) of the device |
# Full screenshot workflow
adb shell screencap /sdcard/bug_screenshot.png
adb pull /sdcard/bug_screenshot.png ~/Desktop/bug_screenshot.png
# Full screen recording workflow
adb shell screenrecord --verbose /sdcard/test_recording.mp4
# Press Ctrl+C to stop recording, then:
adb pull /sdcard/test_recording.mp4 ~/Desktop/test_recording.mp4
Logcat Commands
Logcat is one of the most powerful tools for Android testing. It captures all system logs from the device in real time, letting you filter and trace bugs to their root cause.
| Command | Description |
|---|---|
adb logcat -v time -b all > logs.txt | Captures all logs with timestamps from all buffers and saves to a file |
adb logcat -v time -b all | grep -i build | Filters logs to show only lines containing "build" |
adb logcat -v time -b all | grep -i wifidiags | Filters logs to show only Wi-Fi diagnostic entries |
adb logcat -v time -b all | grep -i unified | Filters logs to show only lines containing "unified" |
adb logcat -v time -b color -d | Retrieves and displays recent logs with colour highlighting |
adb logcat -v time -b all -color -d | Retrieves all buffer logs with colour highlighting |
# Save full logs to a file for bug reporting
adb logcat -v time -b all > test_session_logs.txt
# Real-time Wi-Fi issue filtering
adb logcat -v time -b all | grep -i wifidiags
# Filter for build info in logs
adb logcat -v time -b all | grep -i build
grep with the right keyword cuts through thousands of log lines to find exactly what you need in seconds.
Package Management Commands
These commands let you inspect, list, and manage all apps installed on the device.
| Command | Description |
|---|---|
adb shell pm list packages | Lists all installed packages on the device |
adb shell pm list packages -d | Lists only disabled packages |
adb shell pm list packages -3 | Lists only third-party (user-installed) packages |
adb shell pm list packages -f | Lists all packages along with their APK file paths on the device |
adb shell pm list permissions | Lists all permissions declared by installed packages |
# Find a specific app's package name
adb shell pm list packages | grep -i netflix
# List all third-party apps
adb shell pm list packages -3
# Get full path of an APK
adb shell pm list packages -f | grep -i myapp
Settings Commands
ADB can read and write Android system settings directly — useful for automating device configuration in test setups.
| Command | Description |
|---|---|
adb shell settings list system | Lists all system settings on the device |
adb shell settings get system volume_system | Gets the current system volume value |
adb shell settings list global | Lists all global (device-wide) settings |
adb shell settings list secure android_id | Gets the Android ID — a unique identifier assigned to each device |
adb shell settings list secure bluetooth_address | Gets the Bluetooth MAC address of the device |
Battery Commands
These dumpsys battery commands are extremely useful for testing low-battery scenarios, charging behaviour, and power-sensitive features without draining the physical battery.
| Command | Description |
|---|---|
adb shell dumpsys battery set level 10 | Simulates a battery level of 10% — useful for testing low battery warnings |
adb shell dumpsys battery set level 100 | Simulates a full battery level |
adb shell dumpsys battery reset | Resets battery info back to the actual device state |
adb shell dumpsys battery set usb 0 | Simulates USB disconnected — device will not charge |
adb shell dumpsys battery set usb 1 | Simulates USB connected — device will charge |
# Test low battery behaviour
adb shell dumpsys battery set level 5
# Test charging connected / disconnected states
adb shell dumpsys battery set usb 1 # charging
adb shell dumpsys battery set usb 0 # not charging
# Always reset after testing
adb shell dumpsys battery reset
adb shell dumpsys battery reset at the end of your test to restore real battery readings.
File Operations via ADB Shell
You can create, read, and manage files on the device directly through ADB Shell — useful for preparing test data or verifying file system behaviour.
Steps to create a file on the device
# Enter ADB shell
adb shell
# Navigate to the SD card
cd /sdcard
# Confirm current directory
pwd
# Create a new empty file
touch TestFile.txt
# Write content to the file
echo "Hello, ADB Shell!" > TestFile.txt
# Read the file contents
cat TestFile.txt
# Exit the shell
exit
Pulling files from device to computer
# Pull any file from device to your Desktop
adb pull /sdcard/TestFile.txt ~/Desktop/TestFile.txt
# Pull a folder
adb pull /sdcard/DCIM ~/Desktop/DevicePhotos
ADB for Test Automation Integration
ADB is not just a manual debugging tool — it is a first-class component in automated test pipelines. Combining ADB commands with Python's subprocess.run() lets you control the device, capture evidence, and manage application state directly inside your test scripts without needing a third-party library.
Running ADB Commands from Python Test Scripts
The standard way to invoke ADB from Python is subprocess.run() with capture_output=True. This gives you the command's stdout and stderr as byte strings that you can decode and assert on:
import subprocess
def adb(cmd: list[str]) -> str:
result = subprocess.run(
["adb"] + cmd,
capture_output=True,
text=True,
timeout=30
)
if result.returncode != 0:
raise RuntimeError(f"ADB command failed: {result.stderr.strip()}")
return result.stdout.strip()
Taking a Screenshot and Pulling It to Host During a Pytest Test
Capturing a screenshot on test failure provides visual evidence for bug reports and is especially useful when tests run unattended in CI. The following pattern hooks into pytest's fixture system to pull a screenshot to the host whenever a test fails:
import subprocess
import pytest
@pytest.fixture(autouse=True)
def capture_screenshot_on_fail(request):
yield # test runs here
if request.node.rep_call.failed:
test_name = request.node.name
device_path = f"/sdcard/fail_{test_name}.png"
host_path = f"screenshots/fail_{test_name}.png"
subprocess.run(["adb", "shell", "screencap", device_path])
subprocess.run(["adb", "pull", device_path, host_path])
print(f"[SCREENSHOT] Saved to {host_path}")
Clearing App Data Before Each Test
Starting every test from a clean application state is essential for test independence. Rather than manually navigating to Settings to clear data, use pm clear in your pytest setup fixture:
PACKAGE = "com.example.myapp"
@pytest.fixture(autouse=True)
def reset_app():
subprocess.run(["adb", "shell", "pm", "clear", PACKAGE], check=True)
yield
pm clear wipes all app data, cache, and shared preferences — equivalent to a fresh install without uninstalling and reinstalling the APK. This is significantly faster and ensures every test starts from an identical baseline.
Checking Whether an App Is Running
Before interacting with an app in a test, confirm it is actually running. adb shell pidof returns the process ID if the app is active, or an empty string if it is not:
def is_app_running(package: str) -> bool:
result = subprocess.run(
["adb", "shell", "pidof", package],
capture_output=True, text=True
)
return result.stdout.strip() != ""
Setting Up ADB in GitHub Actions CI
Running ADB-based tests in a GitHub Actions pipeline requires installing the Android SDK platform-tools, starting an emulator, and waiting for it to fully boot before the first test executes:
- name: Install Android SDK platform-tools
run: sudo apt-get install -y android-sdk
- name: Start Android emulator
run: |
$ANDROID_HOME/emulator/emulator -avd test_avd -no-window -no-audio &
- name: Wait for emulator boot
run: adb wait-for-device shell 'while [ "$(getprop sys.boot_completed)" != "1" ]; do sleep 2; done'
- name: Run tests
run: pytest tests/ -v
adb wait-for-device blocks until ADB can see the emulator, but it does not mean the Android OS has finished booting. The getprop sys.boot_completed poll is the correct signal that the emulator is truly ready to receive app interactions.
Capturing Logcat During Tests
Starting logcat in the background during your test run and killing it after gives you a complete device log for any test that fails. Parse the output for specific tags or error keywords:
import subprocess, signal
logcat_proc = subprocess.Popen(
["adb", "logcat", "-v", "time", "-b", "all"],
stdout=open("test_logcat.txt", "w"),
stderr=subprocess.DEVNULL
)
# ... run tests ...
logcat_proc.send_signal(signal.SIGINT) # stop logcat after tests finish
# Parse for crashes
with open("test_logcat.txt") as f:
if "FATAL EXCEPTION" in f.read():
print("[WARNING] Crash detected in logcat")
Common ADB Automation Pitfalls
- Device not found when multiple emulators are running. If more than one emulator or device is connected, ADB commands fail with "error: more than one device." Always specify the target with
-s <serial>:adb -s emulator-5554 shell .... Retrieve the serial fromadb devicesat setup time and store it as a fixture variable. - Emulator not ready. Launching an emulator and immediately running tests causes intermittent failures because the emulator is still in the boot animation. Always poll
adb shell getprop sys.boot_completedand wait for it to return "1" before starting any test interaction. - Path differences between device manufacturers. The path
/sdcard/is standard on most devices, but some manufacturers and Android versions map it differently. Useadb shell echo $EXTERNAL_STORAGEto get the correct external storage path for the specific device under test rather than hardcoding/sdcard/.
Back to Blog