Android TV traps
Where web or phone intuition is wrong on an Android TV emulator.
Bounds are clipped. Android reports the on-screen part of an element. A card half scrolled out of a rail has half its width; a card fully outside is
visible: falsewith zero width. Move focus to it (focus.pressUntilFocused) instead of asserting on off-screen geometry.Hidden means absent.
GONEandINVISIBLEviews are not in the accessibility tree at all, so a hidden screen yields no elements rather than invisible ones. Visibility assertions still work; hidden elements simply match nothing.React Native flattens plain Views. In React Native's accessibility tree a plain
Viewlists its descendants as its siblings, soapp_root, the screen and its texts appear side by side. Focusable views, scroll views andTVFocusGuideViews keep their children. Locators and container scoping on those work; whole-screen text snapshots do not match the nested SDK tree, which is why the driver does not declaretree.hierarchy. Gate them withrequires('tree.hierarchy'), or snapshot a container that keeps its children.Text is what is rendered. Transformations apply: a theme with
textAllCapsturnsPlayintoPLAY. Assert the rendered text or disable the transformation in the test build.Focus is input focus.
focusedis Android's input focus, which is the D-pad focus on TV. Accessibility focus (TalkBack) is a different thing and is ignored.The payload arrives once per launch. toets force-stops before every launch so the activity is created fresh and
getIntent()carries__toets. Apps that also handleonNewIntentmust read it there if they relaunch themselves.localhostis the device. URLs in the payload work only because the driver reverses their ports. Other host URLs need10.0.2.2(emulator alias for the host) and will not be reversed.React Native debug builds miss Metro. React Native picks
10.0.2.2:8081for Metro only on fingerprints it knows as emulators (generic,google/sdk_gphone). Android TV images (google/sdk_google_atv64_arm64) fall through tolocalhost:8081, the device itself, and show "Unable to load script". Reverse Metro's port with the driver optionreversePorts: [8081]:tsimport { defineConfig, platforms } from '@toets/test'; export default defineConfig({ app: { androidTV: { apk: './build/app-debug.apk', package: 'com.example.tv' } }, // Metro, for React Native debug builds that load their bundle from it. projects: [platforms.androidTV({ reversePorts: [8081] })], });No click, no touch. TV images have no touchscreen; everything goes through keys. A view that is clickable but not focusable is unreachable on a real TV, and toets cannot reach it either.
Idle is not awaited. UiAutomator's wait-for-idle is disabled (video and animations can keep a TV screen busy forever). Assertions retry in the core; never sleep.
Element refs are positional. A ref names a position in the last page source; when the screen changes it resolves to nothing (
ANDROID_ELEMENT_DETACHED). Use locators, which resolve again on every use.