Skip to Content

/moai e2e

A command that creates and runs E2E (End-to-End) tests using browser automation tools.

One-line summary: /moai e2e is a “User Journey Tester”. It selects the optimal tool from 3 browser automation options to automatically test user flows.

Slash Command: Type /moai:e2e in Claude Code to run this command directly. Type /moai alone to see the full list of available subcommands.

Overview

E2E tests verify that your application works correctly from the actual user’s perspective. /moai e2e supports 3 browser automation tools and automatically selects the best one for your project environment.

It automatically discovers user journeys, generates test scripts, executes them, and reports results. GIF recording enables visual verification.

Usage

# Run E2E tests with auto tool selection > /moai e2e # Specify Playwright > /moai e2e --tool playwright # Include GIF recording > /moai e2e --record # Target specific URL > /moai e2e --url http://localhost:3000 # Run specific user journey only > /moai e2e --journey login # Disable headless mode (for debugging) > /moai e2e --headless false

Supported Flags

FlagDescriptionExample
--tool TOOLForce browser tool selection (agent-browser, playwright, chrome-mcp)/moai e2e --tool playwright
--recordRecord browser interactions as GIF/moai e2e --record
--url URLTarget URL (default: auto-detect from project config)/moai e2e --url http://localhost:3000
--journey NAMERun specific named user journey only/moai e2e --journey login
--headlessHeadless mode (default: true)/moai e2e --headless false
--browser BROWSERBrowser for Playwright (chromium, firefox, webkit)/moai e2e --browser firefox
--timeout NTest timeout in seconds (default: 30)/moai e2e --timeout 60
--retry NRetry count for failed tests (default: 1)/moai e2e --retry 3

Browser Automation Tools

Tool Comparison

FeatureAgent BrowserPlaywright CLIClaude in Chrome
Token CostLow (CLI output)Low (CLI output)High (MCP round-trips)
Setupnpm installnpx playwright installChrome extension required
HeadlessYesYesNo (requires visible Chrome)
Cross-BrowserChromium onlyChromium, Firefox, WebKitChrome only
GIF RecordingVia Playwright traceVia Playwright traceVia MCP GIF creator
AI NavigationBuilt-in AI agentScript-basedMCP tool-based
Best ForAI-driven explorationDeterministic test suitesInteractive debugging
CI/CDYesYesNo

Auto-Selection Logic

When --tool flag is not specified, the optimal tool is auto-selected based on task characteristics:

ConditionSelected ToolRationale
--record flag usedClaude in ChromeBest GIF recording capability
CI/CD environment detectedPlaywright CLIMost reliable headless support
Journey requires AI explorationAgent BrowserBuilt-in AI navigation
Deterministic tests neededPlaywright CLIMost stable, cross-browser
Interactive debuggingClaude in ChromeReal-time visual feedback
DefaultPlaywright CLIBest balance of features and token efficiency

Execution Process

/moai e2e runs in 5 phases (+ installation phase).

Phase 0: Tool Selection & Installation

Checks installation status of all 3 tools in parallel:

# Auto-detection commands (parallel execution) npx agent-browser --version # Agent Browser npx playwright --version # Playwright # Check Chrome MCP tool availability # Claude in Chrome

If installation is needed:

ToolInstallation Command
Playwrightnpx playwright install --with-deps chromium
Agent Browsernpm install -g agent-browser
Claude in ChromeChrome extension install (not auto-installable)

Phase 1: Journey Mapping

Without --journey flag, analyzes the application to auto-discover key user journeys:

  • Analyze project documentation (.moai/project/product.md)
  • Analyze route definitions (routes.ts, urls.py, router.go)
  • Identify form elements, auth flows, and CRUD operations
  • Map critical user paths (login, main features, error handling)

Phase 2: Test Script Creation

Generates test files matching the selected tool:

ToolTest File FormatLocation
Playwright{journey-name}.spec.tse2e/
Agent Browser{journey-name}.agent.tse2e/
Claude in ChromeStructured MCP promptsIn-memory

Playwright tests include:

  • Page Object Model pattern
  • Step-by-step assertions
  • Screenshot capture
  • Network response validation
  • Accessibility checks (@axe-core/playwright)

Phase 3: Test Execution

ToolExecution Method
Playwrightnpx playwright test e2e/ (CLI, token-efficient)
Agent Browsernpx agent-browser --task "..." (CLI, AI navigation)
Claude in ChromeMCP tool calls (real-time, high token cost)

Phase 4: Recording (Optional)

When --record flag is used:

ToolRecording MethodOutput
Playwrightnpx playwright test --trace one2e/traces/
Agent Browsernpx agent-browser --task "..." --tracee2e/recordings/
Claude in Chromemcp__claude-in-chrome__gif_creatore2e/recordings/{journey}.gif

Phase 5: Report

## E2E Test Report ### Tool Used: Playwright CLI ### Results Summary | Journey | Status | Duration | Screenshots | |---------|--------|----------|-------------| | Login | PASS | 2.3s | 3 captured | | Checkout | FAIL | 5.1s | 4 captured | ### Failures - Checkout (Step 4): Expected redirect to /confirmation, got /error - Screenshot: e2e/screenshots/checkout-step4.png - Error: TimeoutError: Navigation timeout of 30000ms exceeded ### Recordings (if --record) - e2e/recordings/login_flow.gif - e2e/recordings/checkout_process.gif ### Coverage - User journeys tested: 5/7 - Critical paths covered: 3/3 - Error scenarios tested: 2/4

Agent Delegation Chain

Agent Roles:

AgentRoleKey Tasks
MoAI OrchestratorWorkflow coordination, user interactionReport output, next step guidance
expert-testingTool detection, journey mapping, script creation, executionFull E2E test pipeline
expert-frontendChrome MCP execution (Chrome mode only)Browser automation, GIF recording

FAQ

Q: Which tool should I choose?

Playwright CLI is the best choice for most cases. It offers CI/CD support, cross-browser testing, and low token cost. Use Agent Browser for AI-based exploration, or Claude in Chrome for visual debugging.

Q: Can it be used in CI/CD pipelines?

Playwright CLI and Agent Browser support CI/CD. Claude in Chrome requires a real Chrome browser and cannot be used in CI/CD.

Q: What’s the token cost of GIF recording?

Playwright/Agent Browser use CLI traces with no additional token cost. Claude in Chrome’s GIF recording has higher token costs due to MCP round-trips.

Q: What happens if existing E2E tests exist?

Existing tests are detected and new tests are added following existing patterns. Existing tests are never overwritten.

Last updated on