ui.swipe
Simulate swipe gestures on iOS app elements for UI testing and automation. Specify direction, speed, and distance to interact with React Native/Expo interfaces in the simulator.
Instructions
Swipe on an element in a direction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | Element selector to swipe on. | |
| direction | Yes | Swipe direction. | |
| speed | No | Swipe speed. | fast |
| percentage | No | Swipe distance as percentage of element. |
Implementation Reference
- src/mcp/server.ts:507-536 (registration)Registration of the 'ui.swipe' MCP tool, including inline handler that generates a Detox swipe snippet and executes it via runDetoxActionserver.tool( "ui.swipe", "Swipe on an element in a direction", UiSwipeInputSchema.shape, async (args) => { try { const snippet = generateSwipeSnippet({ selector: args.selector, direction: args.direction, speed: args.speed, percentage: args.percentage, }); const result = await runDetoxAction({ actionName: `swipe:${args.direction}:${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:63-68 (schema)Zod schema for ui.swipe tool input validation, including selector, direction, speed, and percentage parametersexport const UiSwipeInputSchema = z.object({ selector: SelectorSchema.describe("Element selector to swipe on."), direction: DirectionSchema.describe("Swipe direction."), speed: z.enum(["fast", "slow"]).optional().default("fast").describe("Swipe speed."), percentage: z.number().min(0).max(1).optional().default(0.75).describe("Swipe distance as percentage of element."), });
- src/detox/actions.ts:34-48 (helper)Helper function generateSwipeSnippet that creates the Detox JavaScript code snippet for performing a swipe action on an elementexport interface SwipeOptions { selector: Selector; direction: Direction; speed?: "fast" | "slow"; percentage?: number; } export function generateSwipeSnippet(options: SwipeOptions): string { const el = buildElementExpr(options.selector); const speed = options.speed ?? "fast"; const percentage = options.percentage ?? 0.75; const normalizedPercentage = Math.round(percentage * 100) / 100; return `await ${el}.swipe('${options.direction}', '${speed}', ${normalizedPercentage});`; }