Documentation for the --visual flag which uses Chrome DevTools MCP for interactive visual testing.
The --visual flag enables browser-based testing using Chrome DevTools MCP tools. This provides real browser verification, accessibility snapshots, and visual regression testing.
# Visual test with Chrome DevTools
/testgen src/pages/Login.tsx --visual
# Combined with E2E type
/testgen src/components/Form.tsx --type e2e --visual
Detects Chrome DevTools MCP availability via mcp__chrome_devtools__* tools
For each component/page:
mcp__chrome_devtools__navigate_pagemcp__chrome_devtools__take_snapshotmcp__chrome_devtools__take_screenshotmcp__chrome_devtools__click, mcp__chrome_devtools__fillGenerates test documentation with:
| Tool | Purpose |
|---|---|
navigate_page |
Load component in browser |
take_snapshot |
Get accessibility tree for element refs |
take_screenshot |
Capture visual state |
click |
Test interactive elements |
fill |
Test form inputs |
list_console_messages |
Capture JS errors |
list_network_requests |
Verify API calls |
performance_start_trace |
Performance profiling |
| Scenario | Recommended |
|---|---|
| Component styling verification | Yes |
| Form interaction testing | Yes |
| Accessibility compliance | Yes |
| Unit testing pure functions | No |
| API integration tests | No |
## Visual Test Results: LoginForm
### Accessibility Snapshot
- Form: role="form", aria-label="Login"
- Email input: role="textbox", name="email"
- Password input: role="textbox", name="password" (masked)
- Submit button: role="button", name="Log in"
### Screenshot
Captured: login-form-baseline.png
### Interactive Tests
- [PASS] Email field accepts input
- [PASS] Password field masks characters
- [PASS] Submit button triggers form validation
- [PASS] Error state displays for invalid email
### Console Errors
None detected
### Suggested Playwright Tests
[Generated code based on visual analysis]
When the mcp__claude-in-chrome__* tools are available, --visual can also use:
| Tool | Purpose |
|---|---|
read_page |
Get comprehensive accessibility tree |
find |
Locate elements by natural language |
computer |
Simulate real user interactions |
get_page_text |
Extract text content |
# Check for Chrome DevTools MCP
if available(mcp__chrome_devtools__take_snapshot); then
echo "Chrome DevTools available - enabling visual testing"
fi
# Check for Claude-in-Chrome
if available(mcp__claude-in-chrome__read_page); then
echo "Claude-in-Chrome available - enabling enhanced visual testing"
fi
If Chrome DevTools is not available, --visual gracefully degrades:
Chrome DevTools MCP → Claude-in-Chrome → Playwright → Cypress → Manual testing
Combine coverage analysis with visual testing:
/testgen src/components/ --coverage --visual
This identifies untested visual states and generates tests for them.
Generate visual regression tests for UI issues found by /review:
/testgen --from-review --visual
When --visual is used, the following artifacts may be created:
| Artifact | Location | Purpose |
|---|---|---|
| Screenshots | tests/__screenshots__/ |
Visual regression baselines |
| Accessibility snapshots | tests/__a11y__/ |
A11y tree for comparison |
| Generated tests | tests/visual/ |
Playwright/Cypress test files |
Visual tests can be run in CI with Chrome:
# GitHub Actions example
- name: Visual Tests
run: |
npx playwright test --project=chromium
env:
CI: true
For Chrome DevTools MCP in CI, ensure the browser is launched in headless mode with remote debugging enabled.