gpt4 book ai didi

android - Facebook 的屏幕截图测试失败,api 大于 23

转载 作者:行者123 更新时间:2023-12-03 19:37:37 31 4
gpt4 key购买 nike

我正在使用 Karumi 的镜头插件 (https://github.com/karumi/shot) 从我的测试中截取屏幕截图,然后使用 facebook 的库进行比较:http://facebook.github.io/screenshot-tests-for-android/

该库在使用大于 23 的 api 运行时会出现问题,因为它需要 WRITE_EXTERNAL_STORAGE 权限,并且由于 api 23,在测试期间授予权限并非易事。

但是在 espresso 3.0 中添加了 GrantPermissionRule 并且有了这个,您可以轻松地在之前设置权限来执行测试。

好吧,我添加了规则:

@Rule @JvmField
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)

并使用以下代码截取屏幕截图:
Screenshot.snapActivity(activityTestRule.activity).record()

我有一个运行的自定义 TestRunner:
override fun onCreate(args: Bundle) {
super.onCreate(args)
ScreenshotRunner.onCreate(this, args)
}

override fun finish(resultCode: Int, results: Bundle) {
ScreenshotRunner.onDestroy()
super.finish(resultCode, results)
}

但是当我执行测试时,我收到以下错误:
java.lang.RuntimeException: Failed to create the directory for screenshots. Is your sdcard directory read-only?
at com.facebook.testing.screenshot.internal.ScreenshotDirectories.getSdcardDir(ScreenshotDirectories.java:66)

最佳答案

该插件无法将屏幕截图保存在 API >= 23 中,因为必须在测试 APK 而不是被测 APK 中授予权限。使用名为授予权限测试规则的规则不提供此功能。官方 Facebook 库不支持此功能,我们暂时不支持它:(

我还在 GitHub 存储库中回答了您的问题 https://github.com/Karumi/Shot/issues/19#issuecomment-328334528

关于android - Facebook 的屏幕截图测试失败,api 大于 23,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46126100/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com