Skip to content

The in-app SDK ​

toets works black-box: the first test needs no app changes. The optional SDK is a small library inside the app that talks to the test host and reports what the app itself knows. It makes tests faster and more reliable, and adds capabilities a black-box driver can not offer.

One exception: an app whose focus lives in a JS focus engine (Norigin Spatial Navigation, LRUD, react-tv-space-navigation, ...) has no focus a driver can see. It reports focus through the SDK with reportFocus() (reporting focus).

DomainAddsCapability
treeuniform element tree, free of accessibility-tree quirkstree.hierarchy
focusthe app's real focus, including app-reported focus
syncidle signal, busy resourcessync.idle
mediaplayer state, position, duration, errorsmedia.state
statelaunch into a named state, feature flagsapp.state
logsconsole output and unhandled errors on the test resultlogs

How it connects ​

Turn it on with toets: { sdk: true } in the config, and start the SDK in the app. On every launch the test host passes a launch payload to the app (SDK host URL, launch token, mock server URL, state). The SDK reads it, connects to the host over WebSocket, and announces the domains it implements; launch() waits for that connection and fails with SDK_NOT_CONNECTED if it never comes. Without a valid payload the SDK does nothing: it never opens a connection in normal use. Exclude it from production builds anyway.

Packages: @toets/sdk (framework-neutral core and web adapter) and @toets/sdk-react-native. Any framework can implement the protocol; a conformance suite verifies it.

Named states ​

With state, a test starts where it needs to be instead of clicking through onboarding:

ts
import { test, expect, requires } from '@toets/test';

test('resumes from the continue-watching rail', requires('app.state'), async ({ app }) => {
  await app.launch({ state: 'signed-in-with-history' });
  await expect(app.getByTestId('rail-continue-watching')).toBeVisible();
});

The app defines what each state name means (onState in the SDK, see app state); toets only delivers the name and any flags.

Traps ​

  • The SDK never sends input. Keys always go through the platform, so the native focus engine is exercised. The SDK only observes and prepares state.
  • Keep black-box tests passing. A test that needs the SDK says so with requires. Do not make the whole suite depend on it by accident.
  • Do not ship it. Guard the SDK behind a debug or test build flag so production bundles exclude it.