shake
Simulate device shaking for mobile testing on Android or iOS platforms, controlling duration and intensity parameters for automation scenarios.
Instructions
Shake the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration | No | Duration of the shake in milliseconds (default: 1000) | |
| intensity | No | Intensity of the shake acceleration (default: 100) | |
| platform | Yes | Platform of the device |
Implementation Reference
- src/server/interactionTools.ts:764-769 (registration)Registration of the 'shake' tool with ToolRegistry, linking schema and handler."shake", "Shake the device", shakeSchema, shakeHandler, true // Supports progress notifications );
- src/server/interactionTools.ts:583-599 (handler)Tool handler function that instantiates Shake class and executes it with provided arguments.const shakeHandler = async (device: BootedDevice, args: ShakeArgs, progress?: ProgressCallback) => { try { const shake = new Shake(device); const result = await shake.execute({ duration: args.duration ?? 1000, intensity: args.intensity ?? 100 }, progress); return createJSONToolResponse({ message: `Shook device for ${args.duration ?? 1000}ms with intensity ${args.intensity ?? 100}`, observation: result.observation, ...result }); } catch (error) { throw new ActionableError(`Failed to shake device: ${error}`); } };
- Zod schema for validating 'shake' tool input arguments.export const shakeSchema = z.object({ duration: z.number().optional().describe("Duration of the shake in milliseconds (default: 1000)"), intensity: z.number().optional().describe("Intensity of the shake acceleration (default: 100)"), platform: z.enum(["android", "ios"]).describe("Platform of the device") });
- src/features/action/Shake.ts:12-57 (handler)Core implementation of shake: sets emulator sensor acceleration to simulate device shake.async execute( options: ShakeOptions = {}, progress?: ProgressCallback ): Promise<ShakeResult> { const duration = options.duration ?? 1000; // Default 1 second const intensity = options.intensity ?? 100; // Default intensity of 100 return this.observedInteraction( async () => { try { // Start the shake by setting high acceleration values await this.adb.executeCommand(`emu sensor set acceleration ${intensity}:${intensity}:${intensity}`); logger.info(`Started shake with intensity ${intensity} for ${duration}ms`); // Wait for the specified duration await new Promise(resolve => setTimeout(resolve, duration)); // Stop the shake by resetting acceleration to 0 await this.adb.executeCommand(`emu sensor set acceleration 0:0:0`); logger.info("Shake completed"); return { success: true, duration, intensity }; } catch (error) { logger.error(`Failed to execute shake: ${error}`); return { success: false, duration, intensity, error: `Failed to shake device: ${error}` }; } }, { changeExpected: false, // Shake typically doesn't change UI directly timeoutMs: duration + 2000, // Give extra time beyond shake duration tolerancePercent: 0.00, progress } ); }
- src/models/ShakeOptions.ts:1-16 (schema)TypeScript interface defining input options for the Shake operation./** * Options for performing a shake operation */ export interface ShakeOptions { /** * Duration of the shake in milliseconds (default: 1000ms) */ duration?: number; /** * Intensity of the shake acceleration (default: 100) * Higher values create more intense shaking */ intensity?: number; }