android / testing-samples

A collection of samples demonstrating different frameworks and techniques for automated testing
Apache License 2.0
9.21k stars 3.62k forks source link

`captureToBitmap` clips the image to the device screen size #480

Closed davidbilik closed 1 year ago

davidbilik commented 1 year ago

I have this class which we use as a base class for our screenshot tests

abstract class ScreenshotTest {

    @get:Rule
    val rule = createComposeRule()

    protected fun snapshotComposable(
        name: String,
        composable: @Composable () -> Unit,
    ) {
        rule.mainClock.autoAdvance = false
        rule.setContent {
            composable()
        }
        rule.waitForIdle()
        rule.onAllNodes(isRoot())
            .onFirst()
            .captureToImage()
            .asAndroidBitmap()
            .writeToTestStorage(name)
    }
}

everything works fine, but if the composable's height is bigger than the device's height, the output bitmap is clipped to the device's resolution. Is there a way to capture the whole composable without this limitation?

brettchabot commented 1 year ago

I suspect this is expected - APIs like captureToBitmap will only capture what is displayed on the screen. But you should ask on a compose related forum to get the authoritative answer. See https://source.android.com/docs/setup/contribute/report-bugs, follow the androidx link