ui.long_press
Perform long press interactions on iOS Simulator UI elements for React Native/Expo app testing. Simulate user gestures by pressing elements for specified durations to test touch interactions and accessibility features.
Instructions
Long press on an element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | Element selector. | |
| duration | No | Press duration in milliseconds. |
Implementation Reference
- src/mcp/server.ts:478-505 (handler)Primary handler and registration for the 'ui.long_press' MCP tool. Generates a Detox action snippet and executes it via runDetoxAction.server.tool( "ui.long_press", "Long press on an element", UiLongPressInputSchema.shape, async (args) => { try { const snippet = generateLongPressSnippet({ selector: args.selector, duration: args.duration, }); const result = await runDetoxAction({ actionName: `longPress:${describeSelector(args.selector)}`, actionSnippet: snippet, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (error) { return handleToolError(error); } } );
- src/mcp/schemas.ts:58-61 (schema)Zod input schema for ui.long_press tool parameters: selector and optional duration.export const UiLongPressInputSchema = z.object({ selector: SelectorSchema.describe("Element selector."), duration: z.number().optional().default(1000).describe("Press duration in milliseconds."), });
- src/detox/actions.ts:23-32 (helper)Helper function that generates the Detox JavaScript snippet for performing a long press action on an element.export interface LongPressOptions { selector: Selector; duration?: number; } export function generateLongPressSnippet(options: LongPressOptions): string { const el = buildElementExpr(options.selector); const duration = options.duration ?? 1000; return `await ${el}.longPress(${duration});`; }
- src/detox/selectors.ts:30-36 (helper)Helper to build Detox element expression from MCP selector, used in snippet generation.export function buildElementExpr(selector: Selector, index?: number): string { const matcher = selectorToDetoxExpr(selector); if (index !== undefined) { return `element(${matcher}).atIndex(${index})`; } return `element(${matcher})`; }
- src/detox/selectors.ts:23-25 (helper)Helper to create a human-readable description of the selector for action names.export function describeSelector(selector: Selector): string { return `${selector.by}="${selector.value}"`; }