https://kotlinlang.org logo
#compose
Title
# compose
k

Kivia Brito

04/05/2022, 6:09 PM
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

FunkyMuse

04/05/2022, 6:56 PM
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

Kivia Brito

04/05/2022, 7:38 PM
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

ritesh

04/05/2022, 9:55 PM
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
10 Views