Skip to main content
Glama

detox_generate_matcher

Generate Detox matcher code for selecting mobile app elements by ID, text, label, type, or traits in React Native E2E testing.

Instructions

Generate Detox matcher code for element selection (by.id, by.text, etc.).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementDescriptionYesDescription of the element to match
matcherTypeNo
withAncestorNoAncestor matcher
withDescendantNoDescendant matcher
atIndexNoIndex for multiple matches

Implementation Reference

  • The handler function that executes the detox_generate_matcher tool: parses input args, calls generateMatcherCode helper, and returns the generated code.
    handler: async (args: z.infer<typeof GenerateMatcherArgsSchema>) => { const parsed = GenerateMatcherArgsSchema.parse(args); const code = generateMatcherCode({ type: parsed.matcherType || "id", value: parsed.elementDescription, withAncestor: parsed.withAncestor, withDescendant: parsed.withDescendant, atIndex: parsed.atIndex, }); return { success: true, code, description: `Matcher for: ${parsed.elementDescription}`, }; },
  • Zod schema defining the input parameters for the detox_generate_matcher tool.
    export const GenerateMatcherArgsSchema = z.object({ elementDescription: z.string().describe("Description of the element to match"), matcherType: z.enum(["id", "text", "label", "type", "traits"]).optional(), withAncestor: z.string().optional().describe("Ancestor matcher"), withDescendant: z.string().optional().describe("Descendant matcher"), atIndex: z.number().optional().describe("Index for multiple matches"), });
  • Core helper function that constructs the Detox matcher code string based on type, value, and optional modifiers like ancestor, descendant, and index.
    export function generateMatcherCode(options: { type: "id" | "text" | "label" | "type" | "traits"; value: string; withAncestor?: string; withDescendant?: string; atIndex?: number; }): string { let matcher: string; switch (options.type) { case "id": matcher = `by.id('${options.value}')`; break; case "text": matcher = `by.text('${options.value}')`; break; case "label": matcher = `by.label('${options.value}')`; break; case "type": matcher = `by.type('${options.value}')`; break; case "traits": matcher = `by.traits(['${options.value}'])`; break; default: matcher = `by.id('${options.value}')`; } if (options.withAncestor) { matcher = `${matcher}.withAncestor(by.id('${options.withAncestor}'))`; } if (options.withDescendant) { matcher = `${matcher}.withDescendant(by.id('${options.withDescendant}'))`; } let code = `element(${matcher})`; if (options.atIndex !== undefined) { code = `element(${matcher}).atIndex(${options.atIndex})`; } return code; }
  • Registration of the detox_generate_matcher tool (as generateMatcherTool) in the allTools array exported for use in the MCP server.
    export const allTools: Tool[] = [ buildTool, testTool, initTool, readConfigTool, listConfigurationsTool, validateConfigTool, createConfigTool, listDevicesTool, generateTestTool, generateMatcherTool, generateActionTool, generateExpectationTool, ];

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