PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 1, 2022

[FIXED] How can I capture Google Maps with android-testify

 July 01, 2022     android, android-espresso, android-testify, screenshot-testing, shopify     No comments   

Issue

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

Solution

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



Answered By - Daniel Jette
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing