glide icon indicating copy to clipboard operation
glide copied to clipboard

Inconsistent screenshot-testing with paparazzi and GlideImage composable

Open hhpettersen opened this issue 1 year ago • 2 comments
trafficstars

Glide Version: 1.0.0-beta01

Integration libraries: Not relevant

Device/Android Version: Ran tests on multiple emulators.

Issue details / Repro steps / Use case background: The issue involves inconsistent loading of images in a screenshot test with Paparazzi using the GlideImage composable. Sometimes the image from a URL loads successfully, other times the image is blank, and occasionally, only the loading placeholder is shown. This inconsistency is problematic for reliable UI testing and screenshot generation.

Composable

val adImageSize = 50.dp
val requestSize = with(LocalDensity.current) { adImageSize.toPx().toInt() }

Box {
    GlideImage(
        model = ad?.image.orEmpty(),
        contentDescription = stringResource(R.string.content_description_adimage),
        contentScale = ContentScale.FillBounds,
        loading = placeholder(painterResource(id = R.drawable.placeholder)),
        failure = placeholder(painterResource(id = R.drawable.ad_placeholder)),
        modifier = Modifier
            .size(adImageSize)
            .align(Alignment.Center)
            .clip(shapes.roundedCornerExtraSmall),
        requestBuilderTransform = {
            it.apply(RequestOptions().override(requestSize))
        },
    )
}

Test

@RunWith(TestParameterInjector::class)
class ChatScreenshotTest(
    @TestParameter
    nightMode: NightMode,
) {
    @get:Rule
    val paparazzi = Paparazzi(
        deviceConfig = DeviceConfig.PIXEL_6_PRO.copy(
            nightMode = nightMode,
        ),
        theme = "android:Theme.Material.ActionBar",
        snapshotHandler = if (PaparazziConfig.isVerifying) {
            SnapshotVerifier(
                maxPercentDifference = PaparazziConfig.maxPercentDifference,
                rootDirectory = PaparazziConfig.dir
            )
        } else {
            HtmlReportWriter(snapshotRootDirectory = PaparazziConfig.dir)
        }
    )

    @Test
    fun textMessages() {
        paparazzi.snapshot {
            CompositionLocalProvider(
                LocalInspectionMode provides true,
            ) {
                Theme {
                    ConversationPreview(createPreviewTextMessages())
                }
            }
        }
    }
}

I also reaised an issue on Paparazzi since I am uncertain where the bug recides at this point: https://github.com/cashapp/paparazzi/issues/1396

hhpettersen avatar Apr 29 '24 11:04 hhpettersen

Is there possibly a way to fake the image request like suggested here? https://github.com/cashapp/paparazzi/issues/1396#issuecomment-2129508948

hhpettersen avatar Aug 14 '24 12:08 hhpettersen