This guide gets you from zero to running AI-generated Playwright tests against your UI.
Add data-ai-id attributes to the elements you want to test:
<input data-ai-id="email" data-ai-role="input" data-ai-label="Email address" />
<input data-ai-id="password" data-ai-role="input" data-ai-label="Password" />
<button data-ai-id="submit" data-ai-role="action" data-ai-label="Sign in">Sign in</button>The SDK also auto-discovers untagged inputs, buttons, and links — tagging is optional but gives Claude better context for generating accurate tests.
Available attributes: see sdk-reference.md.
<script src="path/to/ai-sdk.js"></script>const aiSdk = require('@phantomui/sdk');
const snapshot = aiSdk.getSnapshot({ root: document });import { useAiSnapshot } from '@phantomui/sdk/adapters/react';
function MyApp() {
const { snapshot, refresh, isReady } = useAiSnapshot();
// snapshot.elements contains all tagged + auto-tagged UI elements
}import { useAiSnapshot, AiSdkPlugin } from '@phantomui/sdk/adapters/vue';
// Option A: Composition API composable
const { snapshot, refresh } = useAiSnapshot();
// Option B: Plugin (adds this.$aiSdk to every component)
app.use(AiSdkPlugin);import { AiSdkService } from '@phantomui/sdk/adapters/angular';
// Add to providers, then inject:
constructor(private aiSdk: AiSdkService) {}
ngOnInit() { this.snapshot = this.aiSdk.getSnapshot(); }See sdk-reference.md for full adapter API docs.
cd server
npm install
npm run buildAdd to Claude Code (stdio transport):
claude mcp add --transport stdio phantomui node /absolute/path/to/server/dist/index.jsOr add to ~/.claude/claude_desktop_config.json for Claude Desktop:
{
"mcpServers": {
"phantomui": {
"command": "node",
"args": ["/absolute/path/to/server/dist/index.js"]
}
}
}Open Claude and try:
Take a snapshot of http://localhost:3000/login and generate test scenarios.
Then run the login scenario and save an HTML report to ./reports/login.html
Claude will automatically:
- Call
get_ui_snapshotto discover your UI elements - Call
generate_teststo create Playwright scenarios - Call
run_testto execute them - Call
save_reportto write the report
# Open the HTML report in your browser
start reports/login.html # Windows
open reports/login.html # macOS
xdg-open reports/login.html # LinuxStart as a REST API + local dashboard server:
node dist/index.js --port 3100Then open http://localhost:3100 in your browser for the full dashboard UI (snapshot capture, element grid, test run history, one-click report export). For the raw API, see http-api.md and mcp-tools.md.
PhantomUI supports multiple LLM backends. The server auto-detects which provider to use based on environment variables — no code changes required.
export ANTHROPIC_API_KEY=sk-ant-...
# Optionally override the model:
export AI_MODEL=claude-opus-4-6Run tests entirely offline using a local Ollama instance. No API key needed.
# Install Ollama: https://ollama.ai
ollama pull llama3.1
export LLM_PROVIDER=ollama
export OLLAMA_MODEL=llama3.1 # default: llama3.1
export OLLAMA_BASE_URL=http://localhost:11434 # defaultWorks with OpenAI, Azure OpenAI, Together AI, Groq, or any OpenAI-compatible endpoint.
export LLM_PROVIDER=openai-compatible
export OPENAI_COMPATIBLE_BASE_URL=https://api.openai.com/v1
export OPENAI_COMPATIBLE_API_KEY=sk-...
export OPENAI_COMPATIBLE_MODEL=gpt-4o # default: gpt-4oIf LLM_PROVIDER is not set, the server picks a provider automatically:
ANTHROPIC_API_KEYis set → use Anthropic ClaudeOPENAI_COMPATIBLE_BASE_URLis set → use OpenAI-compatible- Neither → fall back to local Ollama (
http://localhost:11434)