android_uiautomator_dump
Extract the UI hierarchy from Android devices as XML to analyze screen elements and structure for automated testing or accessibility purposes.
Instructions
Dump the UI hierarchy using UIAutomator and return as XML
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceSerial | No | Specific device serial number to target (optional) |
Implementation Reference
- src/handlers.ts:260-280 (handler)The main handler function that executes the android_uiautomator_dump tool logic. It extracts deviceSerial from args, calls adb.getUIHierarchyXml to dump the UI hierarchy, and returns the XML as text content.export async function uiautomatorDumpHandler( adb: ADBWrapper, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { const { deviceSerial } = args as UIAutomatorDumpArgs; try { const xml = await adb.getUIHierarchyXml(deviceSerial); return { content: [ { type: 'text', text: xml, }, ], }; } catch (error) { throw new Error(`UIAutomator dump failed: ${error instanceof Error ? error.message : String(error)}`); } }
- src/adb-wrapper.ts:519-528 (helper)Core helper method in ADBWrapper that performs the UIAutomator dump: runs 'uiautomator dump' via ADB shell, reads the XML file, cleans up, and returns the hierarchy XML string.async getUIHierarchyXml(deviceSerial?: string): Promise<string> { const device = await this.getTargetDevice(deviceSerial); const hierarchyFile = '/sdcard/window_dump.xml'; await this.exec(['shell', 'uiautomator', 'dump', hierarchyFile], device); const { stdout } = await this.exec(['shell', 'cat', hierarchyFile], device); await this.exec(['shell', 'rm', hierarchyFile], device); return stdout; }
- src/index.ts:156-167 (schema)Tool schema definition in the ListTools response, including name, description, and inputSchema for optional deviceSerial.name: 'android_uiautomator_dump', description: 'Dump the UI hierarchy using UIAutomator and return as XML', inputSchema: { type: 'object', properties: { deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, }, },
- src/index.ts:474-475 (registration)Tool registration in the CallToolRequestSchema switch statement, dispatching to the uiautomatorDumpHandler function.case 'android_uiautomator_dump': return await uiautomatorDumpHandler(this.adb, args);