capturing-screenshots-and-screenrecord

Capture Android screenshots and screen recordings via adb for test failures.

303|10|Updated May 15, 2026
One-click install
npx skills add https://github.com/skydoves/android-testing-skills --skill capturing-screenshots-and-screenrecord
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: capturing-screenshots-and-screenrecord
Source: https://github.com/skydoves/android-testing-skills/tree/main/adb/capture/capturing-screenshots-and-screenrecord
Command: npx skills add https://github.com/skydoves/android-testing-skills --skill capturing-screenshots-and-screenrecord

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It solves the problem of needing reliable visual evidence (screenshots and screen recordings) to debug and reproduce Android test failures, especially in CI, where artifacts must be captured correctly and correlated with logs.

Core Features & Use Cases

  • PNG screenshot capture (screencap): Captures PNGs via adb shell screencap -p, including the correct streamed form using adb exec-out to avoid binary corruption.
  • Screen recording (screenrecord): Records MP4 clips via adb shell screenrecord with practical flags such as --size, --bit-rate, --time-limit (bounded to 180s), --rotate, and --bugreport.
  • Capture-on-failure automation: Implements a JUnit4 TestWatcher rule to automatically grab a screencap and a logcat -d dump when a test fails for targeted triage.
  • Use Case: When a flaky instrumentation test fails in CI, use this skill to capture the exact final frame as a PNG and attach a matching logcat dump for fast root-cause analysis and golden image generation.

Quick Start

Ask an AI agent to help you capture a PNG screenshot and a logcat dump for a failing instrumentation test using adb exec-out screencap -p and a JUnit4 TestWatcher rule.

Frequently Asked Questions about capturing-screenshots-and-screenrecord

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I capture an Android screenshot with adb screencap without corrupting the PNG file?

To capture a binary-clean Android screenshot, use `adb exec-out screencap -p` instead of `adb shell` to stream the PNG data directly and avoid binary corruption. This method ensures the resulting image file is encoded correctly for CI artifacts and golden-image workflows.

How do I automatically capture screenshots and logcat dumps when an Android test fails?

You can automatically capture screenshots and logcat dumps on test failure by implementing a JUnit4 `TestWatcher` rule. This capture-on-failure pattern triggers `adb exec-out screencap -p` and `logcat -d` commands simultaneously when a test fails, providing targeted visual and textual evidence for triage.

What is the maximum recording time for adb screenrecord on Android?

The maximum recording time for `adb shell screenrecord` is 180 seconds. You can use the `--time-limit` flag to bound the recording duration, along with other practical flags like `--size`, `--bit-rate`, `--rotate`, and `--bugreport` for generating MP4 clips.

Why do my adb screencap PNG files appear broken when saved in a CI pipeline?

Broken PNG files typically occur because `adb shell screencap -p` introduces carriage returns that corrupt the binary stream. Using `adb exec-out screencap -p` prevents this issue by ensuring a binary-clean stream, which is required for reliable PNG encoding in CI environments.

Does adb screenrecord work with scoped storage on Android?

Yes, `adb screenrecord` works with scoped storage by using scoped-storage aware output paths for saving the MP4 files. It also requires reliable shutdown behavior to ensure the recording stops correctly and the file is properly finalized before retrieval.

Can I use adb to record a video of flaky instrumentation tests for debugging?

Yes, you can record video of flaky instrumentation tests using `adb shell screenrecord` with a 180s time limit. Pairing this MP4 recording with a logcat dump and a final PNG screenshot allows for fast root-cause analysis and golden image generation during CI failures.