1

I am trying to leverage https://github.com/Shopify/android-testify to implement some screenshot tests. However, it is having trouble capturing the map. I have tried with and without setUseSoftwareRenderer and it seems to be displaying a black or gray box.

What am I doing incorrectly or is this a limitation?

Example:

@RunWith(AndroidJUnit4::class)
internal class ShopifyTest {

    @get:Rule
    var rule = ScreenshotRule(ZoomMapActivity::class.java)

    @ScreenshotInstrumentation
    @Test
    fun default() {
        rule.setUseSoftwareRenderer(true)
            .assertSame()
    }
}
isuPatches
  • 6,384
  • 2
  • 22
  • 30

1 Answers1

1

The Google MapView renders its content using a SurfaceView behind the scenes. This means that the default Testify capture methods are not able to "see" the map content. In order to capture the MapView contents, you will need to use an alternative capture methods that is capable of capturing SurfaceViews. I would recommend you enable PixelCopyCapture:

import com.shopify.testify.TestifyFeatures.PixelCopyCapture

@ScreenshotInstrumentation
@Test
fun default() {
    rule
        .withExperimentalFeatureEnabled(PixelCopyCapture)
        .assertSame()
}

PixelCopy grabs the content directly from the GPU on your device, so it's quite sensitive to hardware differences. As such, I recommend you also enable a lower exactness threshold for the matching using setExactness().

import com.shopify.testify.TestifyFeatures.PixelCopyCapture

@ScreenshotInstrumentation
@Test
fun default() {
    rule
        .withExperimentalFeatureEnabled(PixelCopyCapture)
        .setExactness(0.9f)
        .assertSame()
}

You can find an example of this here

Daniel Jette
  • 913
  • 1
  • 9
  • 23