android / android/android-test

Screenshot fails with long view / Screenshot functionality missing

Open
#890 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
11h 29m
Merged PRs (30d)
2

Description

### Description
When using the `Screenshot.capture(view)` method on a long constraint layout (I had a need to capture the full content of a long scroll view), an exception is thrown due to `View.getDrawingCache()` returning `null`. As far as I can tell from research this can occur in views that result in a large bitmap, the `getDrawingCache()` method just gives up.

I tried a number of workarounds but the only effective one has been to draw the view to bitmap by doing a measure, layout, `draw(canvas)` approach. Unfortunately there is no mechanism in `Screenshot` to do things this way, `ScreenCapture` also has a package-private constructor, and the set of processors in `Screenshot` are private, making it difficult to extend the behaviour to accommodate different capture methods. In the end I resorted to defining a hacky extension in the `androidx.test.runner.screenshot` package in my project.

This exposes a functionality gap in the Screenshot class and I'd suggest (and am happy to work on) a variant of of `Screenshot.capture` that either captures the bitmap using the `View.draw` method or takes a function allowing the API user to specify their own bitmap creation allowing easier reuse of the rest of the Screenshot functionality (processing and writing to file).

### AndroidX Test and Android OS Versions
runner 1.3.0

Contributor guide

Open the contributing guide

Research direction

Start with Screenshot.capture(view), then inspect ScreenCapture and the private processors described in the issue to understand the existing capture, processing, and file-writing flow. Done means exposing a supported capture variant that handles long views without getDrawingCache() returning null while preserving the existing processing and file output behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.