Is it possible to use `ComposeTestRule` for UI au...
# compose-wear
l
Is it possible to use
ComposeTestRule
for UI automation when generating baseline profiles? UiAutomator does not really seem to work that well with compose+wear (e.g.
scrollUntil
does not detect scrolling), and I'm wondering if Compose's better UI testing APIs could be used here I tried to use
createEmptyComposeRule
but that does not seem to work either ("No compose hierarchies found in the app")
y
I don't think so, because ComposeTestRule runs in the same process as the code under test.
Macrobenchmark runs separately and wants to install, reset the target.
Looking at the Wear Compose baseline profile generation, it seems like it's doing some hybrid. But I assume it requires some post processing. Since you aren't running for an app. https://cs.android.com/search?q=MacrobenchmarkScope%20scroll&ss=androidx%2Fplatform%2Fframeworks%2Fsupport:wear%2Fcompose%2F
Copy code
/** Represents a screen that can be used in Macrobenchmark tests. */
interface MacrobenchmarkScreen {
    val content: @Composable BoxScope.() -> Unit
    val exercise: MacrobenchmarkScope.() -> Unit
        get() = { device.waitForIdle() }
}
@stevebower with the way you've set these up, does it let you use Compose APIs directly? or is it always still UIAutomator/UIDevice?
l
Ok, thank you for confirming it's not supported. Any ideas if
scrollUntil
should be working with compose? Right now I'm getting these kinds of errors in the logs: "Couldn't determine whether scroll was finished, retrying: count 1" - I think scrollUntil is trying to listen for some View-based scroll events, but won't receive them because scrolling is handled by compose. And after only a few tries it aborts before reaching the specified condition. Is this expected or am I doing something wrong here? I'm using the function like this:
col.scrollUntil(Direction.DOWN, Until.hasObject(By.res("settingsButton")))
y
You can always write this loop yourself for now
But file a bug
l
That's exactly what I did 😄 I'll write the bug later
s
Our Wear Compose Material3 macrobenchmarks use UiAutomator to find and exercise objects on the device. We wrote them in such a way that the 'content' and 'exercise' are written together in a common class which makes it more maintainable to a) set a content description or test tag on the composable b) find the content description / test tag from the test code. But only the macrobenchmark-target uses the 'content' and only the macrobenchmark test uses the 'exercise'.