androidx.test.espresso.screenshot.captureToBitmap 与 3.6.x

问题描述 投票:0回答:1

从 Android Espresso libs 3.6.0 开始,

captureToBitmap
已更改

以前的 3.5.x 版本:

fun ViewInteraction.captureToBitmap(): Bitmap {

使用它

onView(isRoot()).captureToBitmap().writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-open")

现在在 3.6.x 中

我才发现

class CaptureToBitmapAction(val bitmapReceiver: ViewActions.BitmapReceiver) : ViewAction {

所以我尝试了

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))

但是我不知道该做什么

onBitmapCaptured
现在的问题是,如何使用 3.6.x 进行 Espresso 测试屏幕截图?

android android-espresso
1个回答
0
投票

我让它工作了

import android.graphics.Bitmap
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.action.ViewActions

class BitmapReceiver(val name: String) : ViewActions.BitmapReceiver {
    override fun onBitmapCaptured(bitmap: Bitmap?) {
        bitmap?.writeToTestStorage(name)
    }
}

使用它

val receiver = BitmapReceiver("${javaClass.simpleName}_${nameRule.methodName}-open")
onView(isRoot()).perform(CaptureToBitmapAction(receiver))
© www.soinside.com 2019 - 2024. All rights reserved.