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

metadata.json: No such file or directory #296

Open PawelKwiecinski opened 2 years ago

PawelKwiecinski commented 2 years ago

I'm trying to add screenshot testing using screenshot-tests-for-android and ran into an issue where I cannot get it to work. The error I get:

ls: /sdcard/screenshots/com.xyz.test/screenshots-default/metadata.json: No such file or directory
ls: /data/data/com.xyz.test/app_screenshots-default/metadata.json: No such file or directory

The tests live is a library module. Test uses androidx.fragment.app.testing.launchFragmentInContainer, then waits for it and calls Screenshot.snapActivity(fragment.activity!!). I use a custom test runner configured exactly as in the docs to call onCreate + onDestroy. Tests Use Junit4 + Espresso. The screenshot files themselves get generated, saved and pulled correctly. But the whole thing fails because of the missing metadata.

Things I've tried:

oradkovsky commented 2 years ago

With what I believe is a similar setup (aar + sample app), I ended up putting tests into sample app. My manifest under sample/androidTest not only has WRITE_EXTERNAL_STORAGE, but also package (ending with test) and android:sharedUserId (ending with uid) - something sample app also has in its manifest. The above works for me under API28. APIs beyond come with scoped storage, but it's another story.

xiphirx commented 2 years ago

This typically indicates that you're not calling flush() appropriately like so: https://github.com/facebook/screenshot-tests-for-android/blob/f22eab67ea1eed54d2de126de08657c775692197/core/src/main/java/com/facebook/testing/screenshot/ScreenshotRunner.java#L53