Browsertest
Run, create, debug, and maintain browser tests
---
description: Run, create, debug, and maintain browser tests
allowed-tools: Read, Write, Edit, Grep, Glob, Bash, Task, TaskOutput, AskUserQuestion
argument-hint: '<run|debug|maintain|report|create> [feature] [description]'
category: testing
---
# Browser Test Command
You are managing DorkOS browser tests. Parse `$ARGUMENTS` and route to the appropriate action.
## Routing Logic
Parse the first word of `$ARGUMENTS`:
### `run [feature]`
Execute browser tests.
```bash
# Run all tests
cd apps/e2e && npx playwright test
# Run specific feature
cd apps/e2e && npx playwright test tests/<feature>/
After running, read apps/e2e/manifest.json and display a results summary.
create <feature> <description>
Create a new browser test using a 5-phase explore-first loop. Never guess selectors — discover them by navigating like a real user.
Pre-Flight
- Read
apps/e2e/manifest.json— check if a similar test already exists. If it does, confirm with the user before overwriting. - Read
apps/e2e/GOTCHAS.md— absorb known anti-patterns before writing anything. - Check manifest for
explorationNoteson related tests — build on prior knowledge. - Read
apps/e2e/pages/for existing POMs that may already cover needed interactions.
Phase 1: EXPLORE
Navigate the feature step-by-step as a real user would. At each meaningful state change:
mcp__playwright__browser_navigatetohttp://localhost:6241(or the relevant page)mcp__playwright__browser_snapshotto capture the accessibility tree- Document: element roles, names, testids, hierarchy, loading indicators, conditional rendering
- Note timing: what loads immediately, what appears after an SSE event or API call, what animates
Continue until you have observed every state the test needs to assert against. Stay within the scope of <description> — don't explore unrelated features.
Phase 2: WRITE
Using only the selectors discovered in Phase 1:
- Create or update POMs in
apps/e2e/pages/with the explored locators. PrefergetByRole()→data-testid→ text. Never use CSS classes. - Register new POMs in
apps/e2e/fixtures/index.ts. - Write the
.spec.tsfile inapps/e2e/tests/<feature>/using custom fixtures from../../fixtures. - Follow the patterns in
.claude/skills/browser-testing/SKILL.md.
Phase 3: RUN & OBSERVE
cd apps/e2e && npx playwright test tests/<feature>/<new-test>.spec.ts
- If it passes → proceed to Phase 4.
- If it fails (max 3 iterations):
- Read the error message and identify the failing step.
- Use
mcp__playwright__browser_navigate+mcp__playwright__browser_snapshotto inspect the actual page state at the point of failure. - Diagnose: wrong selector? timing issue? unexpected UI state?
- Fix the spec or POM, then re-run.
- If still failing after 3 iterations → use
AskUserQuestionto present the diagnosis and ask for guidance.
Phase 4: STABILIZE
Run the test 3 consecutive times:
cd apps/e2e && npx playwright test tests/<feature>/<new-test>.spec.ts --repeat-each=3
- 3/3 pass → proceed to Phase 5.
- Any failure → diagnose the flaky step (usually a timing issue), fix, then re-run Phase 3 once. If still flaky after that, ask the user.
Phase 5: RECORD
- Write
explorationNotesto the test entry inapps/e2e/manifest.json— document selectors, timing observations, and gotchas specific to this feature. - If you discovered any new anti-patterns, append them to
apps/e2e/GOTCHAS.mdunder the appropriate category. - Display a summary: test name, phases completed, iterations needed, key observations.
debug <test-name>
Debug a failing test:
- Run the test with JSON output:
cd apps/e2e && npx playwright test tests/**/<test-name>.spec.ts --reporter=json 2>&1 - Parse the error message and failure location
- Use Playwright MCP to navigate to the page where the test fails
- Use
mcp__playwright__browser_snapshotto capture the current accessibility tree - Compare the snapshot with what the test expects (locators, text content, element visibility)
- Classify the failure:
- TEST bug (selector changed, timing issue, new UI pattern): Auto-fix the spec or POM, re-run, verify
- CODE bug (regression, broken feature): Present diagnosis and fix options via AskUserQuestion
- Update manifest.json with the debug session results
maintain
Delegate to the maintain command:
Read and follow the instructions in .claude/commands/browsertest:maintain.md
report
Display a health dashboard from manifest data:
- Read
apps/e2e/manifest.json - Calculate aggregate statistics
- Display formatted report:
Browser Test Health Dashboard
==============================
Suite Status: <N> tests | <N> passing | <N> failing | <N>% pass rate
Last Run: <timestamp> (<duration>ms)
Feature Breakdown:
<feature>: <passed>/<total> passing (<percent>%)
...
Recent History (last 5 runs):
#<N>: <passed>/<total> passed (<duration>ms)
...
No recognized subcommand (default)
Treat the arguments as a feature search:
- Read
apps/e2e/manifest.json - Search for a test matching the arguments (fuzzy match on test key, feature, or description)
- If found: Run the matching test
- If not found: Offer to create a new test using the
createflow above
Key Principles
- Always import
testandexpectfrom../../fixtures, never from@playwright/testdirectly - Use Page Object Models for all interactions
- Tag tests:
@smokefor fast critical path,@integrationfor SDK-dependent - Never use
page.waitForTimeout()— use locator state waits - Auto-fix test bugs; ask the user before making code changes
Maintain Browsertest?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Browsertest on getagentictools](https://getagentictools.com/loops/dork-labs-browser-test-command?ref=badge)