tvOS traps
Where web or mobile intuition is wrong on tvOS.
- No click, no tap. There is no pointer. Move focus with the D-pad, act with
SELECT.focus.pressUntilFocusedpresses a direction until the target holds focus. - testId is
accessibilityIdentifier. Set it with.accessibilityIdentifier("x")(SwiftUI),accessibilityIdentifier(UIKit) ortestID(React Native). XCUITest'snamefalls back to the label; toets deliberately ignores that fallback. - SwiftUI identifiers leak into children. An identifier on a stack is applied to every child. Add
.accessibilityElement(children: .contain)to the container first. - Text belongs to the deepest element.
getByText('Play')can resolve to theStaticTextinside a button, which is never focused.focus.pressUntilFocusedandnavigateToaccept it once the button around it holds focus;toBeFocused()does not. Assert focus on a testId, not on text. - System alerts are not app alerts.
appium:autoDismissAlertsdoes not dismiss every system prompt; App Tracking Transparency's stays up and takes focus. Do not request tracking authorization when toets launched the app:getLaunchPayload()from the SDK is defined then, or pass a launch argument (app.tvOS.launchArguments) that the test build checks. If a prompt must be part of the test, it is on screen like any element: press to its button withfocus.pressUntilFocused(Key.UP, app.getByText('Ask App Not to Track'))and pressSELECT. - Accessible elements speak for their subtree. A button's
textis its accessibility label; if the label differs from what is drawn, assertions see the label. BACKat the root leaves the app. The Menu button on a root screen sends the app to the background, like a user would.focusableis inferred. XCUITest has no focusable flag; custom.focusable()views count once they hold focus or carry the Button trait.- Refs follow the screen structure. Element refs are tree paths; after the screen changes, re-resolve the locator (the core does this for you).
- Presses during a screen transition are dropped. For about 350ms after a push or pop nothing has focus and the focus engine ignores the remote, although the new screen is already in the tree. The driver does not wait for focus: assert it on the new screen (
toBeFocused, ortoHaveFocusWithinon the screen) before the next press.toBeVisiblepasses too early. Apps with a JS focus engine assert the focus they report withreportFocus(). - Down only reaches what is below. The focus engine moves to elements that overlap the focused one along the movement axis. A button at the far left is unreachable with
DOWNfrom a card on the right; on web and Android TV spatial navigation often reaches it. - React Native joins texts into labels. An accessible view (a touchable card, a switch row) gets its children's texts joined with
,as its label, e.g.Northern Lights, 2025 · DramaorAutoplay, Start playback automatically, On. UsetoContainText, or assert on the testId of the text itself. - React Native plain views lose their children. XCUITest flattens a non-accessible view with a
testID(a screen, a rail) into an empty element; its children appear as its siblings. Scoping into it andtoHaveFocusWithinon it need the toets SDK; without it, assert on the focused element's testId. - Offscreen list items are there but invisible. A
FlatListkeeps cards outside the viewport in the tree withvisible: false;toBeVisibleon them fails until focus scrolls them in. - Reads never wait. The driver disables XCUITest's wait-for-idle, so reads return the current state immediately and the core's retries do the waiting. Animations are in flight while you assert; assert on end states.
- Clearing data keeps the container folders.
launch({ clearData: true })andapp.reset()run XCUITest'smobile: clearApp, which also deletestmp/andLibrary/Caches. The driver recreatesDocuments,Library/Caches,Library/Preferencesandtmpafterwards, because apps expect them: a React Native debug build writes the Metro bundle toNSTemporaryDirectory()and shows "The folder 'ReactNativeDevBundle.js' doesn't exist" without it. - The first run builds WebDriverAgent. Expect about a minute once per Xcode version; cache it on CI (see setup).
- One simulator per worker. Focus is global to the device.