The Complete Production SOP: How to Deploy and Run Playwright Component Testing (CT) for React & Vue in Autonomous AI Agents
Production SOP to install and execute Playwright Component Testing (CT) for React & Vue in Codex, Claude Code, and Cursor with real-browser verification.
Technical Overview & Architectural Context
Autonomous coding agents frequently default to synthetic DOM runtimes like jsdom or happy-dom when tasked with component tests. While these mock environments execute quickly, they completely fail to catch critical real-world rendering failures: CSS cascade collisions, flexbox/grid layout calculation bugs, cross-browser WebKit/Gecko layout differences, and true synthetic browser events (such as real pointer hover chains and focus trapping). When agents generate tests in pure node environments, they produce false positives that pass in CI but break in production browsers. The Playwright Component Testing (CT) skill forces agents into a deterministic browser-first workflow. It configures @playwright/experimental-ct-react (or @playwright/experimental-ct-vue) with Vite bundler integration to compile components on the fly into an isolated browser canvas. By mounting actual JSX/SFC components inside headless Chromium, Firefox, and WebKit instances, the agent evaluates real computed styles, viewport shifts, and layout bounding boxes while maintaining the execution speed of isolated component test suites.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Manifest Mounting and Agent Rule Registration
Mount the SKILL.md definition into the workspace agent rules hierarchy for deterministic runtime discovery.
Autonomous agents discover behavioral rules by traversing directory standards like .agents/skills/ or vendor-specific directories (.cursor/rules, .claude/skills). Mounting this manifest ensures the agent recognizes explicit triggers like 'mount component playwright ct' and adheres to constrained file writes rather than attempting to download arbitrary external testing wrappers.
mkdir -p .agents/skills/playwright-component-testing-ct && curl -fsSL https://askills.dev/api/skills/playwright-component-testing-ct/raw -o .agents/skills/playwright-component-testing-ct/SKILL.md---
name: "playwright-component-testing-ct"
description: "Execute fast, real-browser component integration tests using Playwright Component Testing."
metadata:
author: "Microsoft"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "setup playwright component testing"
- "mount component playwright ct"
- "cross browser component test"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Execution SOP
1. Install: pnpm add -D @playwright/experimental-ct-react @playwright/test
2. Initialize configuration: playwright-ct.config.ts targeting Chromium, Firefox, WebKit.
3. Create tests matching *.spec.tsx containing import { test, expect } from '@playwright/experimental-ct-react'.
4. Always mount via `const component = await mount(<Component {...props} />);`
5. Verify visual state with `await expect(component).toBeVisible();` and validate real user interaction.Place the SKILL.md under .cursor/rules/playwright-ct.mdc or project root to prevent LLM context dilution while keeping trigger indexing instant.
Do not mix standard '@playwright/test' imports with component testing specs. Component tests must import 'test' and 'expect' strictly from '@playwright/experimental-ct-react' or '@playwright/experimental-ct-vue'.
Bundler Harness & Config Initialization
Generate the playwright-ct.config.ts and index.html/index.ts component test harnesses.
Playwright CT requires a lightweight index.html test harness and a dedicated configuration file specifying the bundler (Vite), component directories, and browser targets. This prevents tests from trying to spin up full end-to-end dev servers.
pnpm add -D @playwright/experimental-ct-react && pnpm exec playwright install --with-deps chromiumimport { defineConfig, devices } from '@playwright/experimental-ct-react';
import path from 'path';
export default defineConfig({
testDir: './src',
testMatch: /.*\.spec\.(tsx|jsx)/,
snapshotDir: './__snapshots__',
timeout: 10 * 1000,
fullyParallel: true,
use: {
trace: 'on-first-retry',
ctPort: 3100,
ctViteConfig: {
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
},
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],
});Restrict default projects to Chromium during local development iterations to cut agent execution latency by 65%. Run WebKit and Firefox in CI.
Ensure playwright/index.html exists. If missing, Playwright CT cannot mount the virtual React root element into the browser viewport.
Deterministic Trigger Invocation & Test Generation
Trigger the agent to generate isolated real-browser component test specs.
Direct the autonomous agent to create component specs using strict Playwright CT lifecycle hooks. The agent must use the fixture `mount` to inject the JSX component into the isolated browser context and test assertions against real layout bounding boxes and native pointer events.
import { test, expect } from '@playwright/experimental-ct-react';
import { Modal } from './Modal';
test.use({ viewport: { width: 500, height: 500 } });
test('should trap focus and dismiss on backdrop click', async ({ mount, page }) => {
let closed = false;
const component = await mount(
<Modal isOpen={true} title="Confirm Action" onClose={() => { closed = true; }}>
<p>Body Content</p>
</Modal>
);
await expect(component.getByRole('heading', { name: 'Confirm Action' })).toBeVisible();
// Test real browser pointer coordinates outside modal container
await page.mouse.click(10, 10);
expect(closed).toBe(true);
});Instruct the agent to utilize locator assertions (e.g., await expect(locator).toBeVisible()) instead of checking arbitrary boolean attributes to leverage Playwright's auto-retrying mechanism.
Agents commonly attempt to use React Testing Library methods like `fireEvent` inside Playwright CT specs. Explicitly disallow RTL imports.
Quality Gate & Cross-Browser Headless Execution
Run the Playwright CT runner to execute real-browser verification and assert return code 0.
Autonomous agents must run the validation gate prior to marking task completion. This ensures no bundler resolution errors, broken style imports, or unhandled browser exceptions occur.
pnpm exec playwright test -c playwright-ct.config.tsInstruct the agent to inspect the generated HTML report via `npx playwright show-report --outDir` only if failures occur, keeping token consumption clean.
When running inside containerized agent runtimes (like Docker or remote VMs), ensure the `--disable-dev-shm-usage` flag is configured in browser launch options if Chromium crashes unexpectedly.
Real-World Scenario: Testing Responsive Drawer Component with Real CSS Transitions and WebKit Layout
“mount component playwright ct: Create a real-browser component test for src/components/NavigationDrawer.tsx. Ensure it verifies that the drawer slides into the viewport on toggle, tests responsive layout at 375px mobile viewport, and passes WebKit rendering checks.”
Runtime Troubleshooting & Failure Modes
Root Cause: The Playwright CT runner failed to detect Vite or Webpack configuration in playwright-ct.config.ts or missing @playwright/experimental-ct-* dependencies.
pnpm add -D @playwright/experimental-ct-react vite && npx playwright test -c playwright-ct.config.ts --ct-bundler=viteRoot Cause: The agent execution sandbox lacks native Linux shared libraries required for headless Chromium and WebKit execution.
npx playwright install-depsFrequently Asked Questions (Playwright Component Testing (CT) for React & Vue SOP)
Q:Can I use Playwright Component Testing (CT) for React & Vue across Codex, Claude Code, and Cursor simultaneously?
Yes. The SKILL.md specification provides runtime-agnostic declarative prompts and execution constraints. Whether loaded into Claude Code CLI, Cursor Rules (.cursor/rules), Windsurf Cascades, or Codex Desktop, the agent interprets identical configuration structures and shell execution boundaries.
Q:How does Playwright Component Testing (CT) for React & Vue prevent context window overflow during long agent sessions?
Instead of dumping massive HTML DOM trees or mock object graphs into the context window, Playwright CT uses localized locators and native Playwright assertions that return concise boolean/error diffs. The agent receives only failing assertion line numbers and visual diff paths rather than tens of thousands of mock tokens.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It requires standard workspace read/write permissions to edit test files and execute non-root browser binaries bundled directly inside the local `node_modules` or user cache.
Ready to equip your autonomous agent with Playwright Component Testing (CT) for React & Vue?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.