Loading...
Loading...
Use this skill to verify a Compose semantics node's properties from a UI test using `assertExists`, `assertDoesNotExist`, `assertIsDisplayed`, `assertIsNotDisplayed`, `assertIsDeactivated`, `assertIsEnabled`, `assertIsOn`, `assertIsOff`, `assertIsSelected`, `assertIsFocused`, `assertTextEquals`, `assertTextContains`, `assertContentDescriptionEquals`, `assertValueEquals`, `assertRangeInfoEquals`, `assertHasClickAction`, plus the generic `assert(matcher)` escape hatch and the boolean `isDisplayed()` / `isNotDisplayed()` for `waitUntil` predicates. Covers collection variants `assertCountEquals`, `assertAny`, `assertAll`. Use when the developer wants to verify a Switch is on, a Button is enabled, a Text shows the expected string, a node is displayed vs merely composed, or asks about `assertIsDisplayed` vs `assertExists`. If the developer mentions any `assert*` API on `SemanticsNodeInteraction`, use this skill.
npx skill4agent add skydoves/android-testing-skills asserting-node-state-and-textfetchSemanticsNodeSemanticsNodeInteractionassert(matcher)waitUntilassertIsDisplayedassertExistsassert(matcher)node.config[...]../../finders/finding-nodes-by-tag-text-content/SKILL.md./asserting-bounds-and-dimensions/SKILL.mdSemanticsMatcher../../finders/composing-semantics-matchers/SKILL.md../../synchronization/synchronizing-with-idle/SKILL.mdComposeTestRuleComposeUiTest../../setup/configuring-test-dependencies/SKILL.mdonNode*onAllNodes*assertIsDisplayedAssertions.kt:30-39commonMain/.../Assertions.kt| Question | API | File:line |
|---|---|---|
| Is it in the tree? | | |
| Is it gone? | | |
| Is it a SubcomposeLayout retained child? | | |
| Is it visible to the user? | | |
| Is it interactive? | | |
| Is the toggle on? | | |
| Is the radio/tab selected? | | |
| Does it have focus? | | |
| Does it equal these strings? | | |
| Does it contain this string? | | |
| Content description equals these? | | |
| Content description contains this? | | |
| StateDescription equals X? | | |
| ProgressBar at this position? | | |
| Has a click action? | | |
| Anything else | | |
assertIsDisplayedassertExistsassertExists()assertIsDisplayed()Assertions.kt:30-39assertExists()assertIsDisplayed()fetchSemanticsNode().config[...]Assertions.kt:254-267assertbuildGeneralErrorMessage(errorMessageOnFail, selector, node)assertCountEquals(expectedSize)Assertions.kt:276-292assertAny(matcher)Assertions.kt:300-312assertAll(matcher)Assertions.kt:323-339waitUntilisDisplayed()BooleanAssertions.kt:351rule.waitUntil { node.isDisplayed() }isNotDisplayed()Assertions.kt:361../../synchronization/synchronizing-with-idle/SKILL.mdassert(matcher)../../finders/composing-semantics-matchers/SKILL.mdmessagePrefixOnErrorassertIsDisplayedassertExists// WRONG
@Test
fun submit_isVisibleAfterError() {
rule.setContent { CheckoutScreen(state = state) }
rule.onNodeWithTag(SubmitTag).assertExists()
}
// WRONG because: assertExists passes for nodes that are composed but off-screen, behind a
// dialog, or measured to zero size. The test does not prove the user actually sees the button.// RIGHT
@Test
fun submit_isVisibleAfterError() {
rule.setContent { CheckoutScreen(state = state) }
rule.onNodeWithTag(SubmitTag).assertIsDisplayed()
}assertIsOn// WRONG
@Test
fun darkMode_switch_isOn() {
rule.setContent { SettingsScreen() }
val node = rule.onNodeWithTag(DarkModeSwitchTag).fetchSemanticsNode()
assertEquals(ToggleableState.On, node.config[SemanticsProperties.ToggleableState])
}
// WRONG because: bypasses the framework's error reporting. Failure prints a JUnit assertEquals
// diff with no node dump, no selector description, no hint about which screen the failure
// happened on.// RIGHT
@Test
fun darkMode_switch_isOn() {
rule.setContent { SettingsScreen() }
rule.onNodeWithTag(DarkModeSwitchTag).assertIsOn()
}assertIsOnassert(isOn())Assertions.kt:74isOn()expectValue(SemanticsProperties.ToggleableState, ToggleableState.On)Filters.kt:61-62assertTextEquals// production:
TextField(value = "hello", onValueChange = {}, label = { Text("Name") },
modifier = Modifier.testTag(NameFieldTag))
// test:
rule.onNodeWithTag(NameFieldTag).assertTextEquals("Name", "hello")assertTextEquals(vararg)SemanticsProperties.TextSemanticsProperties.EditableTextAssertions.kt:181-185Filters.kt:274-293assertTextEquals("Name", includeEditableText = false)assertCountEqualsonAllNodes(...).onFirst().assertExists()// WRONG
rule.onAllNodesWithTag(ItemTag).onFirst().assertExists()
// WRONG because: only proves there is at least one item. Drift to zero items causes
// "no node matched" instead of a count error; drift to many is silently accepted.// RIGHT
rule.onAllNodesWithTag(ItemTag).assertCountEquals(3)assert(matcher)@Test
fun row_hasPriorityOne() {
rule.setContent { TaskList(tasks = tasks) }
rule.onNodeWithTag(TaskRowTag)
.assert(SemanticsMatcher.expectValue(PriorityKey, 1))
}PriorityKeySemanticsPropertyKey<Int>Modifier.semantics { priority = … }../../finders/composing-semantics-matchers/SKILL.mdassertAnyassertAll// "at least one row is selected" — must have at least one row
rule.onAllNodesWithTag(RowTag).assertAny(isSelected())
// "every row is enabled" — accepts zero rows (passes vacuously)
rule.onAllNodesWithTag(RowTag).assertAll(isEnabled())assertAnyAssertionError("Failed to assertAny … no node matched")Assertions.kt:305-307assertAllAssertions.kt:323-339isDisplayed()waitUntil// WRONG
rule.waitUntil { rule.onNodeWithTag(SnackbarTag).assertIsDisplayed(); true }
// WRONG because: assertIsDisplayed throws on the first poll where the snackbar isn't yet
// shown. waitUntil expects a boolean — predicates that throw will fail-fast.// RIGHT
rule.waitUntil(timeoutMillis = 2_000) {
rule.onAllNodesWithTag(SnackbarTag).fetchSemanticsNodes().isNotEmpty() &&
rule.onNodeWithTag(SnackbarTag).isDisplayed()
}
rule.onNodeWithTag(SnackbarTag).assertTextContains("Saved")isDisplayed()falseAssertions.kt:343-351../../synchronization/synchronizing-with-idle/SKILL.mdwaitUntilmainClock.advanceTimeUntilassertIsDeactivated// LookaheadLayout / SubcomposeLayout may retain a previously composed slot for reuse.
// To verify the slot is currently deactivated (kept, not active):
rule.onNodeWithTag(RetainedSlotTag).assertIsDeactivated()assertIsDeactivatedSemanticsNodeInteraction.kt:137-148node.layoutInfo.isDeactivatedassertIsOnassertIsEnabledassertTextEqualsfetchSemanticsNode().config[...]assertIsDisplayed()assertExists()isDisplayed()isNotDisplayed()waitUntil { … }assertIs*waitUntilassertCountEquals[0]../../finders/composing-semantics-matchers/SKILL.mdnode.config[...]assertIs*assertTextEqualsassert(matcher)assertIsDisplayedassertExistswaitUntil { … }isDisplayed()isNotDisplayed()fetchSemanticsNodes().sizeassertIs*assertAnyassertAll./gradlew :app:connectedDebugAndroidTest:app:testDebugUnitTestcompose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Assertions.ktassertIs*assertTextEqualsassertContentDescriptionEqualsassertHasClickActionassertCountEqualsassertAllassertAnyisDisplayedisNotDisplayedcompose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/SemanticsNodeInteraction.ktassertExistsassertDoesNotExistassertIsDeactivatedfetchSemanticsNodecompose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Filters.ktisOnisEnabledhasTexthasClickAction