Does anyone here with the UI test experience knows...
# compose
k
Does anyone here with the UI test experience knows how can I test if a button is enable or disabled? I tried settings the
Copy code
Modifier.
.clickable(enable = true) 
.focusable(enable = true)
And using the method
Copy code
fun SemanticsNodeInteraction.assertIsNotEnabled(): SemanticsNodeInteraction = assert(isNotEnabled())
but my
SemanticsConfiguration
doesn't seems to contain the
SemanticsProperties.Disabled
key. Any thoughts in how to include this key to my
SemanticsConfiguration
?
f
Copy code
var isButtonEnabled by remember { mutableStateOf(false) }
Button(
    enabled = isButtonEnabled,
){
  
}
You can test the variable this way Or access the semantics through the InspectorInfo > properties > properties[“enabled”]
k
I figured out that I wasn't getting the button itself, that is why my
SemanticsProperties.Disabled
wasn't there, I was getting the wrong node when looking for the button by its text. Now I am trying to figure out how to get a node from its Role. Any idea?
I used contentDescription instead. Thanks for the help!
r
Now I am trying to figure out how to get a node from its Role. Any idea?
Everything related to Compose test api's are here https://developer.android.com/jetpack/compose/testing-cheatsheet Including
tree-traversal
api's. Still if you are not able to get the required node, you can tag it and use the same tag to get the node.
🙏 1