Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To save a screenshot when an Android UI test fails, connect a screenshot call to that test framework’s failure-handling hook, then attach or report the image as a test artifact. Android’s modern UI Automator documentation shows how to capture a window or element and report the file to instrumentation results; Firebase Test Lab documents a separate AndroidX screenshot-processor flow. Neither API call automatically means “capture only on failure”: the test runner, rule, extension, or service must invoke it when a failure occurs.

Choose the method that matches where your test runs

First identify the execution environment. Android instrumented UI tests live in src/androidTest/java and run on a device or emulator. Robolectric tests run on the JVM, so device-oriented capture APIs should not be assumed to work there.

For modern device UI tests, use UI Automator when you need a screenshot of the active window, screen, or a particular UI element, and report the saved file through instrumentation results. For instrumentation tests already running in Firebase Test Lab, its documented screenshot processor provides a route to make captured images available in the Test Lab result view. Golden-image tests serve a different purpose: they compare a render with an approved reference to detect visual changes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach Good fit Important consideration
UI Automator capture and ResultsReporter Device UI tests that need a window, screen, or element image The modern 2.4 API is labeled under development in the guide; verify the dependency and integration against your project.
AndroidX Screenshot with Firebase processor Instrumentation tests run in Firebase Test Lab Register the processor and retrieve images from the completed Test Lab result.
Golden-image screenshot test Checking rendered UI against approved reference images Visual differences can come from legitimate UI changes or environment drift; this is not a general failure-state capture hook.
Host-side visual test Local screenshot-oriented rendering workflows Android distinguishes Layoutlib-based static rendering from Robolectric Native Graphics workflows; choose based on rendering scope.

Capture a UI Automator screenshot and report it

The current Android UI Automator guide demonstrates capturing the active window or a selected element, saving the resulting bitmap, and adding the file to instrumentation results with ResultsReporter. The documented sample dependency is androidx.test.uiautomator:uiautomator:2.4.0-alpha05; the guide labels this API as under development, and that coordinate is a versioned example, not a guarantee it is the latest release. Check your dependency catalog and official release information before copying it into a project.

#1 Best Overall
Samsung Galaxy A16 4G LTE (128GB + 4GB) International Model SM-A165F/DS Factory Unlocked, 6.7", Dual SIM, 50MP Triple Camera (Case Bundle), Black
  • Please note, this device does not support E-SIM; This 4G model is compatible with all GSM networks worldwide outside of the U.S. In the US, ONLY compatible with T-Mobile and their MVNO's (Metro and Standup). It will NOT work with other CDMA carriers, and it is also not compatible with their MVNO (Visible, Xfinity Mobile, US Mobile, Cricket Wireless, etc).
  • Compatibility with certain third-party devices and accessibility accessories, including some hearing aids, may vary depending on manufacturer support, Bluetooth protocols, software compatibility, and regional firmware limitations. For additional hearing aid compatibility information, please refer to Samsung’s official support documentation.
  • Camera: 50 MP, f/1.8, (wide), 1/2.76", 0.64µm, AF | 50 MP, f/1.8, (wide), 1/2.76", 0.64µm, AF | 2 MP, f/2.4, (macro). Battery: 5000 mAh, non-removable | A power adapter is NOT included.

The following illustrates the documented capture-and-report sequence in a Kotlin instrumentation test. Replace the selectors and destination with ones that fit your test. The failure-only part belongs in your runner or test framework’s failure hook, as described below.

import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.uiAutomator
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.services.storage.TestStorage
import androidx.test.services.storage.TestStorageConstants
import androidx.test.services.storage.TestStorageConstants.TestOutputFile
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.PNG
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.JPEG
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.WEBP
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.PDF
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.UNKNOWN
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.BMP
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.GIF
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.TIFF
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.HEIC
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.AVIF
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.SVG
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.XML
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.JSON
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.TEXT
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.HTML
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.CSV
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.ZIP
import androidx.test.services.storage.TestStorageConstants.TestOutputFileType.UNKNOWN

Those import names are not a runnable example: the supplied official documentation supports the API sequence, but does not provide enough exact Kotlin signatures here to safely reproduce a complete, compile-ready snippet. Use the guide’s own sample for the matching dependency version rather than relying on guessed imports or method overloads.

At a high level, the supported sequence is:

  1. Obtain the active UI Automator context for the test.
  2. Call activeWindow().takeScreenshot() to capture the active window, or onElement { ... }.takeScreenshot() to capture an element.
  3. Save the returned bitmap with the documented saveToFile operation.
  4. Use ResultsReporter and reportToInstrumentation() to associate the file with the instrumentation result so it can be inspected in Android Studio.

For a test that fails due to a particular view state, an element capture can be smaller and more focused than the whole window. A whole-window capture is more useful when overlays, system UI, or surrounding layout may explain the failure. Confirm what your runner retains and exposes; saving a file alone does not ensure it appears beside the test result.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

Make capture conditional on failure

A screenshot method captures when called; it does not independently know whether an assertion or test has failed. Put the capture-and-report sequence in the failure callback supported by your specific test stack, such as that runner’s rule, extension, listener, or service integration. The cited Android UI Automator and Firebase documentation describe capture/reporting, but do not define one universal failure callback that works for every framework.

  1. Identify the test framework and the callback that runs after a test failure.
  2. In that callback, obtain the still-available device or activity context and run the supported capture operation.
  3. Write the image to a location the runner can collect, then attach or report it using that runner’s artifact mechanism.
  4. Run one deliberately failing test and confirm the callback executes and the image is visible in the expected result viewer.

Failure hooks can vary in what they can access and when they run. Verify behavior for the failure types that matter in your suite, including assertion failures and errors during setup or teardown; do not assume a hook that handles one case handles all of them. If the process or device has already terminated, the last UI state may no longer be available.

Use Firebase Test Lab’s screenshot processor

For instrumentation tests executed in Firebase Test Lab, the documented route registers com.google.firebase.testlab.screenshot.FirebaseScreenCaptureProcessor as the instrumentation screen-capture processor, then calls Screenshot.capture().process() in the test. The guide describes processor registration through manifest metadata or a runner argument. It also offers Screenshot.capture(activity) when an activity-specific capture is appropriate.

Rank #3
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.
  1. Configure the Firebase processor using the manifest metadata or runner argument shown in the Firebase guide.
  2. Call Screenshot.capture().process() at the point your test or failure integration should capture, or use the documented activity overload where suitable.
  3. Run the instrumentation test in Test Lab.
  4. Open the completed test’s Results tab, then its Screenshots tab, to view processed images.

If no processor is registered, the guide says a BasicScreenCaptureProcessor is used. On Android 10 (API 29) or higher, the guide says the legacy WRITE_EXTERNAL_STORAGE permission is not needed for its documented screenshot read/write case. Treat that statement in its stated Android and documented-flow context rather than as a universal rule for every storage operation in an app.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep diagnostic screenshots separate from visual regression tests

A failure screenshot answers “what was on screen when this test failed?” A golden-image test answers “does this render match an approved reference?” The second workflow needs reference-image management, a stable rendering environment, a decision about pixel tolerance, and a reviewer process for approving expected changes. A visual mismatch can indicate a real regression, an intentional design update, or platform, library, or operating-system rendering differences.

Host-side screenshot testing also has distinct rendering choices: Android describes Layoutlib-based static rendering and Robolectric Native Graphics workflows. These approaches can be useful for local visual checks, but they should not be presented as automatically capturing the final device UI after an arbitrary functional-test failure.

Rank #4
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and how to diagnose them

  • No image appears for a failing test: the capture call may not be connected to a failure hook, or the hook may not cover that failure phase. Confirm the callback runs and test with a controlled failure.
  • The image is saved but absent from Android Studio results: a file on disk is not necessarily an instrumentation artifact. Follow the documented ResultsReporter reporting step and inspect the result attachment.
  • Firebase results contain no screenshot: verify that FirebaseScreenCaptureProcessor is registered using the manifest metadata or runner argument and that the test calls Screenshot.capture().process(). Then inspect the completed run’s Results > Screenshots view.
  • UI Automator API or dependency does not match the example: the cited guide labels the 2.4 API under development and shows alpha05 as its sample coordinate. Confirm the version and signatures against current project dependencies and the matching official guide.
  • Screenshot call fails after teardown or process loss: the test may no longer have a live activity, device state, or usable context. Capture in the earliest supported failure callback while the UI state is still accessible.
  • A golden test reports a small visual difference: compare the render environment and intended UI changes before treating it as a functional failure. Reference approval and tolerance belong to the golden-test workflow.

Performance, reliability, and artifact handling

Capturing and reporting an image adds work to a test run, and a full-window image may contain more data than a targeted element image. Capture only when useful to diagnosis, choose the smallest scope that preserves context, and use the artifact mechanism supported by the runner so the file’s lifetime and accessibility are clear. A failed load or a crashed test may prevent capture altogether; screenshot evidence complements logs and assertions rather than replacing them.

For Test Lab, the image is retrieved through the completed test result rather than inferred from a local path. For Android Studio instrumentation results, use the reporting integration described for that path. In either case, verify artifact visibility in CI or the result interface actually used by the team; a local file write is not proof of successful collection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

Android app UI tests run on a device or emulator; ScreenshotNeo is a website screenshot API and MCP server, not a replacement for Android instrumentation capture. It can help when the failure also concerns a web page or web UI rendered in a browser. A single request returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.

Best Value
Samsung Galaxy A16 5G 128GB Cell Phone, Unlocked Android Smartphone, Large AMOLED Display, Durable Design, Super Fast Charging, Expandable Storage, US Version, 2025, Blue Black (Renewed)
  • Charger NOT Included, 6.7" Super AMOLED FHD+, 90Hz Refresh Rate, 385 ppi, 800 nits (HBM), 1080x2340px, 5000mAh Battery
  • 128GB, 4GB RAM, microSDXC, Exynos 1330 (5nm), Octa-Core, Mali-G68 MP2 or Mali-G57 MC2 GPU
  • Rear Camera: 50MP, f/1.8 (wide) + 5MP, f/2.2 (ultrawide) + 2MP, f/2.4 (macro), LED flash, panorama, HDR; Front Camera: 13MP, f/2.0, Android 14, up to 6 major Android upgrades, One UI 6.1
  • 3G: HSDPA 850/900/1700(AWS)/1900/2100; 4G LTE: 1/2/3/4/5/7/12/13/14/20/25/26/28/29/30/38/39/40/41/48/66/71, 5G: 2/5/25/41/66/71/77/78 SA/NSA/Sub6/mmWave - Nano-SIM + eSIM
  • US Model – Global Connectivity – Compatible with Most GSM Carriers like T-Mobile, AT&T, MetroPCS, etc. Will Also work with CDMA Carriers Such as Verizon, Straight Talk.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Visit ScreenshotNeo or sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Does calling a screenshot API automatically capture only failed Android tests?

No. The test runner or framework must connect capture to its failure-handling mechanism.

Can Firebase Test Lab show screenshots from processed instrumentation captures?

Yes. The documented flow exposes them in a completed test’s Results tab under Screenshots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.