Created
May 27, 2022 14:51
-
-
Save marianeum/c9a62e00141c42cdeedbd170126472e7 to your computer and use it in GitHub Desktop.
Access compose root view in test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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