Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AbdelrahmanTalat opened this issue Nov 2, 2023 · 3 comments
Open

Comments

@AbdelrahmanTalat
Copy link

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
Copy link
Contributor

pettero commented Dec 1, 2023

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
Copy link

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

@fyam1997
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants