takahirom / roborazzi

Make JVM Android integration test visible 🤖📸
https://takahirom.github.io/roborazzi/
Apache License 2.0
695 stars 29 forks source link

If provide `RoborazziRule.CaptureType.Gif` to the RoborazziRule then `verifyRoborazziDebug` doesn't fails #465

Open september669 opened 1 month ago

september669 commented 1 month ago

I'm trying the example from the Readme and noticed that if I provide RoborazziRule.CaptureType.Gif() to the RoborazziRule then verifyRoborazziDebug task doesn't fail if any changes were applied to the UI. Also RoborazziRule.CaptureType.Gif() generates gifs on recordRoborazziDebug runs, if it matters. In case I provide RoborazziRule.CaptureType.AllImage() task works well.

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import com.github.takahirom.roborazzi.RoborazziRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode

@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(manifest = Config.NONE)
class ComposeTest {
    @get:Rule
    val composeTestRule = createAndroidComposeRule<ComponentActivity>()

    @get:Rule
    val roborazziRule = RoborazziRule(
        composeRule = composeTestRule,
        captureRoot = composeTestRule.onRoot(),
        options = RoborazziRule.Options(
            // RoborazziRule.CaptureType.Gif() // < -- If I provide this then verifyRoborazziDebug doesn't recognize any difference in the screenshots
            RoborazziRule.CaptureType.AllImage()
        )
    )

    @Test
    fun composable() {
        composeTestRule.setContent {
            SampleComposableFunction()
        }
        repeat(3) {
            composeTestRule
                .onNodeWithTag("AddBoxButton")
                .performClick()
        }
    }
}

@Composable
fun SampleComposableFunction() {
    var count by remember { mutableIntStateOf(0) }
    Column(
        Modifier
            .size(300.dp)
    ) {
        Box(
            Modifier
                .testTag("AddBoxButton")
                .size(50.dp)
                .background(color = Color.Green)
                .clickable {
                    count++
                }
        )
        repeat(count) {
            Spacer(modifier = Modifier.height(1.dp))
            Box(
                Modifier
                    .background(color = Color.Black)
                    .size(30.dp)
            )
        }
    }
}
takahirom commented 1 month ago

Thank you for reporting this. Yes, we currently don't have a way to compare the GIFs. This would be a significant feature, as it would involve comparing frame counts, images, or other aspects. However, I'm not sure if this feature would be used frequently.

september669 commented 1 month ago

Thanks for the clarification and for your lib! But it's quite strange to see a non-working example in the Readme. Maybe add some notes about it to the Readme?

takahirom commented 1 month ago

Thank you. I agree. The GIF feature was created at a very early stage of the library development, so the comparison feature did not exist at that time. It should be noted that we do not currently support comparison for GIFs. Thank you for your feedback.