( runtime: AgentDeviceRuntime, options: WaitCommandOptions, selectorExpression: string, timeoutMs: number | null | undefined, )
| 457 | } |
| 458 | |
| 459 | async function waitForSelector( |
| 460 | runtime: AgentDeviceRuntime, |
| 461 | options: WaitCommandOptions, |
| 462 | selectorExpression: string, |
| 463 | timeoutMs: number | null | undefined, |
| 464 | ): Promise<WaitCommandResult> { |
| 465 | const timeout = timeoutMs ?? DEFAULT_TIMEOUT_MS; |
| 466 | const start = now(runtime); |
| 467 | const chain = parseSelectorChain(selectorExpression); |
| 468 | while (now(runtime) - start < timeout) { |
| 469 | const capture = await captureSelectorSnapshot(runtime, options, { updateSession: true }); |
| 470 | const match = findSelectorChainMatch(capture.snapshot.nodes, chain, { |
| 471 | platform: runtime.backend.platform, |
| 472 | }); |
| 473 | if (match) |
| 474 | return { kind: 'selector', selector: match.selector.raw, waitedMs: now(runtime) - start }; |
| 475 | await sleep(runtime, POLL_INTERVAL_MS); |
| 476 | } |
| 477 | throw new AppError('COMMAND_FAILED', `wait timed out for selector: ${selectorExpression}`); |
| 478 | } |
| 479 | |
| 480 | async function waitForText( |
| 481 | runtime: AgentDeviceRuntime, |
no test coverage detected