Skip to main content
Glama
andreahaku
by andreahaku

ui.wait_for

Wait for UI elements to appear or become visible in iOS Simulator during React Native/Expo testing, ensuring reliable automation by specifying selectors and timeout settings.

Instructions

Wait for an element to be visible or exist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesElement selector to wait for.
visibleNoWait for visibility (true) or existence (false).
timeoutNoTimeout in milliseconds.

Implementation Reference

  • Primary handler for the 'ui.wait_for' MCP tool. Generates a Detox snippet using generateWaitForSnippet and executes it with runDetoxAction, returning the result in MCP format.
    server.tool( "ui.wait_for", "Wait for an element to be visible or exist", UiWaitForInputSchema.shape, async (args) => { try { const snippet = generateWaitForSnippet({ selector: args.selector, visible: args.visible, timeout: args.timeout, }); const result = await runDetoxAction({ actionName: `waitFor:${describeSelector(args.selector)}`, actionSnippet: snippet, timeoutMs: (args.timeout ?? 30000) + 5000, // Add buffer }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (error) { return handleToolError(error); } } );
  • Input schema (Zod) for the ui.wait_for tool, defining selector, visible flag, and timeout.
    export const UiWaitForInputSchema = z.object({ selector: SelectorSchema.describe("Element selector to wait for."), visible: z.boolean().optional().default(true).describe("Wait for visibility (true) or existence (false)."), timeout: z.number().optional().default(30000).describe("Timeout in milliseconds."), });
  • Internal helper implementation of ui.wait_for logic used by the flow.run tool executor.
    case "ui.wait_for": const waitSnippet = generateWaitForSnippet({ selector: input.selector as { by: "id" | "text" | "label"; value: string }, visible: input.visible as boolean | undefined, timeout: input.timeout as number | undefined, }); const waitResult = await runDetoxAction({ actionName: `waitFor:${(input.selector as { value: string }).value}`, actionSnippet: waitSnippet, }); return { success: waitResult.success, result: waitResult, error: waitResult.error?.message };
  • Helper function that generates the actual Detox JavaScript code snippet for waiting on an element (visible or exists). This is the core UI waiting logic.
    export function generateWaitForSnippet(options: WaitForOptions): string { const matcher = selectorToDetoxExpr(options.selector); const timeout = options.timeout ?? 30000; if (options.visible !== false) { return `await waitFor(element(${matcher})).toBeVisible().withTimeout(${timeout});`; } return `await waitFor(element(${matcher})).toExist().withTimeout(${timeout});`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/andreahaku/expo_ios_development_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server