Loading...
Loading...
Use this skill to drive Jetpack Compose UI from tests with the high-level action APIs that do not go through a gesture builder — performClick, performScrollTo, performScrollToIndex, performScrollToKey, performScrollToNode, requestFocus, performSemanticsAction, and performFirstLinkClick. Covers picking the correct receiver node (the scrollable container vs an item), the matchers used to find a scroll parent (hasScrollAction, hasScrollToIndexAction, hasScrollToKeyAction, hasScrollToNodeAction), and how the lazy vs non-lazy scrollable cases differ. Use when the developer asks "how do I tap a Compose node", "scroll to an item in a LazyColumn", "click a link inside Text", "trigger a custom semantics action", or reports "Action performScrollTo failed" / "node has no parent layout with a Scroll SemanticsAction" / "ScrollToIndex not defined".
npx skill4agent add skydoves/android-testing-skills clicking-and-scrollingperformTouchInput { … }../injecting-touch-gestures/SKILL.mdLazyColumnLazyRowAccessibilityAction<T>Modifier.semantics { … }LinkAnnotationText../injecting-touch-gestures/SKILL.md../injecting-mouse-and-keyboard/SKILL.md../entering-text/SKILL.md../../finders/finding-nodes-by-tag-text-content/SKILL.md../../debug/printing-the-semantics-tree/SKILL.mdandroidx.compose.ui:ui-test-junit4androidx.compose.ui:ui-testrunComposeUiTest../../setup/configuring-test-dependencies/SKILL.mdModifier.testTag("…")performScrollToIndexperformScrollToKeyLazyColumnLazyRowModifier.verticalScrollperformFirstLinkClickTextAnnotatedStringLinkAnnotationperformClickperformScrollToperformFirstLinkClickperformScrollToIndexperformScrollToKeyperformScrollToNode../../debug/printing-the-semantics-tree/SKILL.mdperformClick()performTouchInput { click() }actualrule.onNodeWithTag(SubmitButtonTag).performClick()performScrollTo()SemanticsActions.ScrollByAssertionErrorrule.onNodeWithTag(LastItemTag).performScrollTo().assertIsDisplayed()performScrollToIndex(index)SemanticsActions.ScrollToIndexLazyColumnrule.onNode(hasScrollToIndexAction()).performScrollToIndex(42)performScrollToKey(key)IndexForKeyScrollToIndexkey = { … }LazyColumnLazyRowrule.onNode(hasScrollToKeyAction()).performScrollToKey("user-7")performScrollToNode(matcher)performScrollTorule.onNode(hasScrollToNodeAction()).performScrollToNode(hasText("End of feed"))requestFocus()performSemanticsAction(SemanticsActions.RequestFocus)performIndirectPointerInputBasicTextFieldperformTextInputrule.onNodeWithTag(InputTag).requestFocus()AccessibilityAction<T>performSemanticsAction(key, invocation)performSemanticsAction(key)Modifier.semantics { … }AssertionErrorval MyAction = SemanticsPropertyKey<AccessibilityAction<(Int) -> Boolean>>("MyAction")
// production:
Modifier.semantics { this[MyAction] = AccessibilityAction("Bump") { delta -> bump(delta); true } }
// test:
rule.onNodeWithTag(Tag).performSemanticsAction(MyAction) { it(3) }LinkAnnotationTextperformFirstLinkClick(predicate){ true }rule.onNodeWithTag(BodyTag).performFirstLinkClick { it.item is LinkAnnotation.Url }// WRONG
rule.onNodeWithTag("item-7").performScrollToIndex(7)
// WRONG because: performScrollToIndex requires the ScrollToIndex semantics action,
// which lives on the LazyColumn container, not on its items. AssertionError:
// "Failed to scroll to index 7, the node is missing [ScrollToIndex]".// RIGHT
rule.onNode(hasScrollToIndexAction()).performScrollToIndex(7)
rule.onNodeWithTag("item-7").assertIsDisplayed()hasScrollToIndexAction()Filters.ktSemanticsActions.ScrollToIndex// WRONG
rule.onNodeWithTag(BottomBannerTag).assertIsDisplayed()
// WRONG because: a Column inside Modifier.verticalScroll renders all children, but
// children outside the viewport are clipped — assertIsDisplayed fails because
// the visible bounds intersect the viewport at zero pixels.// RIGHT
rule.onNodeWithTag(BottomBannerTag).performScrollTo().assertIsDisplayed()performScrollTohasScrollAction()performScrollToNode// RIGHT
rule.onNode(hasScrollToNodeAction()).performScrollToNode(
hasText("Privacy Policy", substring = true)
)hasScrollToNodeAction()Filters.ktperformScrollToNodeval Bump = SemanticsPropertyKey<AccessibilityAction<(Int) -> Boolean>>("Bump")
@Composable
fun Counter(value: Int, onBump: (Int) -> Unit) {
Box(
Modifier
.testTag("counter")
.semantics {
this[Bump] = AccessibilityAction("Bump") { delta ->
onBump(delta); true
}
}
) { Text(value.toString()) }
}@Test fun bumpAction_increments() {
var value by mutableIntStateOf(0)
rule.setContent { Counter(value) { value += it } }
rule.onNodeWithTag("counter").performSemanticsAction(Bump) { it(5) }
rule.runOnIdle { assertEquals(5, value) }
}OnClick// RIGHT
@Test fun privacyLink_navigates() {
var clicked = false
rule.setContent {
Text(
buildAnnotatedString {
append("Read our ")
withLink(LinkAnnotation.Url("https://example.com/privacy") {
clicked = true
}) { append("Privacy Policy") }
},
modifier = Modifier.testTag(BodyTag),
)
}
rule.onNodeWithTag(BodyTag).performFirstLinkClick { it.item is LinkAnnotation.Url }
rule.runOnIdle { assertTrue(clicked) }
}performFirstLinkClickLinkAnnotationAnnotatedStringOnClick// RIGHT
rule.onNodeWithTag(SurfaceTag).requestFocus()
rule.performIndirectPointerInput( // extension on SemanticsNodeInteractionsProvider, not on a node
indirectPointerEventPrimaryDirectionalMotionAxis = Vertical,
inputDeviceSize = IntSize(1000, 1000),
) {
// events go to the focused tree
}performIndirectPointerInputSemanticsNodeInteractionsProviderComposeUiTestSemanticsNodeInteractioninternalrule.onRoot().performIndirectPointerInput(...)requestFocusperformScrollToIndexperformScrollToKeyperformScrollToNodeAssertionError: the node is missing [ScrollToIndex]performScrollToperformScrollToModifier.testTag("…")runOnIdle { … }stateperformScrollToLazyColumnperformScrollToIndexperformScrollToKeyperformScrollToNodeperformClick../injecting-mouse-and-keyboard/SKILL.mdhasScrollAction()hasScrollToIndexAction()hasScrollToKeyAction()hasScrollToNodeAction()performScrollToIndexperformScrollToKeyperformScrollToNodehasScrollToIndexAction()performClickperformSemanticsActionSemanticsPropertyKeyModifier.semantics { … }rule.runOnIdle { … }./gradlew :app:connectedDebugAndroidTest:app:testDebugUnitTestcompose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Actions.ktperformClickperformScrollToperformScrollToIndexperformScrollToKeyperformScrollToNoderequestFocusperformSemanticsActionperformFirstLinkClickcompose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Filters.kthasScrollActionhasScrollToIndexActionhasScrollToKeyActionhasScrollToNodeActioncompose/foundation/foundation/integration-tests/lazy-tests/.../LazyListTest.ktperformScrollToIndexperformScrollToKeycompose/foundation/foundation/src/androidDeviceTest/.../CombinedClickableTest.ktperformClickperformTouchInput { longClick() }