facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

Use public download directoty to by-pass scoped storage (API 30) #273

Open TimoPtr opened 3 years ago

TimoPtr commented 3 years ago

https://github.com/facebook/screenshot-tests-for-android/issues/162#issuecomment-745454096 I did some try and error on the API 30 and it seems that the only solution that I've found to make it work on API 30 is to use public download dir on external storage.

I first try using specific folder within scoped storage but the files are removed at the end of connected task. I did use download dir because there is some restriction on Picture (filter on the extension).

This solution works but one day this public api is going to be removed.

Also I found out that there is an issue with the orchestrator library and API 30, https://github.com/android/android-test/issues/743 I did try the last alpha but it was not working as expected on the sample project so for now on my side I won't use the orchestrator on API 30.

oradkovsky commented 2 years ago

Really appreciate your effort here, as evolving android is ever-trying to make our lives more "fun".

I cherry-picked the commit and tried it together with whatever master has, not working under Pixel 5 API30 (Android 11) emulator.

Caused by: java.lang.RuntimeException: java.io.IOException: Operation not permitted at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:200) at com.facebook.testing.screenshot.internal.ScreenshotImpl.record(ScreenshotImpl.java:271)

Can be tested under https://maven.pkg.github.com/oradkovsky/screenshot-tests-for-android ver 0.14.2-SNAPSHOT.

oradkovsky commented 2 years ago

Interestingly enough, tests are not crashing under physical device (FTL Pixel 5e redfin, API 30) BUT cloud artifacts no longer have screenshots :(

mo0rti commented 2 years ago

I have the same problem with API 30, The test can't read the file. Is there any update on this PR?

xiphirx commented 2 years ago

Sorry for the (severely) late review. I think the easiest way to maybe get around this would be to move the library to persist screenshots into private app storage and use adb shell run-as when pulling since the APK should be debuggable, although I'm not sure if this will cause issues on real devices off the top of my head.

Dr-Bootman commented 2 years ago

@xiphirx Hey mate, Is there any chance you merge this PR ?