Starting with Android Espresso libs 3.6.0 the captureToBitmap
was changed
fun ViewInteraction.captureToBitmap(): Bitmap {
using it
onView(isRoot()).captureToBitmap().writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-open")
I only found
class CaptureToBitmapAction(val bitmapReceiver: ViewActions.BitmapReceiver) : ViewAction {
So I tried
class BitmapReceiver(name: String) : ViewActions.BitmapReceiver {
override fun onBitmapCaptured(bitmap: Bitmap?) {
TODO("Not yet implemented")
}
}
val receiver = BitmapReceiver("${javaClass.simpleName}_${nameRule.methodName}-open")
onView(isRoot()).perform(CaptureToBitmapAction(receiver))
But I don't know what to do in onBitmapCaptured
The question is now, how to do an Espresso test screenshot with 3.6.x ?
I made it work. Instead of
onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName_${nameRule.methodName}")
I use now
onView(ViewMatchers.isRoot())
.perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") })