Automation API

Android device automation

Getting Started

Create your first automation project and learn the IDE

Creating a New Project

To create a new automation project:

  1. Make sure you are logged in
  2. Navigate to MY ACCOUNT -> AUTOMATIONS in your dashboard
  3. Click the New Automation button
  4. Enter a project name and optional description
  5. Click Create Project

Your project will be created with a default main.ts file as the entry point. This is where your automation code will start executing.

The IDE

The automation IDE provides a full development environment with:

Code Editor

Full TypeScript support with syntax highlighting, autocomplete, and error checking. The editor automatically compiles TypeScript to JavaScript on save.

File Explorer

Manage your project files and folders. Create, rename, and delete files. Organize your code across multiple TypeScript files with ES6 imports.

Git Integration

Built-in version control with commit history, diff viewer, and revert functionality. Track changes and roll back to previous versions when needed.

Options Panel

Configure automation parameters, job variables, requirements, and sharing settings. See the Configuration page for details.

Project Structure

A typical automation project structure:

Project Structure
Text
my-automation/
├── main.ts # Entry point (required)
├── stages.ts # Stage enum definitions
├── screenStates.ts # Screen state enum
├── detection.ts # Screen detection logic
├── handlers.ts # Stage handlers
└── utils.ts # Shared utilities

You can organize your code however you like, but this structure works well for most automations. The entry point is always main.ts.

Your First Automation

Here's a simple automation that launches an app and takes a screenshot:

main.ts
TypeScript
// Simple automation example
const PACKAGE_NAME = "com.example.myapp";
async function main() {
try {
// Launch the app
await agent.actions.launchApp(PACKAGE_NAME);
// Wait for app to load
await sleep(3000);
// Get screen content
const screen = await agent.actions.screenContent();
// Find all text on screen
const allNodes = getAllNodes(screen);
const textNodes = allNodes.filter(node => node.text);
console.log("Found text nodes:", textNodes.length);
// Take a screenshot
const screenshot = await agent.actions.screenshot(1080, 1920, 80);
console.log("Screenshot taken!");
// Submit success
await agent.utils.job.submitTask("success", {
textNodesFound: textNodes.length
});
} catch (error) {
console.error("Automation failed:", error);
await agent.utils.job.submitTask("failed", { error: String(error) });
} finally {
// Always stop the automation
stopCurrentAutomation();
}
}
// Helper function for delays
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Start the automation
main();

Keyboard Shortcuts

ShortcutAction
Ctrl/Cmd + SSave current file
Ctrl/Cmd + SpaceTrigger autocomplete
Ctrl/Cmd + /Toggle line comment
Ctrl/Cmd + FFind in file

TypeScript Compilation

When you save a .ts file, it's automatically compiled to JavaScript. The compiled .js file is what actually runs on the device.

Compilation Errors

If your TypeScript has errors, they'll be displayed when you save. Fix the errors and save again to update the compiled JavaScript.

ES6 Imports

Organize your code across multiple files using ES6 imports:

stages.ts
TypeScript
// Export enum from stages.ts
export enum Stage {
Initialize = "Initialize",
LaunchApp = "LaunchApp",
ProcessData = "ProcessData",
Complete = "Complete",
}
main.ts
TypeScript
// Import in main.ts
import { Stage } from "./stages.js";
let currentStage = Stage.Initialize;
// Use the imported enum
if (currentStage === Stage.Initialize) {
// ...
}

Import Extension

Always use .js extension in imports, even when importing from .ts files. This is because the runtime executes the compiled JavaScript.

Next Steps