> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quiesco.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 类型

> API 参考的方法签名中出现的类型：匹配器、返回值、选项，以及 runner 和 App 内使用的类型。

方法签名中出现的每个类型，及其在 Quiesco 源码中的声明。用 `import type { … } from '@quiesco/core'` 导入；
App 内使用的类型来自 `@quiesco/agent`，runner 的选项来自各 runner 的包。字符串联合类型（`Direction`、`Permission` …）见[常量](https://docs.quiesco.dev/zh/api-constants.md)。

## 匹配器

### `MatcherInput`

```ts theme={null}
type MatcherInput = ElementQuery | string;
```

### `ElementQuery`

```ts theme={null}
interface ElementQuery {
  /** testID：完全一致的字符串或 RegExp。 */
  id?: TextQuery;
  /** 元素子树的文本（返回匹配的最深层元素）。 */
  text?: TextQuery;
  /** accessibilityLabel / aria-label。 */
  label?: TextQuery;
  /** accessibilityRole / role。 */
  role?: string;
  /** 语义类型（`'button'`、`'input'`、`'switch'` …：在所有平台上相同）、宿主组件类型（`'RCTView'`、`'div'`），或渲染该元素的组件的 displayName。 */
  type?: SemanticType | (string & {});
  /** 某个后代元素匹配（Detox 的 `withDescendant`）。 */
  has?: ElementQuery | string;
  /** 元素自身不匹配。 */
  not?: ElementQuery | string;
  /** 位于该匹配器匹配到的唯一元素内部（Detox 的 `withAncestor`）。 */
  within?: ElementQuery | string;
  /** 第 n 个匹配（从 0 开始），按渲染顺序，在所有平台上顺序相同。 */
  index?: number;
}
```

### `TextQuery`

```ts theme={null}
type TextQuery = string | RegExp;
```

## 返回值

### `ElementSummary`

```ts theme={null}
/** agent 报告的匹配元素信息。 */
interface ElementSummary {
  /** 宿主组件类型，例如 `RCTView`、`RCTText`、`div`。 */
  type: string;
  testID?: string;
  text: string;
  role?: string;
  label?: string;
  rect: Rect | null;
  visible: boolean;
  /** 元素面积的可见比例（0–1）：位于窗口内、且位于每个裁剪内容的祖先（滚动视图、`overflow: hidden`）内的部分。被样式隐藏时为 0。 */
  visibleRatio: number;
  /** 元素属于 SEMANTIC_TYPES 之一时，其与平台无关的类型。 */
  semanticType?: SemanticType;
  /** 拥有输入焦点（文本输入框；web 上为获得焦点的 DOM 元素）。 */
  focused: boolean;
  /** 禁用时为 false（`disabled`、`accessibilityState.disabled`、`aria-disabled`、`editable={false}`）。 */
  enabled: boolean;
  /** 开关、复选框和单选框的选中状态（`accessibilityState.checked`、`aria-checked`、Switch 的 `value`）。 */
  checked?: boolean | 'mixed';
  /** 当前值：TextInput 的文本、Switch / Slider / Picker 的值，或 `accessibilityValue`。 */
  value?: JsonValue;
  /** 元素 props 中可序列化的部分（函数和 React 元素会被去掉）。 */
  props: Record<string, JsonValue>;
}
```

### `Rect`

```ts theme={null}
/** 矩形，使用平台的逻辑单位（Android 为 dp，iOS 为 pt，web 为 CSS px），窗口坐标。 */
interface Rect {
  x: number;
  y: number;
  width: number;
  height: number;
}
```

### `TreeNode`

```ts theme={null}
interface TreeNode {
  type: string;
  testID?: string;
  text?: string;
  role?: string;
  semanticType?: SemanticType;
  /** 取整后的矩形。 */
  rect?: Rect;
  children: TreeNode[];
}
```

### `TrackerState`

```ts theme={null}
/** 一个空闲 tracker 的状态。 */
interface TrackerState {
  name: string;
  idle: boolean;
  /** 可读的忙碌原因，例如 `GET https://api.example.com/todos (1200ms)`。 */
  busy: string[];
  /** frame-stable 只在调用等待期间采样，因此同步超时后它会报告空闲：这里是最近一次等待空闲结束时元素树仍在变化的忙碌原因。 */
  lastWait?: string[];
  /** 在 SYNC_TIMEOUT 中：该 tracker 在超时时已空闲，但在此之前的这么多毫秒内处于忙碌，`busy` 是当时忙碌的原因。 */
  idleForMs?: number;
}
```

### `TrackerName`

```ts theme={null}
type TrackerName = 'network' | 'timer' | 'react' | 'idle-callback' | 'frame-stable' | 'native' | 'native-module';
```

## 坐标点

### `Point`

```ts theme={null}
/** 一个点：元素自身坐标（`point`）或窗口坐标（`tapAt`），逻辑单位。 */
interface Point {
  x: number;
  y: number;
}
```

### `TimedPoint`

```ts theme={null}
/** 手指在某一时刻的位置：距手势开始的毫秒数。 */
interface TimedPoint {
  x: number;
  y: number;
  t: number;
}
```

## 调用选项

### `CallOptions`

```ts theme={null}
/** 每个 Driver 调用都接受的选项。 */
interface CallOptions {
  /** 单次调用的超时（agent 端）。默认：`sync.timeoutMs`。 */
  timeoutMs?: number;
  /** `false`：本次调用前后不等待空闲（无限循环的动画等）。 */
  sync?: boolean;
}
```

### `ActionOptions`

```ts theme={null}
interface ActionOptions extends CallOptions {
  mode?: ActionMode;
}
```

### `TapOptions`

```ts theme={null}
/** `tap()` 的选项。 */
interface TapOptions extends ActionOptions {
  /** 触摸位置，使用元素自身坐标（默认：元素中心）。 */
  point?: Point;
}
```

### `LongPressOptions`

```ts theme={null}
/** `longPress()` 的选项。 */
interface LongPressOptions extends ActionOptions {
  /** 按住多久（默认 800 ms）。 */
  durationMs?: number;
  /** 触摸位置，使用元素自身坐标（默认：元素中心）。 */
  point?: Point;
}
```

### `LongPressAtOptions`

```ts theme={null}
/** `longPressAt()` 的选项。 */
interface LongPressAtOptions extends ActionOptions {
  /** 按住多久（默认 800 ms）。 */
  durationMs?: number;
}
```

### `TypeOptions`

```ts theme={null}
/** `type()` 的选项。 */
interface TypeOptions extends ActionOptions {
  /** 像用户一样一次输入一个字符，让 App 看到每一次按键（防抖搜索、输入掩码、`onKeyPress`）。默认：一次输入全部文本。 */
  perCharacter?: boolean;
  /** 配合 `perCharacter`：两个字符之间的间隔（默认 80 ms）。调用结束时会等待空闲。 */
  intervalMs?: number;
}
```

### `ScrollOptions`

```ts theme={null}
/** `scroll()` 的选项。 */
interface ScrollOptions extends ActionOptions {
  /** 滚动距离，逻辑单位。 */
  distance?: number;
  /** 手指在元素内的起点，按 0–1 归一化（默认：中心附近）。 */
  from?: Point;
}
```

### `ScrollToIndexOptions`

```ts theme={null}
/** `scrollToIndex()` 的选项。 */
interface ScrollToIndexOptions extends ActionOptions {
  /** 列表项最终所在的位置：0 顶部，0.5 中间，1 底部（FlatList 的 `viewPosition`）。 */
  viewPosition?: number;
}
```

### `SwipeOptions`

```ts theme={null}
/** `swipe()` 的选项。 */
interface SwipeOptions extends ActionOptions {
  speed?: Speed;
  /** 滑动距离，逻辑单位。 */
  distance?: number;
  /** 手指在元素内的起点，按 0–1 归一化（默认：中心附近）。 */
  from?: Point;
}
```

### `DragOptions`

```ts theme={null}
/** `drag()` 的选项。 */
interface DragOptions extends ActionOptions {
  /** 移动前按住多久（默认 800 ms：足以触发长按拖动）。 */
  holdMs?: number;
  speed?: Speed;
}
```

### `PinchOptions`

```ts theme={null}
/** `pinch()` 的选项。 */
interface PinchOptions extends ActionOptions {
  /** 手指移动所在直线的角度，弧度（默认 0：水平）。 */
  angle?: number;
  speed?: Speed;
}
```

### `RotateOptions`

```ts theme={null}
/** `rotate()` 的选项。 */
interface RotateOptions extends ActionOptions {
  speed?: Speed;
}
```

### `MultiTouchOptions`

```ts theme={null}
/** `multiTouch()` 的选项。 */
interface MultiTouchOptions extends ActionOptions {
  /** 坐标点使用该元素自身的坐标（元素必须可见），而不是窗口坐标。 */
  within?: MatcherInput;
}
```

### `VisibleOptions`

```ts theme={null}
interface VisibleOptions extends CallOptions {
  /** 元素面积的最小可见比例，0–1（Detox 的 `toBeVisible(75)` 即 `{ ratio: 0.75 }`）。 */
  ratio?: number;
}
```

### `WaitForIdleOptions`

```ts theme={null}
/** `waitForIdle()` 的选项。 */
interface WaitForIdleOptions {
  /** 等待多久。默认：`sync.timeoutMs`。 */
  timeoutMs?: number;
}
```

## 设备

### `RelaunchOptions`

```ts theme={null}
interface RelaunchOptions {
  /** 启动参数（任意 JSON），合并在配置的 `launchArgs` 之上；用 `quiesco.launchArgs()` 读取。 */
  args?: LaunchArgs;
  /** 用这个深层链接打开 App（例如 `myapp://todos/1`；web 上打开其路径）。 */
  url?: string;
  /** 先删除 App 的数据（原生：App 的存储；web：全新的浏览器上下文）。 */
  clearData?: boolean;
  /** 先卸载再安装 App（需要 App 的 `binaryPath`；web：同 clearData）。 */
  reinstall?: boolean;
  /** 启动前授予的权限，配置中的权限之外。 */
  permissions?: Permission[];
}
```

### `StatusBarOptions`

```ts theme={null}
/** 用于干净截图的状态栏覆盖；未设置的字段保持真实值。 */
interface StatusBarOptions {
  /** 时钟，`H:MM` / `HH:MM`（例如 `9:41`）。 */
  time?: string;
  /** 0–100。 */
  batteryLevel?: number;
  charging?: boolean;
  /** Wi-Fi 信号，0–3 格。 */
  wifiBars?: number;
  /** 蜂窝信号，0–4 格。 */
  cellularBars?: number;
  /** 信号格旁显示的数据网络；`hide` 隐藏蜂窝指示。 */
  dataNetwork?: 'wifi' | '3g' | '4g' | 'lte' | '5g' | 'hide';
}
```

### `NotificationSpec`

```ts theme={null}
/** 用于 `app.device.sendNotification()` 的通知。 */
interface NotificationSpec {
  title: string;
  body?: string;
  /** 自定义数据：iOS 放在推送 payload 中 `aps` 的旁边，Android 放进启动 intent 的 extras。 */
  data?: Record<string, string>;
}
```

### `OpenNotificationOptions`

```ts theme={null}
/** `app.device.openNotification()` 的选项。 */
interface OpenNotificationOptions {
  /** 等待通知发出的时间（默认 10000 ms）。 */
  timeoutMs?: number;
}
```

### `SystemQuery`

```ts theme={null}
/** 文本（完全一致或 RegExp）和 / 或 id（完整 id，或 `:id/` 之后的部分）。 */
interface SystemQuery {
  text?: string | RegExp;
  id?: string;
}
```

### `SystemWaitOptions`

```ts theme={null}
interface SystemWaitOptions {
  /** 等待系统 UI 出现（或消失）的时间。默认 10 s。 */
  timeoutMs?: number;
}
```

### `ScreenshotTarget`

```ts theme={null}
/** `app.device.screenshot` 截取的对象：一个元素，或用 `fullPage` 截取滚动视图的全部内容（`true`：屏幕上的滚动视图）。 */
type ScreenshotTarget = MatcherInput | { fullPage: true | MatcherInput };
```

### `ScreenshotOptions`

```ts theme={null}
/** `app.device.screenshot()` 的选项。 */
interface ScreenshotOptions {
  /** 指定元素时：截取元素的全部，滚动并拼接（默认 false）。 */
  full?: boolean;
  /** 同时以这个名字把 PNG 保存到场景的 artifacts 中。 */
  name?: string;
}
```

## WebView

### `WebElementQuery`

```ts theme={null}
/** 测试中书写的 WebView 定位器：`{ text }` 也接受 RegExp。 */
type WebElementQuery = ({ css: string } | { xpath: string } | { id: string } | { text: TextQuery }) & { index?: number };
```

### `PageElement`

```ts theme={null}
interface PageElement {
  tag: string;
  id: string;
  text: string;
  value: string | null;
  visible: boolean;
  disabled: boolean;
  /** 页面的 CSS 像素，相对于其视口。 */
  rect: { x: number; y: number; width: number; height: number };
}
```

## JSON

### `JsonValue`

```ts theme={null}
type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };
```

### `JsonPrimitive`

```ts theme={null}
/** 经过 JSON.stringify / JSON.parse 后保持不变的任意值。 */
type JsonPrimitive = string | number | boolean | null;
```

## App 内

### `WithQuiescoOptions`

```ts theme={null}
/** `withQuiesco()` 的选项。 */
type WithQuiescoOptions = {
  enabled?: boolean;
  env?: NodeJS.ProcessEnv;
  projectRoot?: string;
  artifactsDir?: string | false;
  nativeModules?: boolean;
  argv?: readonly string[];
};
```

### `Backdoor`

```ts theme={null}
/** 后门：host 可以调用的仅供测试使用的函数。参数和返回值必须可 JSON 序列化。 */
type Backdoor = (...args: never[]) => unknown;
```

### `StorageAdapter`

```ts theme={null}
/** 在软重置时清空一个持久化存储（AsyncStorage、MMKV、SecureStore …）。 */
interface StorageAdapter {
  name: string;
  clear(): void | Promise<void>;
}
```

## Runner

### `QuiescoVitestOptions`

```ts theme={null}
interface QuiescoVitestOptions {
  /** quiesco.config 中重命名了标签时的标签名（即那里的 `tags`）。 */
  tags?: Partial<TagNames>;
  /** 默认 300 s（第一个测试包含启动 session 的时间）。 */
  testTimeout?: number;
  /** 要额外声明的自定义标签，例如 `['@smoke']`。 */
  extraTags?: readonly string[];
  /** 并行 worker 数，每个 worker 使用自己的设备。默认 1（串行）。 */
  workers?: number;
}
```

### `RegisterOptions`

```ts theme={null}
interface RegisterOptions extends LifecycleOptions {
  /** 使用自己的 World（必须继承 QuiescoWorld）。默认 QuiescoWorld。这里是普通的构造函数类型，而不是 `typeof QuiescoWorld`：后者对 world 参数是泛型的，任何子类都无法满足。 */
  world?: new (options: IWorldOptions<any>) => QuiescoWorld<any>;
  /** 默认的 step 超时。每次 driver 调用有自己的同步超时；这个值限制整个 step。默认 60 s。 */
  stepTimeoutMs?: number;
  /** BeforeAll 的超时：启动模拟器可能需要几分钟。默认 10 min。 */
  setupTimeoutMs?: number;
  /** 每个场景的重置（Before）的超时。App 不在时会重新启动它，最多等待连接超时的 3 倍。默认 3 min。 */
  resetTimeoutMs?: number;
}
```

### `LifecycleOptions`

```ts theme={null}
interface LifecycleOptions {
  /** 使用这个配置，而不是加载 `quiesco.config.*`（QUIESCO_CONFIG 可指定其他文件）。 */
  config?: QuiescoConfig;
  /** 使用这个平台，而不是 QUIESCO_PLATFORM。 */
  platform?: Platform;
  /** Session 工厂（测试、自定义环境）。 */
  createSession?: (options: SessionOptions) => Promise<Session>;
  env?: NodeJS.ProcessEnv;
  /** 该 lifecycle 所在的并行 worker，由 runner 适配器传入：配置函数会收到它，session 使用它自己的设备、端口和 artifacts 目录。默认：唯一的 worker。 */
  worker?: WorkerInfo;
  /** 重复失败提示的输出位置。默认：控制台。 */
  logger?: Logger;
}
```

### `ScenarioTags`

```ts theme={null}
/** 场景的标签：一个扁平列表（单层），或按 Gherkin 层级分组，最外层在前（feature、rule、scenario、examples）。 */
type ScenarioTags = readonly string[] | readonly (readonly string[])[];
```

### `ScenarioResult`

```ts theme={null}
interface ScenarioResult {
  tags: readonly string[];
  failed: boolean;
  /** 失败原因（Error，或 runner 的消息），用于区分重复的相同失败。 */
  error?: unknown;
}
```

### `AfterResult`

```ts theme={null}
interface AfterResult {
  /** 给支持附件的 runner：截图、元素树、日志 … */
  attachments: Attachment[];
  /** 为该测试写入的文件（证据、日志、视频）：不支持附件的 runner 会打印它们。 */
  files: string[];
}
```

### `Attachment`

```ts theme={null}
interface Attachment {
  data: Buffer | string;
  mediaType: string;
  /** 由会为附件命名的 reporter 显示。 */
  fileName?: string;
}
```

### `SessionOptions`

```ts theme={null}
interface SessionOptions {
  config: QuiescoConfig;
  platform: Platform;
  logger?: Logger;
  /** 替换设备 provider（测试、自定义 provider）。 */
  provider?: DeviceProvider;
  /** 该 session 所属的并行测试 worker：它自己的设备、服务器端口（`server.port + index`）和 artifacts 目录。默认：唯一的 worker。 */
  worker?: WorkerInfo;
  /** 等待 App 重新连接期间检查其进程的间隔。默认 500 ms。 */
  crashPollMs?: number;
}
```

### `WorkerInfo`

```ts theme={null}
/** provider 所服务的并行测试 worker；每个 worker 需要自己的设备。 */
interface WorkerInfo {
  /** worker 的序号，从 0 开始。 */
  index: number;
  /** 本次运行的 worker 数（串行运行时为 1）。 */
  count: number;
}
```

### `ScenarioInfo`

```ts theme={null}
interface ScenarioInfo {
  tags?: readonly string[];
  /** 场景名：它的 artifacts 目录。 */
  name?: string;
}
```

### `ScenarioArtifacts`

```ts theme={null}
interface ScenarioArtifacts {
  /** 给报告用：截图、日志和时间线摘要内联；视频 / trace 以路径给出。 */
  attachments: Attachment[];
  /** 为该场景写入的文件。 */
  files: string[];
}
```

### `Evidence`

```ts theme={null}
interface Evidence {
  screenshot?: Buffer;
  tree?: TreeNode | null;
  /** 精简的元素列表和路由。 */
  elements?: ResultOf<AgentMethods['listElements']>;
  idle?: TrackerState[];
  /** 某一项无法收集的原因。 */
  errors: string[];
  /** App 崩溃了：不收集元素树、列表和空闲状态。 */
  crash?: QuiescoError;
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.