bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.59k stars 6.12k forks source link

Inconsistent screenshot-testing with paparazzi and GlideImage composable #5402

Open hhpettersen opened 4 months ago

hhpettersen commented 4 months ago

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 commented 1 month ago

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