Using the IntelliJ new project wizard, I have been...
# compose-desktop
p
Using the IntelliJ new project wizard, I have been able to create a very simple Compose Desktop app. See attachments. Next I would like to write a simple Junit4 test that will do the following: 1. assert that the black square is visible, and 2. automagically click on the close button to end the test. So far in trying to crack this nut, the best example of Compose Desktop test code I have found is the AOSP ScrollBarTest code. This code is excruciatingly difficult to penetrate while at the same time I'm sure it is just simply brilliant code. I will continue my attempt to grok that code but my entire fortune ($12 USD) goes to the saintly person who makes this grok work totally unnecessary.
z
I haven't done a lot of testing with desktop code but from the test you linked it looks the same as android. You need a way to find your black square using semantics. How are you describing it for accessibility?
p
I'm not sure I understand either of your last two sentences. I am sure I am not doing anything with accessibility at this point. Too early. By "using semantics", I think you are saying I need to use something other than
checkIsDisplayed()
. If so, did you have something in mind? Right now, my leading path to a solution is to implement
checkIsDisplayed()
.
z
You use semantics to describe parts of your UI for both accessibility and testing. So e.g. when you use
Text
we automatically publish the text string as a semantics property, which is how
onNodeWithText()
finds it. You probably want to do something similar with your black square.
p
You use semantics to describe parts of your UI for both accessibility and testing.
I do? Not intentionally in any case.
So e.g. when you use 
Text
 we automatically publish the text string as a semantics property, which is how 
onNodeWithText()
 finds it.
I'm curious, who is "we"? Does
onNodeWithText()
finding a view mean that it is also visible with Compose Desktop? I seem to recall with Espresso that a view could exist and not be visible.
You probably want to do something similar with your black square.
You might be onto something here. For example if the black square were an image, and there was an API something like
onNodeWithImage()
I can see how that might work. Or if a node has a unique tag, I could look for that tag. But I still have to wrestle with the visibility property, I think. I don't know Compose UI well enough to answer that today.
z
“We” is compose, sorry. Standard Compose components automatically publish semantics properties. Eg when you pass a content description to an
Image
composable, it gets published as a semantics property, which then lets you search for it in tests. So yes, you're already “using” semantics in a sense even if you don't know it.
And because semantics are critical for accessibility and testing, it's strongly encouraged to publish semantics for custom components you write yourself.
p
Does
checkIsDisplayed()
have an associated semantic property? And where can I study up on these semantic properties?
z
Just look at the source for checkIsDisplayed. It doesn't use semantics, it looks at the actual layout node. Look at the source for the matchers though (eg
onNodeWithText
), or some of the other assertions. The official docs have a section on semantics.