Does Jetpack Compose offer a way to query the sema...
# compose
j
Does Jetpack Compose offer a way to query the semantic tree? For example, looking for a specific node, maybe marked with a
testTag
.
z
Your problem can most likely be solved in another way. Why do you want to achieve this?
j
In the abstract, I'd still like to know the answer to the question i.e. is it possible or not? Practically, for example, let's say I have a dialog that appears for some duration then disappears without user interaction. In an instrumented test, after triggering the dialog to appear, how do I wait till the dialog has disappeared before proceeding with the rest of the test? Instrumented test asserts can tell you if something is no longer visible, but they have the undesirable side effect of also possibly failing the test. So, I'm looking for something like an assert but without the side-effect.
s
if you are looking for a node with a specific test tag, you can use
onNodeWithTag()
e.g.
composeTestRule.onNodeWithTag("myTestTag").assertExists()
j
Thanks @Simon Stahl. I was trying to just check the state of the UI without an assert i.e. without the possibility that the test might fail due to the assert failing.
I just realized that asserts don't have any backdoor to the the test in which they run - they fail the test by throwing an exception. So, though this isn't as clean a solution as I'd hoped for, I could wrap an assert in a try-catch and repeatedly execute the try-catch until the assert no longer throws an exception. That could be fine.