openspec-playwright 0.1.25 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
name: openspec-e2e
|
|
3
3
|
description: Run Playwright E2E verification for an OpenSpec change. Use when the user wants to validate that the implementation works end-to-end by running Playwright tests generated from the specs.
|
|
4
4
|
license: MIT
|
|
5
|
-
compatibility: Requires openspec CLI, Playwright (with browsers installed), and @playwright/mcp (globally installed via claude mcp add).
|
|
5
|
+
compatibility: Requires openspec CLI, Playwright (with browsers installed), and @playwright/mcp (globally installed via `claude mcp add playwright npx @playwright/mcp@latest`).
|
|
6
|
+
|
|
7
|
+
**Architecture**: Uses CLI + SKILLs (not `init-agents`). This follows Playwright's recommended approach for coding agents — CLI is more token-efficient than loading MCP tool schemas into context. MCP is used only for Healer (UI inspection on failure).
|
|
6
8
|
metadata:
|
|
7
9
|
author: openspec-playwright
|
|
8
|
-
version: "2.
|
|
10
|
+
version: "2.2"
|
|
9
11
|
---
|
|
10
12
|
|
|
11
13
|
Run Playwright E2E verification for an OpenSpec change. This skill reads specs from `openspec/changes/<name>/specs/`, generates test files, detects auth requirements, and delegates test execution to the `openspec-pw run` CLI.
|
|
@@ -56,16 +58,47 @@ Create `openspec/changes/<name>/specs/playwright/test-plan.md` by:
|
|
|
56
58
|
|
|
57
59
|
**Idempotency**: If test-plan.md already exists → read it, use it, do NOT regenerate unless user explicitly asks.
|
|
58
60
|
|
|
59
|
-
### 4. Generate test file
|
|
61
|
+
### 4. Generate test file (LLM-driven)
|
|
62
|
+
|
|
63
|
+
Use your file writing capability to create `tests/playwright/<name>.spec.ts`.
|
|
64
|
+
|
|
65
|
+
**Read inputs first**:
|
|
66
|
+
- `openspec/changes/<name>/specs/playwright/test-plan.md` — test cases with `@role` and `@auth` tags
|
|
67
|
+
- `tests/playwright/seed.spec.ts` — code pattern, BASE_URL, and page object structure
|
|
68
|
+
|
|
69
|
+
**Generate Playwright code** for each test case from test-plan.md:
|
|
70
|
+
- Follow the same structure as `seed.spec.ts`
|
|
71
|
+
- Prefer `data-testid` selectors; fallback to `input[name="..."]` or semantic selectors
|
|
72
|
+
- Include **happy path** AND **error/edge cases**
|
|
73
|
+
- Use `test.describe(...)` for grouping related tests
|
|
74
|
+
- Each test: `test('描述性名称', async ({ page }) => { ... })`
|
|
75
|
+
- Add `@project(user)` / `@project(admin)` on role-specific tests
|
|
76
|
+
|
|
77
|
+
**Example pattern** (from seed.spec.ts):
|
|
78
|
+
```typescript
|
|
79
|
+
import { test, expect } from '@playwright/test';
|
|
80
|
+
|
|
81
|
+
const BASE_URL = process.env.BASE_URL || 'http://localhost:3000';
|
|
82
|
+
|
|
83
|
+
test.describe('Feature Name', () => {
|
|
84
|
+
test('happy path - action succeeds', async ({ page }) => {
|
|
85
|
+
await page.goto(`${BASE_URL}/path`);
|
|
86
|
+
await page.getByTestId('element').click();
|
|
87
|
+
await expect(page.getByTestId('result')).toBeVisible();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('error case - invalid input shows message', async ({ page }) => {
|
|
91
|
+
await page.goto(`${BASE_URL}/path`);
|
|
92
|
+
await page.getByTestId('input').fill('invalid');
|
|
93
|
+
await page.getByTestId('submit').click();
|
|
94
|
+
await expect(page.getByTestId('error')).toContainText('Error text');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
```
|
|
60
98
|
|
|
61
|
-
|
|
62
|
-
- Follow the page object pattern from `tests/playwright/seed.spec.ts`
|
|
63
|
-
- Prefer `data-testid` selectors, fall back to semantic selectors
|
|
64
|
-
- Each test maps to one test case from the test-plan
|
|
65
|
-
- Use `@project(admin)` / `@project(user)` for role-specific tests
|
|
66
|
-
- Cover happy path AND key error paths
|
|
99
|
+
**Write the file** using the Write tool. If the file already exists → diff against test-plan, add only missing test cases, preserve existing implementations.
|
|
67
100
|
|
|
68
|
-
**
|
|
101
|
+
**Selector guidance**: If no `data-testid` exists in the app, prefer `getByRole`, `getByLabel`, `getByText` over fragile selectors like CSS paths.
|
|
69
102
|
|
|
70
103
|
### 5. Configure auth (if required)
|
|
71
104
|
|
|
@@ -109,16 +142,46 @@ The CLI handles:
|
|
|
109
142
|
- Port mismatch detection
|
|
110
143
|
- Report generation at `openspec/reports/playwright-e2e-<name>-<timestamp>.md`
|
|
111
144
|
|
|
112
|
-
If tests fail → analyze failures, use Playwright MCP tools to inspect UI state, fix selectors in the test file, and re-run.
|
|
145
|
+
If tests fail → analyze failures, use **Playwright MCP tools** to inspect UI state, fix selectors in the test file, and re-run.
|
|
146
|
+
|
|
147
|
+
**Healer MCP tools** (in order of use):
|
|
148
|
+
|
|
149
|
+
| Tool | Purpose |
|
|
150
|
+
|------|---------|
|
|
151
|
+
| `Navigate to a URL` | Go to the failing test's page |
|
|
152
|
+
| `Page snapshot` | Get page structure to find equivalent selectors |
|
|
153
|
+
| `Get console messages` | Diagnose JS errors that may cause failures |
|
|
154
|
+
| `Take a screenshot` | Visually compare before/after fixes |
|
|
155
|
+
| `Run Playwright code` | Execute custom fix logic (optional) |
|
|
156
|
+
|
|
157
|
+
**Healer workflow**:
|
|
158
|
+
1. Read the failing test file — identify the broken selector or assertion
|
|
159
|
+
2. Navigate to the target page with `Navigate to a URL`
|
|
160
|
+
3. Take a `Page snapshot` — find an equivalent stable selector
|
|
161
|
+
4. Fix the selector in the test file using the Edit tool
|
|
162
|
+
5. Re-run: `openspec-pw run <name>`
|
|
163
|
+
6. Repeat until pass or 3 attempts reached
|
|
164
|
+
|
|
165
|
+
**Note**: For selector fixes, prefer `getByRole`, `getByLabel`, `getByText` over CSS paths. For structural issues (wrong page content), update the assertion in the test file.
|
|
113
166
|
|
|
114
167
|
**Cap auto-heal attempts at 3** to prevent infinite loops.
|
|
115
168
|
|
|
116
169
|
### 8. Report results
|
|
117
170
|
|
|
118
|
-
Read the report
|
|
171
|
+
Read the report at `openspec/reports/playwright-e2e-<name>-<timestamp>.md`.
|
|
172
|
+
|
|
173
|
+
**Present results to user**:
|
|
119
174
|
- Summary table (tests run, passed, failed, duration, final status)
|
|
120
175
|
- Any auto-heal notes
|
|
121
|
-
- Recommendations for failed tests (with specific file:line references)
|
|
176
|
+
- Recommendations for failed tests (with specific `file:line` references)
|
|
177
|
+
|
|
178
|
+
**Update tasks.md** (if all tests pass):
|
|
179
|
+
- Read `openspec/changes/<name>/tasks.md`
|
|
180
|
+
- Find tasks related to E2E testing (look for `[ ]` items mentioning "test", "e2e", "playwright", "verify")
|
|
181
|
+
- Append a verification note: e.g. `✅ Verified via Playwright E2E (<timestamp>)`
|
|
182
|
+
- Write the updated content back using the Edit tool
|
|
183
|
+
|
|
184
|
+
**If tests fail**: Suggest which spec items remain unverified and what needs fixing.
|
|
122
185
|
|
|
123
186
|
---
|
|
124
187
|
|
|
@@ -133,6 +196,7 @@ Read the report generated by `openspec-pw run` and present it to the user:
|
|
|
133
196
|
|
|
134
197
|
- Read specs from `openspec/changes/<name>/specs/` as source of truth
|
|
135
198
|
- Do NOT generate tests that contradict the specs
|
|
199
|
+
- **DO generate real, runnable Playwright test code** — not placeholders or TODO comments. Every test case in test-plan.md must produce an actual `test(...)` block.
|
|
136
200
|
- Do NOT overwrite files outside: `specs/playwright/`, `tests/playwright/`, `openspec/reports/`, `playwright.config.ts`, `tests/auth.setup.ts`
|
|
137
201
|
- Cap auto-heal at 3 attempts
|
|
138
202
|
- If no change specified → always ask user to select
|
|
Binary file
|
package/package.json
CHANGED
package/release-notes.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
## What's Changed
|
|
2
2
|
|
|
3
|
-
-
|
|
3
|
+
- feat(skill): document Healer MCP tools and architecture rationale
|
|
4
4
|
|
|
5
|
-
**Full Changelog**: https://github.com/wxhou/openspec-playwright/releases/tag/v0.1.
|
|
5
|
+
**Full Changelog**: https://github.com/wxhou/openspec-playwright/releases/tag/v0.1.27
|
|
Binary file
|