In-app SDK
The SDK is an optional library inside the app. It connects back to the test host when the app is launched by toets and answers questions only the app can answer quickly: the element tree, focus, idle state, media state, app state and logs.
ts
// playwright.config.ts
export default defineConfig({ toets: { sdk: true } /* ... */ });
// a test
await app.launch({ state: 'details:the-matrix' }); // needs app.state
await expect(app.media).toBePlaying(); // needs media.stateHow it fits
- On launch toets issues a launch token and passes a payload (
sdkUrl,token,mockUrl,state,flags) to the app through the driver. The app connects and toets waits up totimeouts.sdkConnectMs; if it never connects, launch fails withSDK_NOT_CONNECTED. - Reloads keep the launch. When the app reloads (
location.reload(), a React Native JS reload or restart), its session closes and the new JS context connects again with the same token. toets attaches the new session; reads meanwhile wait for it, up totimeouts.sdkConnectMs, and fall back to the driver if it never comes. The nextlaunch,terminateorresetends the launch and revokes the token. - Composition: the SDK answers tree, queries, focus, media and idle; the driver still does input, launch and screenshots. If an SDK request fails, toets falls back to the driver. When the SDK reports nothing focused, the driver's focused element counts, matched into the SDK tree by its unique test ID: some native views take focus without a framework focus event (a react-native-tvos
TextInputon tvOS). - Without the payload the SDK is inert, so production builds can ship it.
Principles
- Black-box first, not black-box only. Locators, focus, remote, screenshots and mocking work without the SDK. The SDK makes them faster and more reliable; it does not change what a test means. The exception is focus owned by a JS focus engine: only the app knows it, and reports it with
reportFocus(). - Launch states replace click-throughs.
launch({ state })lets the app jump straight to a screen, so a test about the player does not navigate menus first.
TV trap: the app is not a browser
There is no DOM to inspect on Android TV or tvOS, and native accessibility trees are slow and lossy. The SDK is how a React Native or native app reports focus and idle with the same fidelity as the web.