---
name: cqa-export-playwright
description: Turn ContextQA test cases into a runnable Playwright TypeScript project. The MCP tool returns a file MANIFEST; this skill writes it to disk, installs, and validates. Typed steps become real Playwright; AI steps become clearly-marked manual checkpoints; credentials are exported in plain text — all per the export contract.
---

# ContextQA → Playwright export

`export_to_playwright` **does not write files** — the server has no access to your
machine. It returns a JSON **manifest** and this skill writes it locally, so the output
lands on *your* disk, not a pod's.

## The contract this implements

- **Typed steps** (click / enter / navigate / scroll / pressEnter / verifyTextContains)
  → real Playwright, using ContextQA's captured locators (alternates in comments).
- **AI Verification** → **assumed to pass**: a yellow banner, non-blocking (`aiVerify`).
  AI `IF` conditions therefore take the **true** branch (the ELSE is left as a comment).
- **AI Agent** actions → **not executable**: a red banner with a **Continue ▶** button;
  the run blocks until a human does the action and clicks Continue (`aiAgent`).
- **Reusable step groups** → expanded inline (recursively).
- **Loops** (FOR/WHILE) → rendered **once** with a note (supply iteration data manually).
- **Credentials** → **plain text** in `credentials.env`. Nothing is masked — but the
  generated project git-ignores that file so it isn't committed by accident.
- **Nothing is silently dropped:** a step with no usable locator, or an action the
  generator doesn't recognize, becomes a labelled manual `aiAgent` checkpoint.

## Steps

### 1. Pick the cases
The tool takes **`test_case_ids`** — the leaf cases you want as specs. Prerequisites and
step groups are pulled in and expanded automatically, so you only list the top-level cases.
Get the ids from `get_test_plans` (a plan's cases) or the reports UI
(`/td/{ws}/plans/{id}/reports`).

### 2. Call the tool
```
export_to_playwright(test_case_ids=[1545, 1546, ...], project_name="commscope-plan-66")
```
It returns:
```json
{ "project_name": "...", "file_count": N,
  "files": [ { "path": "package.json", "content": "..." }, ... ],
  "summary": { "specs": N, "cases_fetched": M, "credentials_present": ["URL","USERNAME","PASSWORD"] } }
```

### 3. Write the manifest to disk
Write each `files[].path` under a project dir — recommended `./exports/<tenant>/<id>/`.
**Because `credentials.env` is plain text, add `exports/` to the repo's `.gitignore`**
before writing, so customer credentials never get committed. Create parent dirs as needed.

### 4. Install and validate
```bash
cd exports/<tenant>/<id>
npm install
npx playwright install chromium
npx playwright test --list      # type-checks + enumerates; runs nothing
```
`--list` compiling cleanly is your "it's runnable" signal. Do **not** auto-run the suite —
it drives a real login against the customer app; that's the user's call.

### 5. Hand off — how to run it
```bash
npm test                         # headed; typed steps run, AI Agent steps show Continue ▶
AI_STEP_MODE=log npm test        # run typed steps end-to-end, AI Agent steps skipped
```
`AI_STEP_MODE`: `button` (default, in-page Continue) · `pause` (Playwright Inspector — use
if a manual action navigates away and removes the button) · `log` (skip & continue) ·
`fail` (throw, for CI).

## What to tell the user
- Which cases became **mostly manual** (AI-heavy source with few captured locators) vs.
  mostly automated — read it off the spec (`aiAgent` count vs. `page.locator` count). Be
  honest; don't imply full automation where the source is AI-driven.
- Login often redirects to SSO; **MFA, if enabled, is a manual step**.
- `credentials.env` holds a real credential in plain text — the user should scope/rotate
  the account accordingly.

## Companion skills
- `cqa-authoring-tests` — author runnable ContextQA cases (the inverse direction).
- `cqa-copy-test-case` — reconstruct a case across environments.
