option

Runs adversarial UI tests in a real browser using the browse CLI, analyzing git diffs to test only changed areas or exploring the full app to find bugs in functionality, accessibility, responsive layout, and UX.

...Expand all
0
Updated time September 29, 2026

UI Test — Agentic UI Testing Skill

Test UI changes in a real browser. Your job is to try to break things, not confirm they work.

Three workflows:

  • Diff-driven — analyze a git diff, test only what changed
  • Exploratory — navigate the app, find bugs the developer didn't think about
  • Parallel — fan out independent test groups across multiple Browserbase browsers

How Testing Works

The main agent coordinates — it plans test strategy, delegates to sub-agents, and merges results. Sub-agents do the actual browser testing.

Planning: multiple angles, then execute once

You MUST complete all three planning rounds yourself and output them before launching any sub-agents. Planning happens in your own response — it is NOT delegated to sub-agents. Do not skip ahead to execution.

Round 1 — Functional: What are the core user flows? What should work? Write out each test as: action → expected result.

Round 2 — Adversarial: Re-read Round 1. What did you miss? Think about: different user types/roles, error paths, empty states, race conditions, edge inputs (empty, huge, special chars, rapid clicks).

Round 3 — Coverage gaps: Re-read Rounds 1–2. What about: accessibility (axe-core, keyboard-only), mobile viewports, console errors, visual consistency with the rest of the app?

Deduplicate: Merge all three rounds into one numbered list of tests. Remove overlaps. Assign each test to a group (e.g. Group A, Group B).

Then execute once — launch one sub-agent per group. Each sub-agent receives its specific list of tests to run, nothing more. Sub-agents do not explore or plan — they execute assigned tests and report results.

Output the three rounds, the merged plan, and the group assignments in your response before calling any Agent tool.

Principles for splitting work

  • Sub-agents run assigned tests, not open exploration. The main agent hands each sub-agent a specific numbered list of tests. Sub-agents do not plan, explore, or decide what to test — they execute the list and stop.
  • The bottleneck is the slowest agent — split work so no single agent has a disproportionate share. Many small agents > few large ones.
  • Size the effort to the change — a single component fix doesn't need many agents or many steps. A full-page redesign does. Let the scope of the diff drive the plan.
  • No early stopping on failures — find as many bugs as possible within the assigned tests.

Giving sub-agents a step budget

The main agent MUST include an explicit browse step limit in every sub-agent prompt. Sub-agents do not self-limit — they will run until done unless told otherwise.

As a rough heuristic: ~25 steps for a few targeted checks, ~40 for a full page with functional + adversarial + a11y, ~75 for multiple pages or a broad category. Adjust based on what the assigned tests actually require — these are starting points, not rules.

As a rough heuristic: ~25 steps for a few targeted checks, ~40 for a full page with functional + adversarial + a11y, ~75 for multiple pages or a broad category. Adjust based on what the assigned tests actually require — these are starting points, not rules.

Every sub-agent prompt must include:

You have a budget of N browse steps (each `browse` command = 1 step). Count your steps as you go. When you reach N, stop immediately and report:
- STEP_PASS/STEP_FAIL for every test you completed
- STEP_SKIP||budget reached for every test you didn't get to

Do not retry or continue after hitting the budget.
Run only these tests: [numbered list from the merged plan]
Do not explore beyond the assigned tests.
Do NOT generate an HTML report or write any files. Return only step markers and your findings as text.

The main agent should NOT run browse commands itself (except to verify the dev server is up). All testing happens in sub-agents.

When a sub-agent hits its budget, the main agent accepts the partial results as-is. Do not re-run or retry the sub-agent. Include SKIPPED tests in the final report so the developer knows what wasn't covered.

Reporting

Every sub-agent reports back with:

Tests: 8 | Passed: 5 | Failed: 2 | Skipped: 1 | Pages visited: 2

The main agent merges into a final report with:

Tests: 20 | Passed: 14 | Failed: 4 | Skipped: 2 | Agents: 3 | Pass rate: 70%

Do not report "steps used" — browse command counts are implementation plumbing, not a meaningful metric for reviewers.

Testing Philosophy

You are an adversarial tester. Your goal is to find bugs, not prove correctness.

  • Try to break every feature you test. Don't just check "does the button exist?" — click it twice rapidly, submit empty forms, paste 500 characters, press Escape mid-flow.
  • Test what the developer didn't think about. Empty states, error recovery, keyboard-only navigation, mobile overflow.
  • Every assertion must be evidence-based. Compare before/after snapshots. Check specific elements by ref. Never report PASS without concrete evidence from the accessibility tree or a deterministic check.
  • Report failures with enough detail to reproduce. Include the exact action, what you expected, what you got, and a suggested fix.

Assertion Protocol

Every test step MUST produce a structured assertion. Do not write freeform "this looks good."

Step markers

For each test step, emit exactly one marker:

STEP_PASS||

or

STEP_FAIL|| → |
  • step-id: short identifier like homepage-cta, form-validation-error, modal-cancel
  • evidence: what you observed that proves the step passed (element ref, text content, URL, eval result)
  • expected → actual: what you expected vs what you got
  • screenshot-path: path to the saved screenshot (failures only — see Screenshot Capture below)

Screenshot Capture for Failures

Every STEP_FAIL MUST have an accompanying screenshot so the developer can see what went wrong visually.

When a test step fails:

# 1. Take a screenshot immediately after observing the failure
browse screenshot --path .context/ui-test-screenshots/.png

# If --path is not supported, take the screenshot and save manually:
browse screenshot
# The browse CLI will output the screenshot path — move/copy it:
cp /tmp/browse-screenshot-*.png .context/ui-test-screenshots/.png

Setup the screenshot directory at the start of any test run:

mkdir -p .context/ui-test-screenshots

Rules:

  • File name = step-id (e.g., double-submit.png, axe-audit.png, modal-focus-trap.png)
  • Store in .context/ui-test-screenshots/ — this directory is gitignored and accessible to the developer and other agents
  • For parallel runs, include the session name: -.png (e.g., signup-double-submit.png)
  • Take the screenshot at the moment of failure — capture the broken state, not after recovery
  • For visual/layout bugs, also screenshot the baseline (working state) for comparison: -baseline.png

How to verify (in order of rigor)

  1. Deterministic check (strongest) — browse eval returns structured data you can inspect. Examples: axe-core violation count, document.title, form field value, console error array, element count.
  2. Snapshot element match — a specific element with a specific role and text exists in the accessibility tree. Check by ref: @0-12 button "Save". An element either exists in the tree or it doesn't.
  3. Before/after comparison — snapshot before action, act, snapshot after. Verify the tree changed in the expected way (element appeared, disappeared, text changed).
  4. Screenshot + visual judgment (weakest) — only for visual-only properties (color, spacing, layout) that the accessibility tree cannot capture. Always accompany with what specifically you're evaluating.

Before/after comparison pattern

This is the core verification loop. Use it for every interaction:

# 1. BEFORE: capture state
browse snapshot
# Record: what elements exist, their text, their refs

# 2. ACT: perform the interaction
browse click @0-12

# 3. AFTER: capture new state
browse snapshot
# Compare: what changed? What appeared? What disappeared?

# 4. ASSERT: emit marker based on comparison
# If dialog appeared: STEP_PASS|modal-open|dialog "Confirm" appeared at @0-20
# If nothing changed:
browse screenshot --path .context/ui-test-screenshots/modal-open.png
# STEP_FAIL|modal-open|expected dialog to appear → snapshot unchanged|.context/ui-test-screenshots/modal-open.png

Setup

which browse || npm install -g browse

Avoid permission fatigue

This skill runs many browse commands (snapshots, clicks, evals). To avoid approving each one, add browse to your allowed commands:

Add both patterns to .claude/settings.json (project-level) or ~/.claude/settings.json (user-level):

{
  "permissions": {
    "allow": [
      "Bash(browse:*)",
      "Bash(BROWSE_SESSION=*)"
    ]
  }
}

The first pattern covers plain browse commands. The second covers parallel sessions (BROWSE_SESSION=signup browse open ...). Both are needed to avoid approval prompts.

Mode Selection

Target Mode Command Auth
localhost / 127.0.0.1 Local browse open --local None needed (clean isolated local browser by default)
Deployed/staging site Remote browse open --remote Browserbase credentials; use contexts where supported

Rule: If the target URL contains localhost or 127.0.0.1, pass --local on the first browse open.

Local Mode (default for localhost)

browse open http://localhost:3000 --local

browse open ... --local uses a clean isolated local browser by default, which is best for reproducible localhost QA runs.

Use local-mode variants only when needed:

  • browse open --auto-connect — auto-discover an existing debuggable local Chrome. Use this only when the test explicitly needs existing local login/cookies/state.
  • browse open --cdp — attach to a specific CDP target (explicit local browser attach).

Remote Mode (deployed sites via cookie-sync)

# Step 1: Sync cookies from local Chrome to Browserbase
node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains your-app.com
# Output: Context ID: ctx_abc123

# Step 2: Open in remote mode with the synced context
SESSION_JSON="$(browse cloud sessions create --context-id ctx_abc123 --persist --keep-alive)"
SESSION_ID="$(echo "$SESSION_JSON" | jq -r .id)"
CONNECT_URL="$(echo "$SESSION_JSON" | jq -r .connectUrl)"

browse open https://staging.your-app.com --cdp "$CONNECT_URL"
browse snapshot
# ... run tests ...
browse stop
browse cloud sessions update "$SESSION_ID" --status REQUEST_RELEASE

Cookie-sync flags: --domains, --context, --verified, --proxy "City,ST,US"

Workflow A: Diff-Driven Testing

Phase 1: Analyze the diff

git diff --name-only HEAD~1          # or: git diff --name-only / git diff --name-only main...HEAD
git diff HEAD~1 --             # read actual changes

Categorize changed files:

File pattern UI impact What to test
*.tsx, *.jsx, *.vue, *.svelte Component Render, interaction, state, edge cases
pages/**, app/**, src/routes/** Route/page Navigation, page load, content, 404 handling
*.css, *.scss, *.module.css Style Visual appearance (screenshot), responsive
*form*, *input*, *field* Form Validation, submission, empty input, long input, special chars
*modal*, *dialog*, *dropdown* Interactive Open/close, escape, focus trap, cancel vs confirm
*nav*, *menu*, *header* Navigation Links, active states, routing, keyboard nav
Non-UI files only None Skip — report "no UI tests needed"

Phase 2: Map files to URLs

Detect framework: cat package.json | grep -E '"(next|react|vue|nuxt|svelte|@sveltejs|angular|vite)"'

Framework Default port File → URL pattern
Next.js App Router 3000 app/dashboard/page.tsx → /dashboard
Next.js Pages Router 3000 pages/about.tsx → /about
Vite 5173 Check router config
Nuxt 3000 pages/index.vue → /
SvelteKit 5173 src/routes/+page.svelte → /
Angular 4200 Check routing module

Phase 3: Ensure the right code is running

Before testing, verify the dev server is serving the code from the diff — not a stale branch.

If testing a PR or specific branch:

# Check what branch is currently checked out
git branch --show-current

# If it's not the PR branch, switch to it
git fetch origin  && git checkout 

# Install deps — the lockfile may differ between branches
yarn install  # or npm install / pnpm install

If the dev server was already running on a different branch, restart it after checkout.

Find a running dev server:

for port in 3000 3001 5173 4200 8080 8000 5000; do
  s=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$port" 2>/dev/null)
  if [ "$s" != "000" ]; then echo "Dev server on port $port (HTTP $s)"; fi
done

If nothing found: tell the user to start their dev server.

Verify it actually renders: After browse open + browse snapshot, check that the accessibility tree contains real page content (navigation, headings, interactive elements) — not just an error overlay or empty body. Next.js dev servers can return HTTP 200 while showing a full-screen build error dialog. If the snapshot is empty or dominated by an error dialog, the server is broken — fix the build before testing.

Phase 4: Generate test plan

For each changed area, plan both happy path AND adversarial tests:

Test Plan (based on git diff)
=============================
Changed: src/components/SignupForm.tsx (added email validation)

1. [happy] Valid email submits successfully
   URL: http://localhost:3000/signup
   Steps: fill valid email → submit → verify success message appears

2. [adversarial] Invalid email shows error
   Steps: fill "not-an-email" → submit → verify error message appears

3. [adversarial] Empty form submission
   Steps: click submit without filling anything → verify error, no crash

4. [adversarial] XSS in email field
   Steps: fill "" → submit → verify sanitized/rejected

5. [adversarial] Rapid double-submit
   Steps: click submit twice quickly → verify no duplicate submission

6. [adversarial] Keyboard-only flow
   Steps: Tab to email → type → Tab to submit → Enter → verify success

Phase 5: Execute tests

browse stop 2>/dev/null
mkdir -p .context/ui-test-screenshots
# localhost/default QA → clean, reproducible local run
browse open http://localhost:3000 --local

For each test, follow the before/after pattern:

# Navigate
browse open http://localhost:3000/path --local
browse wait load

# BEFORE snapshot
browse snapshot
# Note the current state: elements, refs, text

# ACT
browse click @0-ref
# or: browse fill "selector" "value"
# or: browse type "text"
# or: browse press Enter

# AFTER snapshot
browse snapshot
# Compare against BEFORE: what changed?

# ASSERT with marker
# STEP_PASS|step-id|evidence  OR  STEP_FAIL|step-id|expected → actual

Phase 6: Report results

## UI Test Results

### STEP_PASS|valid-email-submit|status "Thanks!" appeared at @0-42 after submit
- URL: http://localhost:3000/signup
- Before: form with email input @0-3, submit button @0-7
- Action: filled "[email protected]", clicked @0-7
- After: form replaced by status element with "Thanks! We'll be in touch."

### STEP_FAIL|double-submit|expected single submission → form submitted twice|.context/ui-test-screenshots/double-submit.png
- URL: http://localhost:3000/signup
- Before: form with submit button @0-7
- Action: clicked @0-7 twice rapidly
- After: two success toasts appeared, suggesting duplicate submission
- Screenshot: .context/ui-test-screenshots/double-submit.png
- Suggestion: disable submit button after first click, or debounce the handler

---
**Summary: 4/6 passed, 2 failed**
Failed: double-submit, xss-sanitization

Screenshots saved to `.context/ui-test-screenshots/` — open any failed step's screenshot to see the broken state.

Always browse stop when done.

Phase 7: Generate HTML report

After producing the text report, generate a standalone HTML report that a reviewer can open in a browser. The report embeds screenshots inline (base64) so it works as a single file — no external dependencies.

Why: Text reports are good for the agent conversation, but reviewers (PMs, designers, other engineers) want a visual artifact they can open, scan, and share. Screenshots inline make failures immediately obvious.

How to generate

  1. Read the HTML template at references/report-template.html
  2. Build the report by replacing the template placeholders with actual test data:
Placeholder Value
{{TITLE}} Report title for </code> tag (e.g., "UI Test: PR #1234 — OAuth Settings")</td> </tr> <tr> <td><code>{{TITLE_HTML}}</code></td> <td>Report title for the visible <code><h1></code>. If a PR URL is available, wrap the PR reference in an <code><a></code> tag so it's clickable (e.g., <code>UI Test: <a href="https://github.com/org/repo/pull/1234">PR #1234</a> — OAuth Settings</code>). If no URL, use plain text same as <code>{{TITLE}}</code>.</td> </tr> <tr> <td><code>{{META}}</code></td> <td>One-line context: date, app URL, user, branch</td> </tr> <tr> <td><code>{{TOTAL_TESTS}}</code></td> <td>Total STEP_PASS + STEP_FAIL count</td> </tr> <tr> <td><code>{{AGENT_COUNT}}</code></td> <td>Number of sub-agents that ran</td> </tr> <tr> <td><code>{{PASS_COUNT}}</code></td> <td>Number of STEP_PASS</td> </tr> <tr> <td><code>{{FAIL_COUNT}}</code></td> <td>Number of STEP_FAIL</td> </tr> <tr> <td><code>{{PASS_RATE}}</code></td> <td>Integer percentage (e.g., "92")</td> </tr> <tr> <td><code>{{RATE_CLASS}}</code></td> <td><code>good</code> (≥90%), <code>warn</code> (70–89%), <code>bad</code> (<70%)</td> </tr> <tr> <td><code>{{FAILURES_SECTION}}</code></td> <td>HTML for failed test cards (see below)</td> </tr> <tr> <td><code>{{PASSES_SECTION}}</code></td> <td>HTML for passed test cards (see below)</td> </tr> </tbody></table> <ol start="3"> <li>For each test result, generate a <code><details></code> card. Failed tests should be <strong>open by default</strong> so reviewers see them immediately:</li> </ol> <pre><code class="language-html"><!-- Failed test card (open by default) --> <div class="section"> <h2>Failures <span class="count">{{FAIL_COUNT}}</span></h2> <details class="test-card fail" open> <summary> <span class="badge fail">FAIL</span> <span class="step-id">step-id-here</span> <span class="evidence">expected → actual</span> </summary> <div class="body"> <dl> <dt>URL</dt><dd>http://localhost:3000/path</dd> <dt>Action</dt><dd>What was done</dd> <dt>Expected</dt><dd>What should have happened</dd> <dt>Actual</dt><dd>What happened instead</dd> </dl> <div class="suggestion">Fix: description of suggested fix</div> <div class="screenshot"> <img src="data:image/png;base64,..." alt="Screenshot of failure"> <div class="caption">step-id.png — captured at moment of failure</div> </div> </div> </details> </div> <!-- Passed test card (collapsed by default) --> <div class="section"> <h2>Passed <span class="count">{{PASS_COUNT}}</span></h2> <details class="test-card pass"> <summary> <span class="badge pass">PASS</span> <span class="step-id">step-id-here</span> <span class="evidence">evidence summary</span> </summary> <div class="body"> <dl> <dt>URL</dt><dd>http://localhost:3000/path</dd> <dt>Evidence</dt><dd>What was observed</dd> </dl> </div> </details> </div> </code></pre> <ol start="4"> <li><strong>Embed screenshots as base64</strong> so the HTML is fully self-contained:</li> </ol> <pre><code class="language-bash"># Convert screenshot to base64 data URI base64 -i .context/ui-test-screenshots/step-id.png | tr -d '\n' # Use as: src="data:image/png;base64,<output>" </code></pre> <p>Read each screenshot file referenced in STEP_FAIL markers, base64-encode it, and embed it as an <code><img src="data:image/png;base64,..."></code> in the corresponding test card. For STEP_PASS, only embed a screenshot if one was explicitly taken (e.g., baseline screenshots).</p> <ol start="5"> <li>Write the final HTML to <code>.context/ui-test-report.html</code>:</li> </ol> <pre><code class="language-bash"># Write the generated HTML cat > .context/ui-test-report.html << 'REPORT_EOF' <!DOCTYPE html> ...generated report... REPORT_EOF # Open it for the reviewer open .context/ui-test-report.html # macOS # xdg-open .context/ui-test-report.html # Linux </code></pre> <ol start="6"> <li>Tell the user: <code>Report saved to .context/ui-test-report.html</code> and offer to open it.</li> </ol> <p><strong>Rules:</strong></p> <ul> <li>Failures section comes before passes — reviewers care about what's broken first</li> <li>Failed cards are <code>open</code> by default; passed cards are collapsed</li> <li>Every STEP_FAIL card MUST have an embedded screenshot — if the screenshot file is missing, note it in the card</li> <li>Include the suggestion/fix in each failure card if one was provided</li> <li>The report must work offline — no CDN links, no external assets</li> <li>Keep the HTML under 5MB — if screenshots push it over, reduce image quality or skip baseline screenshots for passes</li> </ul> <h2>Adversarial Test Patterns</h2> <p>Apply these to every interactive element you test. Read references/adversarial-patterns.md for the full pattern library (forms, modals, navigation, error states, keyboard accessibility).</p> <h2>Deterministic Checks</h2> <p>These produce structured data, not judgment calls. Use them as the strongest form of assertion.</p> <table> <thead> <tr> <th>Check</th> <th>What it catches</th> <th>Assertion</th> </tr> </thead> <tbody><tr> <td>axe-core</td> <td>WCAG violations</td> <td><code>violations.length === 0</code></td> </tr> <tr> <td>Console errors</td> <td>Runtime exceptions, failed requests</td> <td>empty error array</td> </tr> <tr> <td>Broken images</td> <td>Missing/failed image loads</td> <td>no images with <code>naturalWidth === 0</code></td> </tr> <tr> <td>Form labels</td> <td>Inputs without accessible labels</td> <td>every input has <code>hasLabel: true</code></td> </tr> </tbody></table> <p>For the exact <code>browse eval</code> recipes, read references/browser-recipes.md.</p> <h2>Workflow B: Exploratory Testing</h2> <p>No diff, no plan — just open the app and try to break it. Use this when the user says "test my app", "find bugs", or "QA this site."</p> <h3>Approach</h3> <ol> <li><strong>Discover the app</strong> — read <code>package.json</code> to detect the framework, then open the root URL and snapshot to see what's there</li> <li><strong>Navigate everything</strong> — click through nav links, visit every reachable page, note what exists</li> <li><strong>Test what you find</strong> — for each page, apply the adversarial patterns below (forms, modals, navigation, keyboard, error states)</li> <li><strong>Run deterministic checks</strong> — axe-core, console errors, broken images, form labels on every page</li> <li><strong>Report findings</strong> — use STEP_PASS/STEP_FAIL markers, include reproduction steps for failures</li> </ol> <p>Don't try to be systematic about coverage. Just explore like a user would, but with the intent to break things. The agent is good at this — let it roam.</p> <h3>Tips for exploratory runs</h3> <ul> <li>Start with the homepage, then follow the navigation naturally</li> <li>Try the 404 page (<code>/does-not-exist</code>) — is it custom or default?</li> <li>Look for empty states (pages with no data)</li> <li>Test forms with garbage input before valid input</li> <li>Check mobile viewport (375px) on every page — does it overflow?</li> <li>If the app has auth, use cookie-sync first</li> </ul> <h2>Workflow C: Parallel Testing</h2> <p>Run independent test groups concurrently using named <code>browse</code> sessions (<code>BROWSE_SESSION=<name></code>). Each session gets its own browser. Works with both local and remote mode.</p> <p>Use when testing multiple pages or categories and you want faster wall clock time.</p> <p>Read references/parallel-testing.md for the full workflow: session setup, agent fan-out, cookie-sync for auth, and result merging.</p> <h2>Design Consistency</h2> <p>Check whether changed UI matches the rest of the app visually. Read references/design-consistency.md when doing visual or design checks.</p> <h2>Test Categories</h2> <table> <thead> <tr> <th>Category</th> <th>How</th> <th>Assertion type</th> </tr> </thead> <tbody><tr> <td>Accessibility</td> <td>axe-core + keyboard nav</td> <td>Deterministic (violation count)</td> </tr> <tr> <td>Visual Quality</td> <td>Screenshot + heuristic evaluation</td> <td>Visual judgment (weakest — note specifics)</td> </tr> <tr> <td>Responsive</td> <td>Viewport sweep + screenshots</td> <td>Visual + deterministic (overflow check)</td> </tr> <tr> <td>Console Health</td> <td>Console capture eval</td> <td>Deterministic (error count)</td> </tr> <tr> <td>UX Heuristics</td> <td>Snapshot + Laws of UX + Nielsen's</td> <td>Structured judgment (cite specific heuristic)</td> </tr> <tr> <td>Error States</td> <td>Navigate to empty/error states</td> <td>Before/after comparison</td> </tr> <tr> <td>Data Display</td> <td>Snapshot on tables/dashboards</td> <td>Element match (column count, formatting)</td> </tr> <tr> <td>Design Consistency</td> <td>Screenshot baseline + changed page comparison</td> <td>Visual judgment (cite specific property)</td> </tr> <tr> <td>Exploratory</td> <td>Free navigation + adversarial testing</td> <td>Before/after + judgment</td> </tr> </tbody></table> <p>Reference guides (load on demand):</p> <ul> <li><strong>Adversarial patterns</strong> — references/adversarial-patterns.md — load when testing forms, modals, navigation, or keyboard a11y</li> <li><strong>Browser recipes</strong> — references/browser-recipes.md — load when running deterministic checks (axe-core, console, images, form labels)</li> <li><strong>Exploratory testing</strong> — references/exploratory-testing.md — load for Workflow B (no diff, open exploration)</li> <li><strong>UX heuristics</strong> — references/ux-heuristics.md — load when evaluating UX quality or citing specific heuristics</li> <li><strong>Design system</strong> — references/design-system.example.md — template for users to customize</li> <li><strong>Design consistency</strong> — references/design-consistency.md — load when doing visual consistency checks</li> <li><strong>Parallel testing</strong> — references/parallel-testing.md — load for Workflow C (concurrent sessions)</li> <li><strong>Report template</strong> — references/report-template.html — HTML template for Phase 7 report generation</li> </ul> <p>For worked examples with exact commands, read EXAMPLES.md if you need to see the assertion protocol in action.</p> <h2>Best Practices</h2> <ol> <li><strong>Be adversarial</strong> — try to break things, don't just confirm they work</li> <li><strong>Every assertion needs evidence</strong> — snapshot ref, eval result, or before/after diff</li> <li><strong>Before/after for every interaction</strong> — snapshot, act, snapshot, compare</li> <li><strong>Screenshot every failure</strong> — <code>browse screenshot</code> immediately on STEP_FAIL, save to <code>.context/ui-test-screenshots/<step-id>.png</code></li> <li><strong>Deterministic checks first</strong> — axe-core, console errors, form labels before visual judgment</li> <li><strong>For localhost, start with clean local mode</strong> — pass <code>--local</code> on the first <code>browse open</code> for reproducible runs; use <code>--auto-connect</code> only when existing local state is required</li> <li><strong>Always <code>browse stop</code> when done</strong> — for parallel runs, stop every named session</li> <li><strong>Report failures with reproduction steps</strong> — action, expected, actual, screenshot path, suggestion</li> <li><strong>Parallelize independent tests</strong> — use Workflow C with named sessions when testing multiple pages or categories on a deployed site</li> </ol> <h2>Troubleshooting</h2> <ul> <li><strong>"No active page"</strong>: <code>browse stop</code>, retry. For zombies: <code>pkill -f "browse.*daemon"</code></li> <li><strong>Dev server not responding</strong>: <code>curl http://localhost:<port></code> — ask user to start it</li> <li><strong><code>browse eval</code> with <code>await</code> fails</strong>: Use <code>.then()</code> instead — <code>browse eval</code> doesn't support top-level await</li> <li><strong>Element ref not found</strong>: <code>browse snapshot</code> again — refs change on page update</li> <li><strong>Blank snapshot</strong>: <code>browse wait load</code> or <code>browse wait selector ".expected"</code> before snapshotting</li> <li><strong>SPA deep links 404</strong>: Navigate to <code>/</code> first, then click through</li> <li><strong>Remote auth fails</strong>: Re-run cookie-sync with <code>--context <id></code>, try <code>--verified</code></li> <li><strong>Parallel session conflicts</strong>: Ensure every <code>browse</code> command uses <code>BROWSE_SESSION=<name></code> — without it, commands go to the default session</li> <li><strong>Session not stopping</strong>: <code>BROWSE_SESSION=<name> browse stop</code>. For zombies: <code>pkill -f "browse.*<name>.*daemon"</code></li> </ul> </div> <div class="skilldetailsL1_skillmd"> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View on GitHub" target="_blank" rel="nofollow" aria-label="View on GitHub" class="skilldetails_toGitHub"> <span>View on GitHub</span> <b></b> </a> <pre><code>--- name: ui-test description: Runs adversarial UI tests in a real browser using the browse CLI, analyzing git diffs to test only changed areas or exploring the full app to find bugs in functionality, accessibility, responsive layout, and UX. license: MIT --- # UI Test — Agentic UI Testing Skill Test UI changes in a real browser. Your job is to **try to break things**, not confirm they work. Three workflows: - **Diff-driven** — analyze a git diff, test only what changed - **Exploratory** — navigate the app, find bugs the developer didn't think about - **Parallel** — fan out independent test groups across multiple Browserbase browsers ## How Testing Works The main agent **coordinates** — it plans test strategy, delegates to sub-agents, and merges results. Sub-agents do the actual browser testing. ### Planning: multiple angles, then execute once **You MUST complete all three planning rounds yourself and output them before launching any sub-agents.** Planning happens in your own response — it is NOT delegated to sub-agents. Do not skip ahead to execution. **Round 1 — Functional:** What are the core user flows? What should work? Write out each test as: action → expected result. **Round 2 — Adversarial:** Re-read Round 1. What did you miss? Think about: different user types/roles, error paths, empty states, race conditions, edge inputs (empty, huge, special chars, rapid clicks). **Round 3 — Coverage gaps:** Re-read Rounds 1–2. What about: accessibility (axe-core, keyboard-only), mobile viewports, console errors, visual consistency with the rest of the app? **Deduplicate:** Merge all three rounds into one numbered list of tests. Remove overlaps. Assign each test to a group (e.g. Group A, Group B). **Then execute once** — launch one sub-agent per group. Each sub-agent receives its specific list of tests to run, nothing more. Sub-agents do not explore or plan — they execute assigned tests and report results. Output the three rounds, the merged plan, and the group assignments in your response before calling any Agent tool. ### Principles for splitting work - **Sub-agents run assigned tests, not open exploration.** The main agent hands each sub-agent a specific numbered list of tests. Sub-agents do not plan, explore, or decide what to test — they execute the list and stop. - **The bottleneck is the slowest agent** — split work so no single agent has a disproportionate share. Many small agents > few large ones. - **Size the effort to the change** — a single component fix doesn't need many agents or many steps. A full-page redesign does. Let the scope of the diff drive the plan. - **No early stopping on failures** — find as many bugs as possible within the assigned tests. ### Giving sub-agents a step budget **The main agent MUST include an explicit browse step limit in every sub-agent prompt.** Sub-agents do not self-limit — they will run until done unless told otherwise. As a rough heuristic: ~25 steps for a few targeted checks, ~40 for a full page with functional + adversarial + a11y, ~75 for multiple pages or a broad category. **Adjust based on what the assigned tests actually require** — these are starting points, not rules. As a rough heuristic: ~25 steps for a few targeted checks, ~40 for a full page with functional + adversarial + a11y, ~75 for multiple pages or a broad category. **Adjust based on what the assigned tests actually require** — these are starting points, not rules. Every sub-agent prompt must include: ``` You have a budget of N browse steps (each `browse` command = 1 step). Count your steps as you go. When you reach N, stop immediately and report: - STEP_PASS/STEP_FAIL for every test you completed - STEP_SKIP|<test-id>|budget reached for every test you didn't get to Do not retry or continue after hitting the budget. Run only these tests: [numbered list from the merged plan] Do not explore beyond the assigned tests. Do NOT generate an HTML report or write any files. Return only step markers and your findings as text. ``` The main agent should NOT run `browse` commands itself (except to verify the dev server is up). All testing happens in sub-agents. **When a sub-agent hits its budget, the main agent accepts the partial results as-is.** Do not re-run or retry the sub-agent. Include SKIPPED tests in the final report so the developer knows what wasn't covered. ### Reporting **Every sub-agent reports back with:** ``` Tests: 8 | Passed: 5 | Failed: 2 | Skipped: 1 | Pages visited: 2 ``` **The main agent merges into a final report with:** ``` Tests: 20 | Passed: 14 | Failed: 4 | Skipped: 2 | Agents: 3 | Pass rate: 70% ``` Do not report "steps used" — browse command counts are implementation plumbing, not a meaningful metric for reviewers. ## Testing Philosophy **You are an adversarial tester.** Your goal is to find bugs, not prove correctness. - **Try to break every feature you test.** Don't just check "does the button exist?" — click it twice rapidly, submit empty forms, paste 500 characters, press Escape mid-flow. - **Test what the developer didn't think about.** Empty states, error recovery, keyboard-only navigation, mobile overflow. - **Every assertion must be evidence-based.** Compare before/after snapshots. Check specific elements by ref. Never report PASS without concrete evidence from the accessibility tree or a deterministic check. - **Report failures with enough detail to reproduce.** Include the exact action, what you expected, what you got, and a suggested fix. ## Assertion Protocol Every test step MUST produce a structured assertion. Do not write freeform "this looks good." ### Step markers For each test step, emit exactly one marker: ``` STEP_PASS|<step-id>|<evidence> ``` or ``` STEP_FAIL|<step-id>|<expected> → <actual>|<screenshot-path> ``` - `step-id`: short identifier like `homepage-cta`, `form-validation-error`, `modal-cancel` - `evidence`: what you observed that proves the step passed (element ref, text content, URL, eval result) - `expected → actual`: what you expected vs what you got - `screenshot-path`: path to the saved screenshot (failures only — see Screenshot Capture below) ### Screenshot Capture for Failures **Every STEP_FAIL MUST have an accompanying screenshot** so the developer can see what went wrong visually. When a test step fails: ```bash # 1. Take a screenshot immediately after observing the failure browse screenshot --path .context/ui-test-screenshots/<step-id>.png # If --path is not supported, take the screenshot and save manually: browse screenshot # The browse CLI will output the screenshot path — move/copy it: cp /tmp/browse-screenshot-*.png .context/ui-test-screenshots/<step-id>.png ``` Setup the screenshot directory at the start of any test run: ```bash mkdir -p .context/ui-test-screenshots ``` **Rules:** - File name = step-id (e.g., `double-submit.png`, `axe-audit.png`, `modal-focus-trap.png`) - Store in `.context/ui-test-screenshots/` — this directory is gitignored and accessible to the developer and other agents - For parallel runs, include the session name: `<session>-<step-id>.png` (e.g., `signup-double-submit.png`) - Take the screenshot at the moment of failure — capture the broken state, not after recovery - For visual/layout bugs, also screenshot the baseline (working state) for comparison: `<step-id>-baseline.png` ### How to verify (in order of rigor) 1. **Deterministic check** (strongest) — `browse eval` returns structured data you can inspect. Examples: axe-core violation count, `document.title`, form field value, console error array, element count. 2. **Snapshot element match** — a specific element with a specific role and text exists in the accessibility tree. Check by ref: `@0-12 button "Save"`. An element either exists in the tree or it doesn't. 3. **Before/after comparison** — snapshot before action, act, snapshot after. Verify the tree changed in the expected way (element appeared, disappeared, text changed). 4. **Screenshot + visual judgment** (weakest) — only for visual-only properties (color, spacing, layout) that the accessibility tree cannot capture. Always accompany with what specifically you're evaluating. ### Before/after comparison pattern This is the core verification loop. Use it for every interaction: ```bash # 1. BEFORE: capture state browse snapshot # Record: what elements exist, their text, their refs # 2. ACT: perform the interaction browse click @0-12 # 3. AFTER: capture new state browse snapshot # Compare: what changed? What appeared? What disappeared? # 4. ASSERT: emit marker based on comparison # If dialog appeared: STEP_PASS|modal-open|dialog "Confirm" appeared at @0-20 # If nothing changed: browse screenshot --path .context/ui-test-screenshots/modal-open.png # STEP_FAIL|modal-open|expected dialog to appear → snapshot unchanged|.context/ui-test-screenshots/modal-open.png ``` ## Setup ```bash which browse || npm install -g browse ``` ### Avoid permission fatigue This skill runs many `browse` commands (snapshots, clicks, evals). To avoid approving each one, add `browse` to your allowed commands: Add both patterns to `.claude/settings.json` (project-level) or `~/.claude/settings.json` (user-level): ```json { "permissions": { "allow": [ "Bash(browse:*)", "Bash(BROWSE_SESSION=*)" ] } } ``` The first pattern covers plain `browse` commands. The second covers parallel sessions (`BROWSE_SESSION=signup browse open ...`). Both are needed to avoid approval prompts. ## Mode Selection | Target | Mode | Command | Auth | |--------|------|---------|------| | `localhost` / `127.0.0.1` | Local | `browse open <url> --local` | None needed (clean isolated local browser by default) | | Deployed/staging site | Remote | `browse open <url> --remote` | Browserbase credentials; use contexts where supported | **Rule: If the target URL contains `localhost` or `127.0.0.1`, pass `--local` on the first `browse open`.** ### Local Mode (default for localhost) ```bash browse open http://localhost:3000 --local ``` `browse open ... --local` uses a clean isolated local browser by default, which is best for reproducible localhost QA runs. Use local-mode variants only when needed: - `browse open <url> --auto-connect` — auto-discover an existing debuggable local Chrome. Use this only when the test explicitly needs existing local login/cookies/state. - `browse open <url> --cdp <port|url>` — attach to a specific CDP target (explicit local browser attach). ### Remote Mode (deployed sites via cookie-sync) ```bash # Step 1: Sync cookies from local Chrome to Browserbase node .claude/skills/cookie-sync/scripts/cookie-sync.mjs --domains your-app.com # Output: Context ID: ctx_abc123 # Step 2: Open in remote mode with the synced context SESSION_JSON="$(browse cloud sessions create --context-id ctx_abc123 --persist --keep-alive)" SESSION_ID="$(echo "$SESSION_JSON" | jq -r .id)" CONNECT_URL="$(echo "$SESSION_JSON" | jq -r .connectUrl)" browse open https://staging.your-app.com --cdp "$CONNECT_URL" browse snapshot # ... run tests ... browse stop browse cloud sessions update "$SESSION_ID" --status REQUEST_RELEASE ``` Cookie-sync flags: `--domains`, `--context`, `--verified`, `--proxy "City,ST,US"` ## Workflow A: Diff-Driven Testing ### Phase 1: Analyze the diff ```bash git diff --name-only HEAD~1 # or: git diff --name-only / git diff --name-only main...HEAD git diff HEAD~1 -- <file> # read actual changes ``` Categorize changed files: | File pattern | UI impact | What to test | |-------------|-----------|--------------| | `*.tsx`, `*.jsx`, `*.vue`, `*.svelte` | Component | Render, interaction, state, edge cases | | `pages/**`, `app/**`, `src/routes/**` | Route/page | Navigation, page load, content, 404 handling | | `*.css`, `*.scss`, `*.module.css` | Style | Visual appearance (screenshot), responsive | | `*form*`, `*input*`, `*field*` | Form | Validation, submission, empty input, long input, special chars | | `*modal*`, `*dialog*`, `*dropdown*` | Interactive | Open/close, escape, focus trap, cancel vs confirm | | `*nav*`, `*menu*`, `*header*` | Navigation | Links, active states, routing, keyboard nav | | Non-UI files only | None | Skip — report "no UI tests needed" | ### Phase 2: Map files to URLs Detect framework: `cat package.json | grep -E '"(next|react|vue|nuxt|svelte|@sveltejs|angular|vite)"'` | Framework | Default port | File → URL pattern | |-----------|-------------|-----| | Next.js App Router | 3000 | `app/dashboard/page.tsx` → `/dashboard` | | Next.js Pages Router | 3000 | `pages/about.tsx` → `/about` | | Vite | 5173 | Check router config | | Nuxt | 3000 | `pages/index.vue` → `/` | | SvelteKit | 5173 | `src/routes/+page.svelte` → `/` | | Angular | 4200 | Check routing module | ### Phase 3: Ensure the right code is running Before testing, verify the dev server is serving the code from the diff — not a stale branch. **If testing a PR or specific branch:** ```bash # Check what branch is currently checked out git branch --show-current # If it's not the PR branch, switch to it git fetch origin <branch> && git checkout <branch> # Install deps — the lockfile may differ between branches yarn install # or npm install / pnpm install ``` If the dev server was already running on a different branch, restart it after checkout. **Find a running dev server:** ```bash for port in 3000 3001 5173 4200 8080 8000 5000; do s=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$port" 2>/dev/null) if [ "$s" != "000" ]; then echo "Dev server on port $port (HTTP $s)"; fi done ``` If nothing found: tell the user to start their dev server. **Verify it actually renders:** After `browse open` + `browse snapshot`, check that the accessibility tree contains real page content (navigation, headings, interactive elements) — not just an error overlay or empty body. Next.js dev servers can return HTTP 200 while showing a full-screen build error dialog. If the snapshot is empty or dominated by an error dialog, the server is broken — fix the build before testing. ### Phase 4: Generate test plan For each changed area, plan **both happy path AND adversarial tests**: ``` Test Plan (based on git diff) ============================= Changed: src/components/SignupForm.tsx (added email validation) 1. [happy] Valid email submits successfully URL: http://localhost:3000/signup Steps: fill valid email → submit → verify success message appears 2. [adversarial] Invalid email shows error Steps: fill "not-an-email" → submit → verify error message appears 3. [adversarial] Empty form submission Steps: click submit without filling anything → verify error, no crash 4. [adversarial] XSS in email field Steps: fill "<script>alert(1)</script>" → submit → verify sanitized/rejected 5. [adversarial] Rapid double-submit Steps: click submit twice quickly → verify no duplicate submission 6. [adversarial] Keyboard-only flow Steps: Tab to email → type → Tab to submit → Enter → verify success ``` ### Phase 5: Execute tests ```bash browse stop 2>/dev/null mkdir -p .context/ui-test-screenshots # localhost/default QA → clean, reproducible local run browse open http://localhost:3000 --local ``` For each test, follow the **before/after pattern**: ```bash # Navigate browse open http://localhost:3000/path --local browse wait load # BEFORE snapshot browse snapshot # Note the current state: elements, refs, text # ACT browse click @0-ref # or: browse fill "selector" "value" # or: browse type "text" # or: browse press Enter # AFTER snapshot browse snapshot # Compare against BEFORE: what changed? # ASSERT with marker # STEP_PASS|step-id|evidence OR STEP_FAIL|step-id|expected → actual ``` ### Phase 6: Report results ``` ## UI Test Results ### STEP_PASS|valid-email-submit|status "Thanks!" appeared at @0-42 after submit - URL: http://localhost:3000/signup - Before: form with email input @0-3, submit button @0-7 - Action: filled "user@test.com", clicked @0-7 - After: form replaced by status element with "Thanks! We'll be in touch." ### STEP_FAIL|double-submit|expected single submission → form submitted twice|.context/ui-test-screenshots/double-submit.png - URL: http://localhost:3000/signup - Before: form with submit button @0-7 - Action: clicked @0-7 twice rapidly - After: two success toasts appeared, suggesting duplicate submission - Screenshot: .context/ui-test-screenshots/double-submit.png - Suggestion: disable submit button after first click, or debounce the handler --- **Summary: 4/6 passed, 2 failed** Failed: double-submit, xss-sanitization Screenshots saved to `.context/ui-test-screenshots/` — open any failed step's screenshot to see the broken state. ``` Always `browse stop` when done. ### Phase 7: Generate HTML report After producing the text report, generate a standalone HTML report that a reviewer can open in a browser. The report embeds screenshots inline (base64) so it works as a single file — no external dependencies. **Why:** Text reports are good for the agent conversation, but reviewers (PMs, designers, other engineers) want a visual artifact they can open, scan, and share. Screenshots inline make failures immediately obvious. #### How to generate 1. Read the HTML template at [references/report-template.html](references/report-template.html) 2. Build the report by replacing the template placeholders with actual test data: | Placeholder | Value | |-------------|-------| | `{{TITLE}}` | Report title for `<title>` tag (e.g., "UI Test: PR #1234 — OAuth Settings") | | `{{TITLE_HTML}}` | Report title for the visible `<h1>`. If a PR URL is available, wrap the PR reference in an `<a>` tag so it's clickable (e.g., `UI Test: <a href="https://github.com/org/repo/pull/1234">PR #1234</a> — OAuth Settings`). If no URL, use plain text same as `{{TITLE}}`. | | `{{META}}` | One-line context: date, app URL, user, branch | | `{{TOTAL_TESTS}}` | Total STEP_PASS + STEP_FAIL count | | `{{AGENT_COUNT}}` | Number of sub-agents that ran | | `{{PASS_COUNT}}` | Number of STEP_PASS | | `{{FAIL_COUNT}}` | Number of STEP_FAIL | | `{{PASS_RATE}}` | Integer percentage (e.g., "92") | | `{{RATE_CLASS}}` | `good` (≥90%), `warn` (70–89%), `bad` (<70%) | | `{{FAILURES_SECTION}}` | HTML for failed test cards (see below) | | `{{PASSES_SECTION}}` | HTML for passed test cards (see below) | 3. For each test result, generate a `<details>` card. Failed tests should be **open by default** so reviewers see them immediately: ```html <!-- Failed test card (open by default) --> <div class="section"> <h2>Failures <span class="count">{{FAIL_COUNT}}</span></h2> <details class="test-card fail" open> <summary> <span class="badge fail">FAIL</span> <span class="step-id">step-id-here</span> <span class="evidence">expected → actual</span> </summary> <div class="body"> <dl> <dt>URL</dt><dd>http://localhost:3000/path</dd> <dt>Action</dt><dd>What was done</dd> <dt>Expected</dt><dd>What should have happened</dd> <dt>Actual</dt><dd>What happened instead</dd> </dl> <div class="suggestion">Fix: description of suggested fix</div> <div class="screenshot"> <img src="data:image/png;base64,..." alt="Screenshot of failure"> <div class="caption">step-id.png — captured at moment of failure</div> </div> </div> </details> </div> <!-- Passed test card (collapsed by default) --> <div class="section"> <h2>Passed <span class="count">{{PASS_COUNT}}</span></h2> <details class="test-card pass"> <summary> <span class="badge pass">PASS</span> <span class="step-id">step-id-here</span> <span class="evidence">evidence summary</span> </summary> <div class="body"> <dl> <dt>URL</dt><dd>http://localhost:3000/path</dd> <dt>Evidence</dt><dd>What was observed</dd> </dl> </div> </details> </div> ``` 4. **Embed screenshots as base64** so the HTML is fully self-contained: ```bash # Convert screenshot to base64 data URI base64 -i .context/ui-test-screenshots/step-id.png | tr -d '\n' # Use as: src="data:image/png;base64,<output>" ``` Read each screenshot file referenced in STEP_FAIL markers, base64-encode it, and embed it as an `<img src="data:image/png;base64,...">` in the corresponding test card. For STEP_PASS, only embed a screenshot if one was explicitly taken (e.g., baseline screenshots). 5. Write the final HTML to `.context/ui-test-report.html`: ```bash # Write the generated HTML cat > .context/ui-test-report.html << 'REPORT_EOF' <!DOCTYPE html> ...generated report... REPORT_EOF # Open it for the reviewer open .context/ui-test-report.html # macOS # xdg-open .context/ui-test-report.html # Linux ``` 6. Tell the user: `Report saved to .context/ui-test-report.html` and offer to open it. **Rules:** - Failures section comes before passes — reviewers care about what's broken first - Failed cards are `open` by default; passed cards are collapsed - Every STEP_FAIL card MUST have an embedded screenshot — if the screenshot file is missing, note it in the card - Include the suggestion/fix in each failure card if one was provided - The report must work offline — no CDN links, no external assets - Keep the HTML under 5MB — if screenshots push it over, reduce image quality or skip baseline screenshots for passes ## Adversarial Test Patterns Apply these to every interactive element you test. Read [references/adversarial-patterns.md](references/adversarial-patterns.md) for the full pattern library (forms, modals, navigation, error states, keyboard accessibility). ## Deterministic Checks These produce structured data, not judgment calls. Use them as the strongest form of assertion. | Check | What it catches | Assertion | |-------|----------------|-----------| | axe-core | WCAG violations | `violations.length === 0` | | Console errors | Runtime exceptions, failed requests | empty error array | | Broken images | Missing/failed image loads | no images with `naturalWidth === 0` | | Form labels | Inputs without accessible labels | every input has `hasLabel: true` | For the exact `browse eval` recipes, read [references/browser-recipes.md](references/browser-recipes.md). ## Workflow B: Exploratory Testing No diff, no plan — just open the app and try to break it. Use this when the user says "test my app", "find bugs", or "QA this site." ### Approach 1. **Discover the app** — read `package.json` to detect the framework, then open the root URL and snapshot to see what's there 2. **Navigate everything** — click through nav links, visit every reachable page, note what exists 3. **Test what you find** — for each page, apply the adversarial patterns below (forms, modals, navigation, keyboard, error states) 4. **Run deterministic checks** — axe-core, console errors, broken images, form labels on every page 5. **Report findings** — use STEP_PASS/STEP_FAIL markers, include reproduction steps for failures Don't try to be systematic about coverage. Just explore like a user would, but with the intent to break things. The agent is good at this — let it roam. ### Tips for exploratory runs - Start with the homepage, then follow the navigation naturally - Try the 404 page (`/does-not-exist`) — is it custom or default? - Look for empty states (pages with no data) - Test forms with garbage input before valid input - Check mobile viewport (375px) on every page — does it overflow? - If the app has auth, use cookie-sync first ## Workflow C: Parallel Testing Run independent test groups concurrently using named `browse` sessions (`BROWSE_SESSION=<name>`). Each session gets its own browser. Works with both local and remote mode. Use when testing multiple pages or categories and you want faster wall clock time. Read [references/parallel-testing.md](references/parallel-testing.md) for the full workflow: session setup, agent fan-out, cookie-sync for auth, and result merging. ## Design Consistency Check whether changed UI matches the rest of the app visually. Read [references/design-consistency.md](references/design-consistency.md) when doing visual or design checks. ## Test Categories | Category | How | Assertion type | |----------|-----|---------------| | Accessibility | axe-core + keyboard nav | Deterministic (violation count) | | Visual Quality | Screenshot + heuristic evaluation | Visual judgment (weakest — note specifics) | | Responsive | Viewport sweep + screenshots | Visual + deterministic (overflow check) | | Console Health | Console capture eval | Deterministic (error count) | | UX Heuristics | Snapshot + Laws of UX + Nielsen's | Structured judgment (cite specific heuristic) | | Error States | Navigate to empty/error states | Before/after comparison | | Data Display | Snapshot on tables/dashboards | Element match (column count, formatting) | | Design Consistency | Screenshot baseline + changed page comparison | Visual judgment (cite specific property) | | Exploratory | Free navigation + adversarial testing | Before/after + judgment | Reference guides (load on demand): - **Adversarial patterns** — [references/adversarial-patterns.md](references/adversarial-patterns.md) — load when testing forms, modals, navigation, or keyboard a11y - **Browser recipes** — [references/browser-recipes.md](references/browser-recipes.md) — load when running deterministic checks (axe-core, console, images, form labels) - **Exploratory testing** — [references/exploratory-testing.md](references/exploratory-testing.md) — load for Workflow B (no diff, open exploration) - **UX heuristics** — [references/ux-heuristics.md](references/ux-heuristics.md) — load when evaluating UX quality or citing specific heuristics - **Design system** — [references/design-system.example.md](references/design-system.example.md) — template for users to customize - **Design consistency** — [references/design-consistency.md](references/design-consistency.md) — load when doing visual consistency checks - **Parallel testing** — [references/parallel-testing.md](references/parallel-testing.md) — load for Workflow C (concurrent sessions) - **Report template** — [references/report-template.html](references/report-template.html) — HTML template for Phase 7 report generation For worked examples with exact commands, read [EXAMPLES.md](EXAMPLES.md) if you need to see the assertion protocol in action. ## Best Practices 1. **Be adversarial** — try to break things, don't just confirm they work 2. **Every assertion needs evidence** — snapshot ref, eval result, or before/after diff 3. **Before/after for every interaction** — snapshot, act, snapshot, compare 4. **Screenshot every failure** — `browse screenshot` immediately on STEP_FAIL, save to `.context/ui-test-screenshots/<step-id>.png` 5. **Deterministic checks first** — axe-core, console errors, form labels before visual judgment 6. **For localhost, start with clean local mode** — pass `--local` on the first `browse open` for reproducible runs; use `--auto-connect` only when existing local state is required 7. **Always `browse stop` when done** — for parallel runs, stop every named session 8. **Report failures with reproduction steps** — action, expected, actual, screenshot path, suggestion 9. **Parallelize independent tests** — use Workflow C with named sessions when testing multiple pages or categories on a deployed site ## Troubleshooting - **"No active page"**: `browse stop`, retry. For zombies: `pkill -f "browse.*daemon"` - **Dev server not responding**: `curl http://localhost:<port>` — ask user to start it - **`browse eval` with `await` fails**: Use `.then()` instead — `browse eval` doesn't support top-level await - **Element ref not found**: `browse snapshot` again — refs change on page update - **Blank snapshot**: `browse wait load` or `browse wait selector ".expected"` before snapshotting - **SPA deep links 404**: Navigate to `/` first, then click through - **Remote auth fails**: Re-run cookie-sync with `--context <id>`, try `--verified` - **Parallel session conflicts**: Ensure every `browse` command uses `BROWSE_SESSION=<name>` — without it, commands go to the default session - **Session not stopping**: `BROWSE_SESSION=<name> browse stop`. For zombies: `pkill -f "browse.*<name>.*daemon"` </code></pre> </div> </div> </div> <script> layui.use(function () { var element = layui.element; element.tab({ headerElem: "#skilldetailsL1_header>button", bodyElem: "#skilldetailsL1_body>div", }); }); </script> <div class="skilldetailsL2"> <div class="skilldetailsL2_title"> <h2>All Files</h2> <span>12 files</span> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="EXAMPLES.md" target="_blank" aria-label="EXAMPLES.md" rel="nofollow">EXAMPLES.md</a> <span>23.4k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="LICENSE.txt" target="_blank" aria-label="LICENSE.txt" rel="nofollow">LICENSE.txt</a> <span>1k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="README.md" target="_blank" aria-label="README.md" rel="nofollow">README.md</a> <span>4k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="SKILL.md" target="_blank" aria-label="SKILL.md" rel="nofollow">SKILL.md</a> <span>28.2k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/adversarial-patterns.md" target="_blank" aria-label="references/adversarial-patterns.md" rel="nofollow">references/adversarial-patterns.md</a> <span>3.6k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/browser-recipes.md" target="_blank" aria-label="references/browser-recipes.md" rel="nofollow">references/browser-recipes.md</a> <span>6.5k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/design-consistency.md" target="_blank" aria-label="references/design-consistency.md" rel="nofollow">references/design-consistency.md</a> <span>2.5k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/design-system.example.md" target="_blank" aria-label="references/design-system.example.md" rel="nofollow">references/design-system.example.md</a> <span>4k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/exploratory-testing.md" target="_blank" aria-label="references/exploratory-testing.md" rel="nofollow">references/exploratory-testing.md</a> <span>2.9k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/parallel-testing.md" target="_blank" aria-label="references/parallel-testing.md" rel="nofollow">references/parallel-testing.md</a> <span>7.2k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/report-template.html" target="_blank" aria-label="references/report-template.html" rel="nofollow">references/report-template.html</a> <span>9.3k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> <div class="skillFiles"> <div class="skillFilesL"> <b></b> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="references/ux-heuristics.md" target="_blank" aria-label="references/ux-heuristics.md" rel="nofollow">references/ux-heuristics.md</a> <span>18k</span> </div> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="View" target="_blank" aria-label="View" rel="nofollow">View</a> </div> </div> </div> <div class="skilldetailsR"> <div class="skilldetailsR1"> <div class="skilldetailsR1s"> <h2>Install ui-test</h2> <div class="skilldetailsR1s_header" id="skilldetailsR1s_header"> <button class="layui-this"> <b></b> <span>Download ZIP</span> </button> <button class=""> <b></b> <span>Git Clone</span> </button> </div> <div class="skilldetailsR1s_body" id="skilldetailsR1s_body"> <div class="skilldetailsR1s_body1 layui-show"> <p>Download and extract the skill files to your .claude/skills/ directory.</p> <a href="javascript:;" title="Download ZIP" data-source="jTz7L2nOWmJbruF4z-KtfQ" aria-label="Download ZIP" role="button" class="skill_downloadzip"> <b></b> <span>Download ZIP</span> </a> </div> <div class="skilldetailsR1s_body2"> <p>Clone the repository and copy the skill files to your project.</p> <div class="skill_clone"> <p> git clone https://github.com/browserbase/skills/tree/main/skills/ui-test # Copy SKILL.md to your .claude/skills/ directory </p> <a href="javascript:;" title="Copy" role="button" aria-label="Copy" class="skill_clone_copy"> <img src="/assets/images/prompt_word2RMs_p_btn.png" alt="Copy" /> <span>Copy</span> </a> </div> </div> </div> <div class="skilldetailsR1s_info"> <span>Quick Setup: </span> Copy the skill folder to .claude/skills/ Claude will automatically detect and use the skill </div> <div class="skilldetailsR1s_repository"> <span>Repository</span> <a href="https://github.com/browserbase/skills/tree/main/skills/ui-test" title="browserbase/skills" target="_blank" aria-label="Repository" rel="nofollow">browserbase/skills</a> </div> </div> </div> <div class="skilldetailsR2"> <h2>Related Skills</h2> <div> <div class="skilldetailsR2s"> <a href="/skill/detail/githubcodesearch.html" title="github-code-search" aria-label="github-code-search">github-code-search</a> <div> <div class="skilldetailsR2s_time"> <b></b> <span>Updated time June 29, 2026</span> </div> <button class="xix_star skill_datas" data-source="ImFzApSELVOJ4BS9OPm6AQ"> <b></b> <span class="collectNums_ImFzApSELVOJ4BS9OPm6AQ">0</span> </button> </div> </div> <div class="skilldetailsR2s"> <a href="/skill/detail/drizzleorm.html" title="drizzle-orm" aria-label="drizzle-orm">drizzle-orm</a> <div> <div class="skilldetailsR2s_time"> <b></b> <span>Updated time June 29, 2026</span> </div> <button class="xix_star skill_datas" data-source="DKEbAJtyry1xeBt689E4mA"> <b></b> <span class="collectNums_DKEbAJtyry1xeBt689E4mA">0</span> </button> </div> </div> <div class="skilldetailsR2s"> <a href="/skill/detail/prismaclientapi.html" title="prisma-client-api" aria-label="prisma-client-api">prisma-client-api</a> <div> <div class="skilldetailsR2s_time"> <b></b> <span>Updated time June 29, 2026</span> </div> <button class="xix_star skill_datas" data-source="lelVT1hPEcLSdrlO0f3DHQ"> <b></b> <span class="collectNums_lelVT1hPEcLSdrlO0f3DHQ">0</span> </button> </div> </div> <div class="skilldetailsR2s"> <a href="/skill/detail/clickhouseio.html" title="clickhouse-io" aria-label="clickhouse-io">clickhouse-io</a> <div> <div class="skilldetailsR2s_time"> <b></b> <span>Updated time June 29, 2026</span> </div> <button class="xix_star skill_datas" data-source="C1NN_dqOG6dfmc1tQzgtGQ"> <b></b> <span class="collectNums_C1NN_dqOG6dfmc1tQzgtGQ">0</span> </button> </div> </div> </div> </div> </div> </div> </div> </main> <footer> <div class="footer"> <div class="footer1"> <div class="footer11"> <span class="footer11_title">Hot AI tools</span> <div class="footer11info"> <a href="/tool/ai-clothes-remover.html" aria-label="AI Clothes Remover" class="footer11s">AI Clothes Remover</a> <a href="/tool/deepnude-generator.html" aria-label="DeepNude generator" class="footer11s">DeepNude generator</a> <a href="/tool/purechat.html" aria-label="PureChat" class="footer11s">PureChat</a> </div> </div> <div class="footer12"> <span class="footer11_title">AI tools with potential</span> <div class="footer11info"> <a href="/tool/qi-jing-ai-ai-tool.html" aria-label="奇境 AI" class="footer11s">奇境 AI</a> <a href="/tool/ezaudio-ai-tool.html" aria-label="EZAudio" class="footer11s">EZAudio</a> <a href="/tool/viralclip-ai-tool.html" aria-label="ViralClip" class="footer11s">ViralClip</a> </div> </div> <div class="footer13"> <span class="footer11_title">Read more</span> <div class="footer11info"> <a href="/ainews/ai-hosts-notebooklm-podcast-interviews.html" aria-label="AI Hosts of NotebookLM Podcast Now Available for Interviews" class="footer11s">AI Hosts of NotebookLM Podcast Now Available for Interviews</a> <a href="/ainews/corporate-ai-adoption-leveling-ramp-data.html" aria-label="Corporate AI Adoption Plateaus, Ramp Data Reveals" class="footer11s">Corporate AI Adoption Plateaus, Ramp Data Reveals</a> <a href="/ainews/microsoft-unveils-businessfocused-copilot-surface-devices-powered-intel.html" aria-label="Microsoft Unveils Business-Focused Copilot+ Surface Devices Powered by Intel" class="footer11s">Microsoft Unveils Business-Focused Copilot+ Surface Devices Powered by Intel</a> </div> </div> <div class="footer4"> <span class="footer11_title">Follow</span> <div class="footer11info"> <a href="javascript:;" class="footer11s">Contact us</a> <a href="mailto:admin@xix.ai" role="button" aria-label="Contact us" class="footer11s">admin@xix.ai</a> <a href="/sitemap.xml" class="footer11s" aria-label="SiteMap">SiteMap</a> </div> </div> </div> <span class="footer2"></span> <div class="footer3">Copyright ©2025 xix.ai All Rights Reserved.</div> </div> </footer> <div class="ai_cookie" style="display: none"> <div class="ai_cookie_b"> <div class="icon_f ai_cookie_close"> <svg class="icon" aria-hidden="true"> <use xlink:href="#icon-guanbi1"></use> </svg> </div> <p> By clicking "Accept All Cookies", you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts.<span>Privacy Policy</span> Notice </p> <div class="cokiesetRight"> <a href="javascript:;" class="cokieA ai_cookie_open" role="button" aria-label="Cookie Settings">Cookie Settings</a> <a href="javascript:;" class="cokieA RefuseCookies" role="button" aria-label="Reject All">Reject All</a> <a href="javascript:;" class="cokieA cokieAall" role="button" aria-label="Accept All Cookies">Accept All Cookies</a> </div> </div> </div> <div class="ai_cookieSettings" style="display: none"> <div class="layuiDivcokie layui-layer-wrap" id="layuiDivcokie" style="display: block"> <div class="cokielayTop dlyflx"> <img src="/assets/images/logo.png" alt="" /> <div class="icon_f ai_cookie_close1"> <svg class="icon" aria-hidden="true"> <use xlink:href="#icon-guanbi"></use> </svg> </div> </div> <hr /> <div class="cokielayDown dlyflx"> <p class="cokielaydTop">Privacy Preference</p> <p class="cokielaydDesc"> When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings.However, blocking some types of cookies may impact your experience of the site and the services we are able to offer. <a href="#" title="Privacy Policy" aria-label="Privacy Policy"><span>Privacy Policy</span></a> <b>Statement</b> </p> <div class="cokielayDivdown"> <p class="coklaydownP">Manage Preferences</p> <ul class="cokidownUl"> <li class="cokidownli dlyflx" style="padding: 25px 0px 25px"> <div class="ckdTops"> <div class="ckdLeft"> <div class="icon_f"> <svg class="icon" aria-hidden="true"> <use xlink:href="#icon-add"></use> </svg> <svg class="icon icon_active" aria-hidden="true"> <use xlink:href="#icon-add1"></use> </svg> </div> <p class="ckdlipmid">Strictly Necessary Cookie</p> </div> <p class="ckdlipr">Always Active</p> </div> <p class="ckdDowns"> These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information. </p> </li> </ul> </div> </div> <div class="cklyBtn"> <a href="javascript:;" role="button" aria-label="Accept All Cookies" class="active cokieAall">Accept All Cookies</a> </div> </div> <script> $(document).on("click", ".ai_cookie_close", function () { $(".ai_cookie").hide(); }); $(document).on("click", ".ai_cookie_close1", function () { $(".ai_cookieSettings").hide(); }); $(document).on("click", ".ai_cookie_open", function () { $(".ai_cookieSettings").show(); }); $(document).on("click", ".ckdLeft", function () { var $li = $(this).closest("li"); var $downs = $li.find(".ckdDowns"); var $iconBox = $(this).find(".icon_f"); $downs.slideToggle(200, function () { if ($downs.is(":visible")) { $iconBox.find(".icon").hide(); $iconBox.find(".icon_active").show(); } else { $iconBox.find(".icon").hide(); $iconBox.find(".icon").first().show(); } }); }); </script> </div> <link rel="stylesheet" type="text/css" href="https://accounts.google.com/gsi/style"> <div class="login_tab"> <div class="login_mainC"> <div class="login_tab_top"> <div class="login_tab_top1"> <a href="javascript:;" role="tab" aria-label="Sign In" aria-selected="true" class="login_tab_top1a ">Sign In</a> <a href="javascript:;" role="tab" aria-label="Sign Up" aria-selected="false" class="login_tab_top2a">Sign Up</a> </div> <div class="login_tab_top2"> <a href="javascript:;"><img src="/assets/images/login_mainC_top_m_img.png" alt=""></a> </div> </div> <div class="forms_google"> <div id="g_id_signin"></div> </div> <div class="forms_or"> <div class="forms_line"></div> <span>OR</span> <div class="forms_line"></div> </div> <div class="login_tab_bottom"> <div class="login_tab_top1a_bottom"> <div class="login_form "> <div class="login_forms"> <img src="/assets/images/login_email.png" alt="Email"> <input type="text" placeholder="Please fill in your email address" class="login_forms_email"> <span></span> </div> <div class="login_forms"> <img src="/assets/images/login_password.png" alt="Password"> <input type="password" placeholder="Please enter your password" class="login_forms_password"> <i style="cursor: pointer;" class="layui-icon layui-icon-eye-invisible toggle-password" id="toggleLoginPassword"></i> <span></span> </div> <div class="login_forms forms_code1"> <input type="text" placeholder="Please enter the graphic verification code" class="login_forms_captcha"> <img src="" alt="Please enter the graphic verification code" class="login-js-refresh-captcha"> <span></span> </div> <div class="login_forms_bottom"> <label class="login_remember"> <input type="checkbox" aria-label="Remember me"> <span>Remember me</span> </label> <a href="/account/forgetPassword.html" aria-label="Change password" class="login_forget">Forgot password</a> </div> <a href="javascript:;" type="button" role="button" aria-label="Sign In" id="login_button" class="login_button">Sign In</a> </div> </div> <div class="login_tab_top2a_bottom"> <div class="login_form"> <div class="login_forms"> <img src="/assets/images/login_email.png" alt="Email"> <input type="text" placeholder="Please fill in your email address" class="register_forms_email"> <span></span> </div> <div class="login_forms"> <img src="/assets/images/login_password.png" alt="Password"> <input type="password" placeholder="Please enter your password" class="register_forms_password"> <i style="cursor: pointer;" class="layui-icon layui-icon-eye-invisible toggle-password" id="toggleRegisterPassword"></i> <span></span> </div> <div class="login_forms forms_code1"> <input type="text" placeholder="Please enter the graphic verification code" class="register_forms_captcha"> <img src="" alt="Please enter the graphic verification code" class="register-js-refresh-captcha" id="register_captcha"> <span></span> </div> <div class="login_forms"> <input type="text" class="verify-code-input" placeholder="Please enter the verification code"> <button id="verifyCodeBtn" class="verify-code-btn" data-text="Get Verification Code">Get Verification Code</button> <span></span> </div> <a href="javascript:;" role="button" aria-label="Sign Up" class="login_button" id="register_button">Sign Up</a> </div> </div> </div> </div> </div> <script src="https://accounts.google.com/gsi/client" async defer></script> <script> $(document).ready(function () { LoginRegister.init({ selectors: { email: { login: '.login_forms_email', register: '.register_forms_email' }, password: { login: '.login_forms_password', register: '.register_forms_password' }, captcha: { login: '.login_forms_captcha', register: '.register_forms_captcha', verify: '.verify-code-input' }, buttons: { login: '#login_button', register: '#register_button', verifyCode: '#verifyCodeBtn' }, tabs: { login: '.login_tab_top1a', register: '.login_tab_top2a', close: '.login_tab_top2 a' } }, messages: { email: "The email format is incorrect", password: { empty: "Please enter your password", invalid: "The password must be 6-18 characters and contain both letters and numbers" }, captcha: "Please enter the graphic verification code", verifyCode: "Please enter the verification code", operationInProgress: "Operation in progress, please wait", unexpectedError: "An unexpected error occurred" }, urls: { login: "/account/dologin.html", register: "/account/register.html", getMailSign: "/account/getMailSign", sendMail: "/account/registerSendMail.html", redirctUrl:'pc' } }); }); function initializeGoogleSignIn() { if (typeof google === 'undefined' || !google.accounts) { setTimeout(initializeGoogleSignIn, 100); return; } google.accounts.id.initialize({ client_id: "294584378011-s53466qiuig7d30tcqrpjv1ue3ni2gun.apps.googleusercontent.com", callback: handlePCCredentialResponse, auto_select: false, locale: 'en', }); google.accounts.id.renderButton( document.getElementById("g_id_signin"), { theme: "outline", size: "large", type: "standard", shape: "rectangular", logo_alignment: "left", text: "signin_with", width: 400, locale: 'en', } ); } document.addEventListener('DOMContentLoaded', initializeGoogleSignIn); </script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-LN407DS0B4"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-LN407DS0B4'); </script> <script src="/kukukuwl.js" type="text/javascript"></script> <a href="javascript:void(0);" class="totop" role="button" aria-label="Back to Top"><img src="/assets/images/totop.png" alt="" /></a> <script> layui.use(function () { var element = layui.element; element.tab({ headerElem: "#skilldetailsR1s_header>button", bodyElem: "#skilldetailsR1s_body>div", }); }); function initSkillCloneCopy() { $(document) .off("click.skillCloneCopy") .on("click.skillCloneCopy", ".skill_clone .skill_clone_copy", function (e) { e.preventDefault(); var $btn = $(this); var $img = $btn.find("img"); var text = $.trim($btn.siblings("p").text()); var $temp = $("<textarea>"); $("body").append($temp); $temp.val(text).select(); try { document.execCommand("copy"); // 切换成功图标 $img.attr("src", "/assets/images/prompt_word2RMs_p_btn_ok.png"); $btn.addClass("active"); // 清除上一次定时器 clearTimeout($btn.data("copyTimer")); // 3秒后恢复原图 var timer = setTimeout(function () { $img.attr("src", "/assets/images/prompt_word2RMs_p_btn.png"); $btn.removeClass("active"); }, 3000); $btn.data("copyTimer", timer); } catch (err) { alert("复制失败"); } $temp.remove(); }); } function initSkilldetailsFixed() { var $box = $(".skilldetailsR1"); if (!$box.length) { return; } var fixedTop = 20; var topOffset = $box.offset().top; var boxHeight = $box.outerHeight(); var $placeholder = $("<div></div>").height(boxHeight).hide(); $box.before($placeholder); function handleFixed() { if ($(window).width() <= 1024) { $placeholder.hide(); $box.css({ position: "", top: "", width: "", zIndex: "", }); return; } var scrollTop = $(window).scrollTop(); if (scrollTop >= topOffset - fixedTop) { $placeholder.show(); $box.css({ position: "fixed", top: fixedTop + "px", width: $placeholder.width() + "px", zIndex: 100, }); } else { $placeholder.hide(); $box.css({ position: "", top: "", width: "", zIndex: "", }); } } $(window).on("scroll.skilldetailsFixed resize.skilldetailsFixed", handleFixed); handleFixed(); } function initSkilldetailsExpand() { $(".skilldetailsL_p").each(function () { var $item = $(this); $item.find(".skilldetailsL_p_expand").text($item.hasClass("active") ? "...Expand all" : "Hidden"); }); $(document) .off("click.skilldetailsExpand") .on("click.skilldetailsExpand", ".skilldetailsL_p_expand", function (e) { e.preventDefault(); var $parent = $(this).closest(".skilldetailsL_p"); if ($parent.hasClass("active")) { $parent.removeClass("active"); $(this).text("Hidden"); } else { $parent.addClass("active"); $(this).text("...Expand all"); } }); } function checkFollow() { let dataSources = []; $('button.skill_datas').each(function () { let source = $(this).data('source'); if (source) { dataSources.push(String(source).trim()); } }); dataSources = [...new Set(dataSources)]; if (dataSources.length === 0) { return; } $.post('/api/user/FindSkillFollow', { source: dataSources }, function (res) { if (res.code == 1 && res.data.length > 0) { res.data.forEach(function (id) { $('button.skill_datas[data-source="' + id + '"]').addClass('active'); }); } }, 'json'); } $(function () { checkFollow(); initSkillCloneCopy(); initSkilldetailsFixed(); initSkilldetailsExpand(); }); $(document).on('click', 'button.skill_datas', function (e) { e.preventDefault(); const that = $(this); let source = that.data('source'); if (!source || source === undefined || !CommonUtils.checkLogin()) return false; layer.load(2, { shade: [0.3, "#000"], time: 0, }); var path = "/user/followSkill"; var realPath = CommonUtils.getRealPath(path); $.post(realPath, { source: source }, function (result) { layer.closeAll(); CommonUtils.showMsg(result.msg, result.code); if (result.code == 1) { var values = result.data.data_source; var count = result.data.count; var collected = result.data.collected; var elements = $(".collectNums_" + values); if (elements.length > 0) { elements.each(function () { $(this).parents('button').toggleClass('active', collected); $(this).text(count); }); } } }) }) $(document).on('click', '.skill_downloadzip', function (e) { e.preventDefault(); const url = $(this).data("source"); if (!url) return; window.open("/api/index/download_zip?source=" + encodeURIComponent(url), "_blank"); }) </script> </body> </html>