cross-app-tests-with-uiautomator
Installation
SKILL.md
Cross-App Tests with UiAutomator — Drive System UI and Other Apps
UiAutomator is the only AndroidX test framework that can drive UI across process boundaries — Settings, the dialer, system notifications, another app's activity. Espresso refuses (InjectEventSecurityException) when an event would cross to a foreign window. UiAutomator works against the platform AccessibilityNodeInfo tree, so it sees every window. This skill encodes the modern BySelector / UiObject2 API, the singleton acquisition, the StaleObjectException recovery pattern, and the cross-app launch path.
When to use this skill
- The test must drive system UI (Settings, dialer, system notifications, quick settings, recents).
- The test spans the developer's app and another app (share sheet, contacts picker, camera).
- Espresso threw
InjectEventSecurityExceptionbecause the test reached a foreign window. - The user reports
StaleObjectExceptionand is debugging cached-node lifetime. - The user asks how to send the device home, press recents, or toggle airplane mode in a test.
- The user mixes
BySelectorandUiSelectorin the same test and is confused which is current.
When NOT to use this skill
- The UI is entirely inside the developer's app — Espresso (Views) or Compose tests are faster and more reliable. See
../../espresso/writing-espresso-tests/SKILL.mdfor Views. - The runner stack is not yet set up — start with
../../runner/running-instrumented-tests-with-androidjunit4/SKILL.md. - The user only needs to push device-side state changes (animations off, intent stub) — see
../../../adb/control/injecting-input-and-state/SKILL.md. - The test only needs to scrape logs after a run — see
../../../adb/observability/extracting-logs-with-logcat/SKILL.md.