android / android/android-test

IOException in BasicScreenCaptureProcessor.process

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

Description

### Description

`BasicScreenCaptureProcessor` uses a deprecated method (`Environment#getExternalStoragePublicDirectory`) for storing screenshot files.

I know that `BasicScreenCaptureProcessor` might be deprecated someday... (see https://github.com/android/android-test/issues/383), but would be nice if it worked in the mean time.

https://github.com/android/android-test/blob/7a8e7b79db529f530aa340b05bddad2b688a50f0/runner/android_junit_runner/java/androidx/test/runner/screenshot/BasicScreenCaptureProcessor.java#L52-L54

Can use the logic from [Facebook screenshotter, which seems to work accross API 23-30 on FTL](https://github.com/facebook/screenshot-tests-for-android/blob/3f6134d668b4e75d73faf3064857915f911e0b8c/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java)

essentially, Facebook screenshotter does the below, plus they call `dir.setWritable(/* writeable = */ true, /* ownerOnly = */ false);` and they grant permissions if needed.
```java
public BasicScreenCaptureProcessor() {
this(new File(System.getenv("EXTERNAL_STORAGE"), "screenshots"));
}
```

Any solution should be compatible with the [FTL `directories-to-pull` option](https://cloud.google.com/sdk/gcloud/reference/alpha/firebase/test/android/run#--directories-to-pull)
> These must be absolute paths under /sdcard, /storage, or /data/local/tmp

### Steps to Reproduce

run `Screenshot.capture().process()` in a test on API 23 virtual device on FTL

### Expected Results

Saves screenshot to disk.

### Actual Results

Exception.
```
E/TestRunner(6545): Caused by: java.io.IOException: The directory /storage/emulated/0/Pictures/screenshots does not exist and could not be created or is not writable.
E/TestRunner(6545): at androidx.test.runner.screenshot.BasicScreenCaptureProcessor.process(BasicScreenCaptureProcessor.java:72)
E/TestRunner(6545): at androidx.test.runner.screenshot.ScreenCapture.process(ScreenCapture.java:140)
E/TestRunner(6545): at androidx.test.runner.screenshot.ScreenCapture.process(ScreenCapture.java:126)
E/TestRunner(6545): ... 34 more
```

### AndroidX Test and Android OS Versions

AndroidX test 1.3.0, API 23

Contributor guide

Open the contributing guide

Research direction

Start in runner/android_junit_runner/java/androidx/test/runner/screenshot/BasicScreenCaptureProcessor.java, especially the constructor and process() path at the reported lines. Reproduce Screenshot.capture().process() on an API 23 FTL virtual device and compare the storage logic with the linked Facebook ScreenshotDirectories implementation. Done means screenshots are saved successfully to an absolute pullable path under /sdcard, /storage, or /data/local/tmp across the stated API range.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile-dev, testing
Issue type
Bug
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.