Skip to content

Instantly share code, notes, and snippets.

@marianeum
Created May 27, 2022 14:51
Show Gist options
  • Save marianeum/c9a62e00141c42cdeedbd170126472e7 to your computer and use it in GitHub Desktop.
Save marianeum/c9a62e00141c42cdeedbd170126472e7 to your computer and use it in GitHub Desktop.
Access compose root view in test
// Sometimes you may need access to the root view in a test when working with compose.
// This is particularly useful for screenshot tests with popups/dialog where the root view
// will be in a separate window, rather than the activity
// This snippet shows how this can be used
val view = composeTestRule.onNode(isDialog()).fetchRootView()
private fun SemanticsNodeInteraction.fetchRootView(): View {
val node = fetchSemanticsNode()
return (node.root as ViewRootForTest).view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment