takahirom / roborazzi

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

Make A11y Dump more generic via SnapshotTransformer #291

Open yschimke opened 3 months ago

yschimke commented 3 months ago

The A11y dump https://github.com/takahirom/roborazzi/pull/55 doesn't suit my purpose. There isn't an easy way to supply an alternate strategy.

Ideally the existing A11y dump feature and other features could be implemented using a clean API.

Examples

I ended up using the RoboComponent.Screen class to grab a bitmap, then transforming it to show A11y info in a resized bitmap.

See here https://github.com/google/horologist/pull/2182/files#diff-7d20314095381dcb544af22f8ddd40d6dd3121bd95864b77eaa155d724afa678R124

    public fun captureScreenA11yRoboImage(
        filePath: String,
        roborazziOptions: RoborazziOptions,
    ) {
        Espresso.onIdle()

        val screenImage: Bitmap = captureScreenImageToBitmap(roborazziOptions) // uses RoboComponent.Screen

        val annotatedImage: Bitmap = A11ySnapshotTransformer().transform(composeRule.onRoot(), screenImage)

        annotatedImage.captureRoboImage(filePath, roborazziOptions)
    }
yschimke commented 3 months ago

Example

image

takahirom commented 3 months ago

Thank you, as always. It seems that you would like to access the screen bitmap, is that correct? Or is there something else you want to do?

yschimke commented 3 months ago

At minimum I guess a clean API to capture the bitmap.

But I'm hoping there is some interceptor style API to postprocess the bitmap with contextual info before comparison.

takahirom commented 2 months ago

I have a different use case for this. I want to focus on crucial screen elements, such as the visibility of a button. Therefore, I'd like to highlight that area with a square. We might need to develop more basic APIs rather than practical ones for this purpose.

captureRoboImage() { roboCanvas ->
  roboCanvas.drawRectWithText(onNodeWithTag('subscribe_button').toRoboComponent(), "Subscribe Button")
}
yschimke commented 2 months ago

@takahirom That sounds great. I think I could rework the current A11y transformer I have to do those draw operations.

Although I hope it's possible to expand or reduce the result bitmap size.