pedrovgs / Shot

Screenshot testing library for Android
Apache License 2.0
1.19k stars 116 forks source link

Is there any way to capture a snapshot of a BottomSheetDialog #347

Open AbdelrahmanTalat opened 1 year ago

AbdelrahmanTalat commented 1 year ago

Expected behaviour

When a snapshot is captured the BottomSheetDialog should be present

Actual behaviour

BottomSheetDialog is not present in a captured snapshot

Steps to reproduce

Create an activity with a BottomSheetDialog when the bottom sheet is displayed and compareScreenshot(activity) is called the resulting snapshot doesn't contain the BottomSheetDialog

Version of the library

pettero commented 11 months ago

We had this problem as well.

Solved by finding the view that we wanted and taking the screenshot of the view within the bottomsheet.

onView(withId(R.id.xxx)).check { view, _ ->
  compareScreenshot(view)
}
nelson-glauber commented 11 months ago

I'm facing the same issue, but on ModalBottomSheet from Material M3 library... any news about this?

fyam1997 commented 10 months ago

I'm facing the same issue, but on ModalBottomSheet from Material M3 library... any news about this?

My solution is

    fun SemanticsNodeInteraction.rootView() = (fetchSemanticsNodes().root as ViewRootForTest).view

    rule.setContent {
        ModalBottomSheet(
            modifier = Modifier.testTag("dialog"),
            ...
        )
    }
    val view = rule.onNodeWithTag("dialog").rootView()
    compareScreenshot(view)

rootView is for the test to capture the bottomSheet with a transparent background. If do compareScreenshot(rule.onNodeWithTag("dialog")), it will capture the status bar