takahirom / roborazzi

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

Background on screenshots when using composeRule instead of the capture method directly #398

Closed eddnav closed 3 weeks ago

eddnav commented 4 weeks ago

In my code I have:

 @get:Rule
    val composeRule = createComposeRule()

    @Before
    fun setup() {
        LottieTask.EXECUTOR = Executor(Runnable::run)
    }

    @Test
    fun test() {
        composeRule.setContent {
             SomeComposableUsingLottie()
        }
        composeRule.onRoot().captureRoboImage("name.png")
    }

This works well, test don't hang due to Lottie, however, this causes my snapshots to have a background: snapshot

What could be causing this?

If instead I just do:

    @Test
    fun test() {
        captureRoboImage("name.png) {
             SomeComposableUsingLottie()
        }
    }

My snapshots render as expected: snapshot

For everything except Composables that include Lottie of course because they never finish.

I noticed a related issue here: https://github.com/takahirom/roborazzi/issues/166. This user has the exact same issue and he resolved it by using my initial approach, but for me it's critical that my backgrounds are transparent.

takahirom commented 4 weeks ago

I can't say for sure, but I think the reason why you can't capture a transparent screenshot is that you are using the default activity. How about specifying RoborazziTransparentActivity when you use createComposeRule()?

eddnav commented 3 weeks ago

I can't say for sure, but I think the reason why you can't capture a transparent screenshot is that you are using the default activity. How about specifying RoborazziTransparentActivity when you use createComposeRule()?

Yep! this did the trick. Very much appreciated. It might be a good idea to include RoborazziTransparentActivity somewhere in the readme though! In any case, thank you!