facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

Screenshot doesn't render icons in MaterialButtons. Screenshots only shows button text. #275

Open oluwasanmiAderibigbePapershift opened 3 years ago

oluwasanmiAderibigbePapershift commented 3 years ago

Explanation

I'm trying to generate screenshots for a Material components button, but I noticed button icons are missing in the screenshot. The screenshots only show the button text instead of the button text and icon.

The rendered screenshot below

ScreenEdgePrimaryButton_Enabled

The screenshot is supposed to look like this. image

Steps to reproduce

  1. I followed the steps from #253 to setup screenshots-tets-for-android for material components.
  2. wrote my activity_main.xml
    <com.google.android.material.button.MaterialButton
        android:id="@+id/primaryButton"
        style="@style/ScreenEdgePrimaryButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:icon="@drawable/ic_lock_filled_18"
        tools:text="Edit Password" />
  3. And finally wrote my test case

    @RunWith(AndroidJUnit4::class)
    class ScreenEdgePrimaryButtonTest {
    private val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
    
    @Test
    fun designSizeVariantShouldMatchScreenshot() {
        val themedContext = ContextThemeWrapper(context, R.style.Base_DesignTheme)
        val view = ScreenEdgePrimaryButton(themedContext)
    
        view.setupWithState(
            ScreenEdgePrimaryButtonState(
                icon = R.drawable.ic_lock_filled_24,
                label = "Edit Password",
                onClick = { /* no-op */ }
            )
        )
        ViewHelpers.setupView(view).setExactWidthDp(180).setExactHeightDp(50).layout()
        screenshot(view, "Enabled")
    
        view.updateState { enabled = false }
        ViewHelpers.setupView(view).setExactWidthDp(180).setExactHeightDp(50).layout()
        screenshot(view, "Disabled")
    }
    }

    Did I miss something

Briefly

Everything works fine except the icons are missing when taking screenshots of the MaterialButton