screenshot-tests-for-android icon indicating copy to clipboard operation
screenshot-tests-for-android copied to clipboard

metadata.json: No such file or directory

Open PawelKwiecinski opened this issue 3 years ago • 2 comments

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:

  • with/without orchestrator
  • check logcat (nothing related to the issue there)
  • use snap(fragment!!.view) -> same issue
  • add all the test data by hand using setName(), etc
  • use different API level emulators: 28,29,27
  • make sure both lib AndroidManifest.xml and test AndroidManifest.xml have WRITE_EXTERNAL_STORAGE permission
  • probably couple other things I've forgot

PawelKwiecinski avatar Oct 07 '21 10:10 PawelKwiecinski

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.

oradkovsky avatar Oct 12 '21 07:10 oradkovsky

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

xiphirx avatar Feb 02 '22 22:02 xiphirx