我如何才能用android捕获谷歌地图作证



我正在努力利用https://github.com/Shopify/android-testify以实现一些屏幕截图测试。然而,它在捕捉地图时遇到了问题。我试过使用和不使用setUseSoftwareRenderer,它似乎显示了一个黑色或灰色的框。

我做错了什么,还是这是一个限制?

示例:

@RunWith(AndroidJUnit4::class)
internal class ShopifyTest {
@get:Rule
var rule = ScreenshotRule(ZoomMapActivity::class.java)
@ScreenshotInstrumentation
@Test
fun default() {
rule.setUseSoftwareRenderer(true)
.assertSame()
}
}

Google MapView在后台使用SurfaceView渲染其内容。这意味着默认的Testify捕获方法不能";参见";地图内容。为了捕获MapView内容,您需要使用能够捕获SurfaceView的其他捕获方法。我建议您启用PixelCopyCapture:

import com.shopify.testify.TestifyFeatures.PixelCopyCapture
@ScreenshotInstrumentation
@Test
fun default() {
rule
.withExperimentalFeatureEnabled(PixelCopyCapture)
.assertSame()
}

PixelCopy直接从设备上的GPU获取内容,因此它对硬件差异非常敏感。因此,我建议您也使用setExactness()为匹配启用较低的精确性阈值。

import com.shopify.testify.TestifyFeatures.PixelCopyCapture
@ScreenshotInstrumentation
@Test
fun default() {
rule
.withExperimentalFeatureEnabled(PixelCopyCapture)
.setExactness(0.9f)
.assertSame()
}

你可以在这里找到一个例子

最新更新