I’m using composer to handle instrumented tests.
GrantPermissionRule has introduced for the andorid test support library, [Android]Checking Android Testing Support Library 1.0. The Rule work as @Rule in JUnit4.
We’d like to clean screenshots every time. But we need some permissions to clean them. To achieve it, we can use PermissionRequester to get permissions.
In my case, I run this in Runner and before starting test cases.
fun clearComposerScreenshots() {
val requester = PermissionRequester()
requester.addPermissions(
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.READ_EXTERNAL_STORAGE)
requester.requestPermissions()
val spoon = Environment.getExternalStoragePublicDirectory("app_spoon-screenshots")
val deleteRecursively = spoon.deleteRecursively()
val result = if (deleteRecursively) "success" else "failure"
Log.i(TAG, "clearing screenshots from folder ${spoon.absolutePath} $result")
}
https://github.com/KazuCocoa/EspressoEnv/pull/5 is an example to use the above in Runner.