detox_generate_action
Generate Detox mobile testing actions like tap, type, scroll, and swipe for React Native E2E automation.
Instructions
Generate Detox action code (tap, typeText, scroll, etc.).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| actionType | Yes | Type of action | |
| elementMatcher | Yes | Matcher code or description | |
| actionParams | No |
Implementation Reference
- src/tools/index.ts:384-402 (handler)The complete tool object definition for 'detox_generate_action', including its handler function that parses input arguments and generates Detox action code using the generateActionCode helper.export const generateActionTool: Tool = { name: "detox_generate_action", description: "Generate Detox action code (tap, typeText, scroll, etc.).", inputSchema: zodToJsonSchema(GenerateActionArgsSchema), handler: async (args: z.infer<typeof GenerateActionArgsSchema>) => { const parsed = GenerateActionArgsSchema.parse(args); const code = generateActionCode({ actionType: parsed.actionType, elementMatcher: parsed.elementMatcher, params: parsed.actionParams, }); return { success: true, code, }; }, };
- src/utils/validators.ts:110-139 (schema)Zod schema defining the input parameters for the detox_generate_action tool, used for validation and JSON schema conversion.export const GenerateActionArgsSchema = z.object({ actionType: z .enum([ "tap", "multiTap", "longPress", "typeText", "replaceText", "clearText", "scroll", "scrollTo", "swipe", "pinch", ]) .describe("Type of action"), elementMatcher: z.string().describe("Matcher code or description"), actionParams: z .object({ text: z.string().optional(), times: z.number().optional(), duration: z.number().optional(), direction: z.enum(["up", "down", "left", "right"]).optional(), speed: z.enum(["fast", "slow"]).optional(), offset: z.number().optional(), edge: z.enum(["top", "bottom", "left", "right"]).optional(), }) .optional(), }); export type GenerateActionArgs = z.infer<typeof GenerateActionArgsSchema>;
- src/tools/index.ts:429-442 (registration)The allTools array exports all MCP tools, registering 'detox_generate_action' (via generateActionTool) for use in the protocol.export const allTools: Tool[] = [ buildTool, testTool, initTool, readConfigTool, listConfigurationsTool, validateConfigTool, createConfigTool, listDevicesTool, generateTestTool, generateMatcherTool, generateActionTool, generateExpectationTool, ];
- Core helper function generateActionCode that generates the specific Detox action code snippet invoked by the tool handler.export function generateActionCode(options: { actionType: | "tap" | "multiTap" | "longPress" | "typeText" | "replaceText" | "clearText" | "scroll" | "scrollTo" | "swipe" | "pinch"; elementMatcher: string; params?: { text?: string; times?: number; duration?: number; direction?: "up" | "down" | "left" | "right"; speed?: "fast" | "slow"; offset?: number; edge?: "top" | "bottom" | "left" | "right"; point?: { x: number; y: number }; }; }): string { const element = options.elementMatcher; const p = options.params || {}; switch (options.actionType) { case "tap": if (p.point) { return `await ${element}.tap({ x: ${p.point.x}, y: ${p.point.y} });`; } return `await ${element}.tap();`; case "multiTap": return `await ${element}.multiTap(${p.times || 2});`; case "longPress": if (p.duration) { return `await ${element}.longPress(${p.duration});`; } return `await ${element}.longPress();`; case "typeText": return `await ${element}.typeText('${p.text || ""}');`; case "replaceText": return `await ${element}.replaceText('${p.text || ""}');`; case "clearText": return `await ${element}.clearText();`; case "scroll": const scrollOffset = p.offset || 200; const scrollDir = p.direction || "down"; return `await ${element}.scroll(${scrollOffset}, '${scrollDir}');`; case "scrollTo": const edge = p.edge || "bottom"; return `await ${element}.scrollTo('${edge}');`; case "swipe": const swipeDir = p.direction || "up"; const speed = p.speed || "fast"; return `await ${element}.swipe('${swipeDir}', '${speed}');`; case "pinch": const scale = p.offset || 2; return `await ${element}.pinch(${scale});`; default: return `await ${element}.tap();`; } }