Task API Reference
Choose task APIs by iOS or Android, virtual or physical device, SDK or device mode, and app framework.
Repository tasks execute known operations against one live Ansight session and prove their outcome with named assertions. Start here to choose compatible APIs, then use the focused references for arguments, results, and examples.
Tasks use the generated
ansight/tasks/ansight-task.d.ts
contract. ansight workspace init . installs the support files; existing files
are preserved unless --force is supplied. Author against your installed CLI’s
declaration and check the availability notes below before choosing a method.
Compatibility
Four independent choices determine what a task can do:
| Dimension | Values | What it controls |
|---|---|---|
| Platform | ios, android | Native operations, permission names, and platform tools |
| Device kind | virtual, physical | Simulator/emulator features versus real hardware |
| Execution mode | sdk, device | Connected SDK tools versus external automation |
| App framework | MAUI, React Native, Flutter, Capacitor, native, and other declared framework values | Framework-specific inspection and actions |
Virtual means an iOS Simulator or Android Emulator. Physical
means a real iPhone/iPad or Android device. Either kind can use SDK mode; device
mode also supports both kinds when the external provider is configured.
run.executionMode === "device" does not mean a physical phone.
| Target | External/device-mode provider | SDK-mode app tools |
|---|---|---|
| iOS Simulator | macOS, Xcode, simulator capture and input | Registered iOS/framework SDK tools |
| Physical iOS | Appium/XCUITest and signed WebDriverAgent | Registered iOS/framework SDK tools |
| Android Emulator | ADB and emulator tooling | Registered Android/framework SDK tools |
| Physical Android | Authorized ADB device and UIAutomator | Registered Android/framework SDK tools |
SDK pairing does not provision host input, permission, or simulation tools. See capture modes and external monitoring setup for prerequisites.
Check mode and method support separately
Use schemaVersion: 1, or omit it, in either mode. Declare essential
requires.capabilities and requires.appTools so the host checks the selected
session before importing the module. Omitting requirements does not imply an
SDK dependency or grant access to every API: individual methods still enforce
platform, device, and provider restrictions.
| API family | SDK mode | Device mode |
|---|---|---|
| Visible UI actions, keyboard, live screenshots | Supported provider required | Supported provider required |
| Lifecycle and native permissions | Platform/device restrictions | Platform/device restrictions |
| Logs, telemetry, retained artifacts and annotations | Available evidence | Available evidence |
External sandbox ansight.files | Unavailable | Supported external file provider |
SDK app.* tools and framework navigation | Registered, executable app tools | Unavailable |
| Location, motion, audio, network conditioning | Supported virtual target | Currently unavailable to task calls |
| HTTP, connectivity and touch readers; database and screenshot assertions | Relevant provider/data required | Currently unavailable to task calls |
The ansight prefix means a host API, not that it works without the SDK.
Broad capabilities such as lifecycle or evidence.read do not guarantee
every method in a family. The host method index
labels individual mode restrictions. The
device support matrix distinguishes
iOS/Android and virtual/physical support per operation.
For example, clearLocation() is iOS Simulator only, playAccelerometer() is
Android Emulator only, and native permission control supports physical Android
but not physical iOS. Framework suites require their matching SDK adapter,
regardless of whether the device is virtual or physical.
Module shape
Every task exports a static descriptor and one default function. This example supports SDK or device sessions with semantic UI support:
import type { TaskDefinition, TaskInvocation } from "./ansight-task.d.ts";
export const task = {
"schemaVersion": 1,
"title": "Verify home",
"description": "Proves that the signed-in home screen is visible.",
"startingState": "The app is signed in and showing its home screen.",
"successState": "The home screen remains visible.",
"platforms": ["ios", "android"],
"deviceKinds": ["virtual", "physical"],
"requires": { "capabilities": ["ui.semantic"] }
} satisfies TaskDefinition;
export default async function run({ ansight, expect }: TaskInvocation) {
const result = await ansight.ui.assert({
automationId: "home",
exists: true,
expectedVisible: true
});
expect(result.passed, { id: "home-visible" }).toBe(true);
return { matchCount: result.matchCount };
}
Replace home with an ID observed in the selected provider’s UI tree. The task
does not sign in or navigate automatically: state hints describe prerequisites
and outcomes, and the assertion verifies them. Await host and app calls serially.
A normal return without a named assertion is Inconclusive.
Find a reference
Existing links to sections of this page lead to the corresponding reference below.
| Reference | Topics |
|---|---|
| Task Definition and Execution | Complete descriptor fields, TaskInvocation, TaskRun, secrets, target constraints |
| Requirements, composition and assertions | Capability checks, child tasks, named expect, result status, execution limits |
| UI Automation | Selectors, accessibility and SDK trees, gestures, keyboard, screenshots |
| Device Controls | Support matrix, lifecycle, permissions, location, motion, audio, network conditioning |
| Evidence | Files, spans, HTTP, connectivity, logs, telemetry, artifacts, annotations |
| App Tool API | Common SDK suites, framework-specific tools, registration and result handling |
| Host API Methods | Complete host-method index with execution-mode availability |
ansight: host API
ansight methods run through the resident host and are pinned to
run.sessionId. Target overrides from task code are discarded. Standard typed
methods need no hostTools declaration. ansight.callTool<TResult>(name, args?)
is for extra task-callable host tools explicitly named in the descriptor.
Host methods return inspection data or action results; check their relevant fields with a named assertion. Read the method index and the focused UI, device, and evidence references above.
app: live app API
app.available indicates whether an SDK tool provider is connected. Each
app.* method additionally needs the tool to be registered, granted, and
executable. Use ansight.appTools.list() to discover exact tool IDs and schemas;
declare essential IDs in requires.appTools in the task descriptor.
app.maui, app.react, app.flutter, and app.capacitor require their matching
framework adapter. app.jniReferences is Android-specific. Common SDK suites
and their availability are described in the App Tool API.
App methods return AppToolCallResult<TResult>; narrow on responseType before
reading payload.result. See the result envelope.