ui.scroll
Scroll within scrollable elements in iOS Simulator for React Native/Expo apps. Specify direction and element selector to navigate UI during testing.
Instructions
Scroll within a scrollable element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | Scrollable element selector. | |
| direction | Yes | Scroll direction. | |
| amount | No | Scroll amount in pixels. |
Implementation Reference
- src/mcp/server.ts:538-566 (registration)Registration of the 'ui.scroll' MCP tool, including the inline handler function that generates a Detox scroll code snippet using generateScrollSnippet and executes it via runDetoxAction.server.tool( "ui.scroll", "Scroll within a scrollable element", UiScrollInputSchema.shape, async (args) => { try { const snippet = generateScrollSnippet({ selector: args.selector, direction: args.direction, amount: args.amount, }); const result = await runDetoxAction({ actionName: `scroll:${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/server.ts:542-565 (handler)Handler function for 'ui.scroll' tool: validates input via schema, generates Detox scroll snippet, executes via runDetoxAction, returns result or error.async (args) => { try { const snippet = generateScrollSnippet({ selector: args.selector, direction: args.direction, amount: args.amount, }); const result = await runDetoxAction({ actionName: `scroll:${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:70-74 (schema)Zod input schema for 'ui.scroll' tool defining selector, direction (up/down/left/right), and optional scroll amount (pixels).export const UiScrollInputSchema = z.object({ selector: SelectorSchema.describe("Scrollable element selector."), direction: DirectionSchema.describe("Scroll direction."), amount: z.number().optional().default(200).describe("Scroll amount in pixels."), });
- src/detox/actions.ts:50-65 (helper)Helper function generateScrollSnippet that creates the Detox JavaScript code for scrolling a scrollable element by amount pixels in the specified direction from relative start position.export interface ScrollOptions { selector: Selector; direction: Direction; amount?: number; startPositionX?: number; startPositionY?: number; } export function generateScrollSnippet(options: ScrollOptions): string { const el = buildElementExpr(options.selector); const amount = options.amount ?? 200; const startX = options.startPositionX ?? 0.5; const startY = options.startPositionY ?? 0.5; return `await ${el}.scroll(${amount}, '${options.direction}', ${startX}, ${startY});`; }