Loading...
Loading...
Use this skill to capture visual artefacts from a device for test failures, golden image generation, QA repro, and demo videos. Covers `adb shell screencap -p` (PNG screenshot), `adb exec-out screencap -p > out.png` (binary-clean stream that avoids CRLF translation on Windows), `adb shell screenrecord` with `--size`, `--bit-rate`, `--time-limit`, `--rotate`, `--bugreport`, `--verbose` flags, the 3-minute hard cap, scoped-storage rules for `/sdcard/` on API 30+, and the JUnit4 TestWatcher capture-on-failure pattern that grabs a screencap plus `logcat -d` on failure. If the user mentions "screenshot device", "screencap PNG", "raw RGBA dump", "screenrecord 3 minute limit", "scrcpy / Vysor streaming", "exec-out vs shell", or "bugreport overlay timestamp", use this skill.
npx skill4agent add skydoves/android-testing-skills capturing-screenshots-and-screenrecordadbcaptureToImage()adb shell screencap /sdcard/out.png-padb exec-out screencap -pcaptureToImage()screenrecord../../control/injecting-input-and-state/SKILL.md../../transfer/extracting-test-artifacts/SKILL.mdadb get-statedevice../../devices/connecting-to-devices/SKILL.mdscreenrecordscreenrecordscreenrecord/sdcard/shell/sdcard/Android/data/<pkg>/screencap"Thecommand is a shell utility for taking a screenshot of a device display." — developer.android.com/tools/adb#screencapscreencap
screencap [-h] [-p] [-d <displayId>] [<path-on-device>]| Flag | Meaning |
|---|---|
| (no flag) | Writes raw RGBA framebuffer to file. Not a PNG. |
| Encode as PNG. Required when streaming to stdout for the host. |
| Capture a specific logical display (multi-display devices). |
| Help. |
# 1. Save to device, then pull (good when the test continues running).
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png ./screen.png
# 2. Stream PNG bytes back to host without an intermediate file.
adb exec-out screencap -p > screen.png
# 3. Multi-display capture: external display + main.
adb shell screencap -p -d 0 /sdcard/main.png
adb shell screencap -p -d 1 /sdcard/external.pngexec-outshelladb shell\n\r\nadb exec-outadb shell screencap -p > out.pngadb exec-out screencap -p > out.pngadb pullscreenrecord"Thecommand is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file." — developer.android.com/tools/adb#screenrecordscreenrecord
screenrecord [--size WIDTHxHEIGHT] [--bit-rate RATE] [--time-limit TIME]
[--rotate] [--bugreport] [--verbose] <path-on-device>| Flag | Verbatim meaning (developer.android.com/tools/adb#screenrecord) |
|---|---|
| "Display command syntax and options". |
| "Set the video size. The default value is the device's native display resolution (if supported), 1280x720 if not." |
| "Set the video bit rate for the video, in megabits per second. The default value is 20Mbps." |
| "Set the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes)." |
| "Rotate the output 90 degrees. This feature is experimental." |
| Embeds a textual frame info / timestamp overlay used by bug-report attachments. |
| "Display log information on the command-line screen." |
screenrecordscreenrecord| Path | When |
|---|---|
| Default. User-visible video. Scoped-storage rules apply on API 30+ but |
| Use when the test app must produce output before the SD card is mounted, or to avoid touching the public store. Always pullable by |
screenrecord--time-limitadb shell screenrecord --time-limit 180 /sdcard/run.mp4 &
REC=$!
# … run instrumentation; on failure, send SIGINT to the on-device process …
adb shell pkill -INT screenrecord
wait $REC
adb pull /sdcard/run.mp4 ./run.mp4--bugreport--bugreportadb logcat -v threadtime,year,UTC../../observability/extracting-logs-with-logcat/SKILL.mdTestRuleTestWatcherfailed()screencaplogcat -dclass CaptureOnFailureRule(private val outputDir: File) : TestWatcher() {
override fun failed(e: Throwable, description: Description) {
val testName = "${description.className}.${description.methodName}"
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val target = File(outputDir, testName).apply { mkdirs() }
// PNG screenshot
device.executeShellCommand("screencap -p /sdcard/fail.png")
device.executeShellCommand("logcat -d -v threadtime").let { log ->
File(target, "logcat.txt").writeText(log)
}
// The test process can pull /sdcard/fail.png via Context.getExternalFilesDir
// or push through TestStorageService — see ../../transfer/extracting-test-artifacts/SKILL.md.
}
}../../automation/scripting-adb-for-ci/SKILL.mdset +e
./gradlew connectedDebugAndroidTest
RC=$?
set -e
if [ "$RC" -ne 0 ]; then
mkdir -p artifacts
adb shell screencap -p /sdcard/fail.png
adb pull /sdcard/fail.png artifacts/fail.png
adb logcat -d -v threadtime > artifacts/logcat.txt
adb logcat -d -b crash -v threadtime > artifacts/crash.txt
fi
exit $RC../../transfer/extracting-test-artifacts/SKILL.mdscreencap-p# WRONG
adb shell screencap /sdcard/out.png
file /sdcard/out.png # → "data" (not a PNG)
# WRONG because: without -p, screencap writes a raw RGBA framebuffer (header + naked pixel
# bytes), not a PNG. Image viewers refuse to open it. The .png extension is misleading.# RIGHT
adb shell screencap -p /sdcard/out.png
adb pull /sdcard/out.png ./out.pngadb shell screencap -p > out.png# WRONG (on Windows / certain CI hosts)
adb shell screencap -p > out.png
# WRONG because: `adb shell` allocates a PTY and translates LF to CRLF on stdout. For
# binary streams (PNG bytes) this corrupts the file.# RIGHT (binary-clean stdout)
adb exec-out screencap -p > out.png# WRONG — assumes a single screenrecord can capture 10 minutes
adb shell screenrecord --time-limit 600 /sdcard/run.mp4
# WRONG because: --time-limit is capped at 180. The utility silently truncates to 180.# RIGHT — chain
for i in 1 2 3 4; do
adb shell screenrecord --time-limit 180 /sdcard/run-$i.mp4
done
adb pull /sdcard/run-1.mp4 ./
adb pull /sdcard/run-2.mp4 ./
adb pull /sdcard/run-3.mp4 ./
adb pull /sdcard/run-4.mp4 ./
# Concatenate with ffmpeg if needed:
# ffmpeg -f concat -i list.txt -c copy out.mp4adb shell screenrecord --bugreport --time-limit 60 \
--bit-rate 8000000 --size 720x1280 /sdcard/repro.mp4
# Each frame has a frame-info + timestamp overlay aligning with logcat -v threadtime,year,UTC.
adb pull /sdcard/repro.mp4 ./repro.mp4
adb logcat -d -v threadtime,year,UTC > repro-logcat.txt-pscreencapadb exec-out screencap -p > out.pngadb shell screencap -p > out.png\n → \r\nscreenrecord --time-limitscreenrecordadb shell pkill -INT screenrecordkill -9screenrecordscreenrecordscreenrecord --bugreportlogcat -v threadtime,year,UTCfile ./out.pngPNG image dataadb shell screencap -p /sdcard/out.png && adb pull /sdcard/out.pngadb exec-out screencap -p > out.png\r\nscreencaplogcat -dscreenrecord --time-limit <N>N > 180kill -9screenrecordpkill -INT screenrecordClass.methodscreencap-pscreenrecordexec-outshelltasks/research/A2-adb-shell-commands.mdscreencapscreenrecordtasks/research/A3-adb-observability-automation.mdexec-out../../architecture/understanding-adb-architecture/SKILL.mdadb shelladb exec-out../../devices/connecting-to-devices/SKILL.mdadb get-state../../devices/connecting-over-wifi/SKILL.mdadb pair../../apps/installing-and-managing-apps/SKILL.md../../tests/running-instrumented-tests-via-adb/SKILL.mdam instrument../../control/injecting-input-and-state/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.md../../transfer/extracting-test-artifacts/SKILL.mdadb pull../../automation/scripting-adb-for-ci/SKILL.md../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.mdTestWatcher../../../instrumentation/scenarios/launching-activities-with-activityscenario/SKILL.md../../../fundamentals/strategies/applying-testing-strategies/SKILL.md