takahirom / roborazzi

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

captureScreenRoboImage generates screenshots with top bar #315

Closed victorpineda-jt closed 2 months ago

victorpineda-jt commented 2 months ago

This might be a silly question, but I've noticed that captureScreenRoboImage() generates a screenshot with a top bar that contains the app name. Is it possible to remove this top bar somehow when using this method?

Thanks in advance.

takahirom commented 2 months ago

Thank you for your message. The function captureScreenRoboImage() is designed to capture the entire screen, whereas captureRoboImage() should be used for specific components. To better assist you, I would need to understand more about your use case. Could you please clarify why you are looking to remove the top app bar from the captureScreenRoboImage() function?

victorpineda-jt commented 2 months ago

I'm using captureScreenRoboImage() as I want to capture a bottom sheet with material 3, and captureRoboImage doesn't seem to be able to do so, even though I've specifically capturing the last root element like composeRule.onAllNodes(isRoot).onLast().captureRoboImage(). But captureScreenRoboImage() works fine. But this method is adding a top bar that doesn't belong to my app with the app name:

Captura de pantalla 2024-04-24 a las 11 28 00

So I was wondering if there is any option to remove it.

takahirom commented 2 months ago

I'm not sure, but Material 3's bottom sheet seems a little different. Have you tried using Espresso instead of a Compose rule to find the node? It would go something like this, though we need to figure out how to do it.

onView(????).captureRoboImage()

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.android.kt;l=473?q=PopupLayout%20androidx.compose.ui.window

victorpineda-jt commented 2 months ago

No, I haven't, I'm not using espresso in my project as it is 100% compose. I don't really want to find the specific bottom sheet node but capture the whole screen, which includes the content behind the bottom sheet. But if there is no easy way to remove that top bar that seems to be somehow generated by robolectric (that top bar is not part of my app) it won't be a big deal, I was just wondering if there was an easy way to remove it from the screenshot.

takahirom commented 2 months ago

Compose's rule uses ActivityScenario, which is part of Espresso. Therefore, I believe you are already using Espresso, perhaps without realizing it. You should be able to use the onView() method. We might have a solution, so I will close this issue for now. I value our users, so if you have any use cases for this feature and the workaround is insufficient, please let me know. I'll reopen the issue.