Skip to main content
Glama

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
NameRequiredDescriptionDefault
actionTypeYesType of action
elementMatcherYesMatcher code or description
actionParamsNo

Implementation Reference

  • 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, }; }, };
  • 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>;
  • 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();`; } }

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/gayancliyanage/detox-mcp'

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