如何使用 android-testify 捕获 Google 地图
How can I capture Google Maps with android-testify
我正在尝试利用 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()
}
你可以找到一个这样的例子here
我正在尝试利用 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()
}
你可以找到一个这样的例子here