Skip to content

Important information on compose testing.

Devrath edited this page Mar 4, 2024 · 5 revisions

Semantics

  • We use semantics in compose to interact with the UI.
  • A UI can be anything from a UI ranging from a piece to an entire screen. So it can be a small composable or a collection of composables.
  • How much semantics is exposed by the developer depends on how much testing needs to be done.

Three main ways to interact with elements

  • Finders: Select one or multiple nodes.
  • Assertions: Check if the nodes contain certain properties.
  • Actions: Now act on the selected nodes such as click action, and gestures.

Ways to identify the view/composable

  • OnNodeWithText
  • OnNodeWithTag
  • OnNodeWithContentDescription

Performing actions

  • performClick()
  • performSemanticsAction(key)
  • performKeyPress(keyEvent)
  • performGesture { swipeLeft() }

Waiting Until

* composeTestRule.waitUntil(timeoutMs) { condition }
* composeTestRule.waitUntilAtLeastOneExists(matcher, timeoutMs)
* composeTestRule.waitUntilDoesNotExist(matcher, timeoutMs)
* composeTestRule.waitUntilExactlyOneExists(matcher, timeoutMs)
* composeTestRule.waitUntilNodeCount(matcher, count, timeoutMs)