openspec-playwright 0.1.44 → 0.1.45
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.
|
@@ -5,7 +5,7 @@ license: MIT
|
|
|
5
5
|
compatibility: Requires openspec CLI, Playwright (with browsers installed), and @playwright/mcp (globally installed via `claude mcp add playwright npx @playwright/mcp@latest`).
|
|
6
6
|
metadata:
|
|
7
7
|
author: openspec-playwright
|
|
8
|
-
version: "2.
|
|
8
|
+
version: "2.9"
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
## Input
|
|
@@ -23,11 +23,11 @@ metadata:
|
|
|
23
23
|
|
|
24
24
|
## Architecture
|
|
25
25
|
|
|
26
|
-
Pipeline: **Planner** (Step
|
|
26
|
+
Pipeline: **Planner** (Step 5) → **Generator** (Step 6) → **Healer** (Step 9).
|
|
27
27
|
|
|
28
|
-
Uses CLI + SKILLs (not `init-agents`). CLI is ~4x more token-efficient than loading MCP tool schemas. MCP is used
|
|
28
|
+
Uses CLI + SKILLs (not `init-agents`). CLI is ~4x more token-efficient than loading MCP tool schemas. MCP is used for **Explore** (Step 4, real DOM data) and **Healer** (UI inspection on failure).
|
|
29
29
|
|
|
30
|
-
**Schema owns templates. CLI handles execution. Skill handles cognitive work.**
|
|
30
|
+
**Schema owns templates. CLI handles execution. Skill handles cognitive work. Exploration drives generation.**
|
|
31
31
|
|
|
32
32
|
## Steps
|
|
33
33
|
|
|
@@ -74,25 +74,194 @@ This validates: app server reachable, auth fixtures initialized, Playwright work
|
|
|
74
74
|
|
|
75
75
|
**If seed test fails**: Stop and report. Fix the environment before proceeding.
|
|
76
76
|
|
|
77
|
-
### 4.
|
|
77
|
+
### 4. Explore application
|
|
78
|
+
|
|
79
|
+
**Before writing test plan, explore the app to collect real DOM data.** This is the most critical step — it eliminates blind selector guessing.
|
|
80
|
+
|
|
81
|
+
**Prerequisites**: seed test pass. If auth is required, ensure `auth.setup.ts` has been run (Step 7).
|
|
82
|
+
|
|
83
|
+
#### 4.1. Extract routes from specs
|
|
84
|
+
|
|
85
|
+
Read all files in `openspec/changes/<name>/specs/*.md`. Extract every URL, route, or path mentioned:
|
|
86
|
+
|
|
87
|
+
- Full URLs: `http://localhost:3000/dashboard`, `BASE_URL + /admin`
|
|
88
|
+
- Relative paths: `/dashboard`, `/api/auth/login`, `/admin/settings`
|
|
89
|
+
- Infer routes from text: "navigate to the dashboard" → check if `/dashboard` exists
|
|
90
|
+
|
|
91
|
+
Group routes by role:
|
|
92
|
+
- **Guest routes**: `/`, `/login`, `/about` (no auth needed)
|
|
93
|
+
- **Protected routes**: `/dashboard`, `/profile`, `/admin` (auth required)
|
|
94
|
+
|
|
95
|
+
#### 4.2. Explore each route via Playwright MCP
|
|
96
|
+
|
|
97
|
+
For each route, use these tools in order:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
browser_navigate → browser_snapshot → browser_take_screenshot
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**For guest routes** (no auth):
|
|
104
|
+
```javascript
|
|
105
|
+
// Navigate directly
|
|
106
|
+
await browser_navigate(`${BASE_URL}/<route>`)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**For protected routes** (auth required):
|
|
110
|
+
```javascript
|
|
111
|
+
// Option A: use existing storageState (recommended if auth.setup.ts already ran)
|
|
112
|
+
// Option B: navigate to /login first, fill form, then navigate to target
|
|
113
|
+
// Option C: use browser_run_code to set auth cookies directly
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Wait for page stability after navigation:
|
|
117
|
+
- Prefer waiting for a specific element: `browser_wait_for` with text or selector
|
|
118
|
+
- Avoid `networkidle` / `load` — they are too slow or unreliable
|
|
119
|
+
- Use a "page ready" signal: look for a heading, a loading spinner disappearing, or a URL change
|
|
120
|
+
|
|
121
|
+
#### 4.3. Parse the snapshot
|
|
122
|
+
|
|
123
|
+
From `browser_snapshot` output, extract **interactive elements** for each route:
|
|
124
|
+
|
|
125
|
+
| Element type | What to capture | Priority |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| **Buttons** | text, selector (`getByRole`, `getByLabel`, `data-testid`) | data-testid > role > label > text |
|
|
128
|
+
| **Form fields** | name, type, label, selector | data-testid > name > label |
|
|
129
|
+
| **Navigation links** | text, href, selector | text > href |
|
|
130
|
+
| **Headings** | text content, selector | for assertions |
|
|
131
|
+
| **Error messages** | text patterns, selector | for error path testing |
|
|
132
|
+
| **Dynamic content** | structure (not content) — row counts, card layouts | for data-driven tests |
|
|
133
|
+
|
|
134
|
+
**Selector strategy** (in priority order):
|
|
135
|
+
1. `[data-testid="..."]` — most stable, prefer these
|
|
136
|
+
2. `getByRole('button', { name: '...' })` — semantic, stable
|
|
137
|
+
3. `getByLabel('...')` — for form fields
|
|
138
|
+
4. `getByText('...')` — fallback, fragile
|
|
139
|
+
5. CSS selectors — last resort
|
|
140
|
+
|
|
141
|
+
#### 4.4. Write app-exploration.md
|
|
142
|
+
|
|
143
|
+
Output: `openspec/changes/<name>/specs/playwright/app-exploration.md`
|
|
144
|
+
|
|
145
|
+
```markdown
|
|
146
|
+
# App Exploration — <name>
|
|
147
|
+
Generated: <timestamp>
|
|
148
|
+
BASE_URL: <from env or seed.spec.ts>
|
|
149
|
+
|
|
150
|
+
## Route: /
|
|
151
|
+
- **Auth**: none
|
|
152
|
+
- **URL**: ${BASE_URL}/
|
|
153
|
+
- **Ready signal**: page has heading
|
|
154
|
+
- **Elements**:
|
|
155
|
+
- login link: `a:text("登录")`
|
|
156
|
+
- signup link: `[data-testid="signup-link"]`
|
|
157
|
+
- **Screenshot**: `__screenshots__/index.png`
|
|
158
|
+
|
|
159
|
+
## Route: /dashboard (user)
|
|
160
|
+
- **Auth**: required (storageState: playwright/.auth/user.json)
|
|
161
|
+
- **URL**: ${BASE_URL}/dashboard
|
|
162
|
+
- **Ready signal**: [data-testid="dashboard-heading"] visible
|
|
163
|
+
- **Elements**:
|
|
164
|
+
- heading: `[data-testid="page-title"]`
|
|
165
|
+
- logout btn: `[data-testid="logout-btn"]`
|
|
166
|
+
- profile form: `form >> input[name="displayName"]`
|
|
167
|
+
- settings link: `nav >> text=Settings`
|
|
168
|
+
- **Screenshot**: `__screenshots__/dashboard-user.png`
|
|
169
|
+
|
|
170
|
+
## Route: /admin (admin)
|
|
171
|
+
- **Auth**: required (storageState: playwright/.auth/admin.json)
|
|
172
|
+
- **URL**: ${BASE_URL}/admin
|
|
173
|
+
- **Ready signal**: [data-testid="admin-panel"] visible
|
|
174
|
+
- **Elements**:
|
|
175
|
+
- admin panel: `[data-testid="admin-panel"]`
|
|
176
|
+
- user table: `table#user-table tbody tr`
|
|
177
|
+
- add user btn: `[data-testid="add-user-btn"]`
|
|
178
|
+
- delete btn: `button:has-text("Delete")`
|
|
179
|
+
- **Screenshot**: `__screenshots__/admin-panel.png`
|
|
180
|
+
|
|
181
|
+
## Exploration Notes
|
|
182
|
+
- Route /admin → user gets redirected to /login (no admin role)
|
|
183
|
+
- /dashboard loads user-specific data (test assertions should use toContainText, not toHaveText)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### 4.5. Edge cases
|
|
187
|
+
|
|
188
|
+
| Situation | What to do |
|
|
189
|
+
|-----------|-----------|
|
|
190
|
+
| Route 404 | Mark as "⚠️ route not found — verify URL in specs" |
|
|
191
|
+
| Network error | Mark as "⚠️ unreachable — check if server is running" |
|
|
192
|
+
| Auth required, no storageState | Skip protected routes → note which routes need auth |
|
|
193
|
+
| SPA routing (URL changes but page doesn't reload) | Explore via navigation clicks from known routes, not direct URLs |
|
|
194
|
+
| Page loads but no interactive elements | Try waiting longer for SPA hydration |
|
|
195
|
+
| Dynamic content (user-specific) | Record structure, not content — use `toContainText`, not `toHaveText` |
|
|
196
|
+
|
|
197
|
+
**Idempotency**: If `app-exploration.md` already exists → read it, verify routes still match specs, update only new routes or changed pages.
|
|
198
|
+
|
|
199
|
+
#### 4.6. After exploration
|
|
200
|
+
|
|
201
|
+
Pass `app-exploration.md` to:
|
|
202
|
+
- **Step 5 (Planner)**: reference real routes, auth states, and elements in test-plan.md
|
|
203
|
+
- **Step 6 (Generator)**: use verified selectors instead of inferring
|
|
204
|
+
|
|
205
|
+
### 5. Generate test plan
|
|
78
206
|
|
|
79
207
|
Create `openspec/changes/<name>/specs/playwright/test-plan.md`:
|
|
208
|
+
|
|
209
|
+
**Read inputs first**:
|
|
210
|
+
- `openspec/changes/<name>/specs/*.md` — functional requirements
|
|
211
|
+
- `openspec/changes/<name>/specs/playwright/app-exploration.md` — **real routes and verified selectors**
|
|
212
|
+
|
|
213
|
+
Create test cases:
|
|
80
214
|
- List each functional requirement as a test case
|
|
81
215
|
- Mark with `@role(user|admin|guest|none)` and `@auth(required|none)`
|
|
82
216
|
- Include happy path AND error paths
|
|
83
|
-
- Reference the route
|
|
217
|
+
- Reference the **real route URL** from app-exploration.md for each test
|
|
218
|
+
- Reference **verified selectors** from app-exploration.md instead of inferring
|
|
219
|
+
|
|
220
|
+
```markdown
|
|
221
|
+
### User can view dashboard
|
|
222
|
+
- **Route**: /dashboard (from app-exploration.md)
|
|
223
|
+
- **Auth**: required (user storageState)
|
|
224
|
+
- **Test steps**:
|
|
225
|
+
1. Go to `/dashboard`
|
|
226
|
+
2. Assert page heading: `[data-testid="page-title"]` contains "Dashboard"
|
|
227
|
+
3. Assert logout button visible: `[data-testid="logout-btn"]`
|
|
228
|
+
```
|
|
84
229
|
|
|
85
230
|
**Idempotency**: If test-plan.md already exists → read it, use it, do NOT regenerate.
|
|
86
231
|
|
|
87
|
-
###
|
|
232
|
+
### 6. Generate test file
|
|
88
233
|
|
|
89
234
|
Create `tests/playwright/<name>.spec.ts`:
|
|
90
235
|
|
|
91
236
|
**Read inputs first**:
|
|
92
|
-
- `openspec/changes/<name>/specs/playwright/test-plan.md`
|
|
93
|
-
- `
|
|
237
|
+
- `openspec/changes/<name>/specs/playwright/test-plan.md` — test cases
|
|
238
|
+
- `openspec/changes/<name>/specs/playwright/app-exploration.md` — **verified routes and selectors**
|
|
239
|
+
- `tests/playwright/seed.spec.ts` — code pattern and page object structure
|
|
240
|
+
|
|
241
|
+
#### Verify selectors before writing
|
|
242
|
+
|
|
243
|
+
**For each test case, verify selectors in a real browser BEFORE writing the test code.** This is the most important step — do not skip it.
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
For each test case in test-plan.md:
|
|
247
|
+
|
|
248
|
+
1. Determine target route (from app-exploration.md)
|
|
249
|
+
2. Determine auth state (load storageState if @auth(required))
|
|
250
|
+
3. Navigate: browser_navigate to the route
|
|
251
|
+
4. Wait for page ready: browser_wait_for with a key element
|
|
252
|
+
5. Verify: browser_snapshot to confirm page loaded
|
|
253
|
+
6. For each selector in the test case:
|
|
254
|
+
a. Check if selector exists in app-exploration.md
|
|
255
|
+
b. If yes → verify it's still valid via browser_snapshot
|
|
256
|
+
c. If no → find equivalent from current snapshot
|
|
257
|
+
d. Selector priority: data-testid > getByRole > getByLabel > getByText
|
|
258
|
+
7. Write test code with verified selectors
|
|
259
|
+
8. If selector cannot be verified → note it for Healer (Step 9)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
This ensures every selector in the generated test code has been validated against the live DOM.
|
|
94
263
|
|
|
95
|
-
**Generate** Playwright code for each test case:
|
|
264
|
+
**Generate** Playwright code for each verified test case:
|
|
96
265
|
- Follow `seed.spec.ts` structure
|
|
97
266
|
- Prefer `data-testid`; fallback to `getByRole`, `getByLabel`, `getByText`
|
|
98
267
|
- Include happy path AND error/edge cases
|
|
@@ -183,7 +352,7 @@ await page.getByRole('button', { name: 'Submit' }).click();
|
|
|
183
352
|
|
|
184
353
|
If the file exists → diff against test-plan, add only missing test cases.
|
|
185
354
|
|
|
186
|
-
###
|
|
355
|
+
### 7. Configure auth (if required)
|
|
187
356
|
|
|
188
357
|
- **API login**: Generate `auth.setup.ts` using `E2E_USERNAME`/`E2E_PASSWORD` + POST to login endpoint
|
|
189
358
|
- **UI login**: Generate `auth.setup.ts` using browser form fill. Update selectors to match your login page
|
|
@@ -206,7 +375,7 @@ Auth required. To set up:
|
|
|
206
375
|
|
|
207
376
|
**Idempotency**: If `auth.setup.ts` already exists → verify format, update only if stale.
|
|
208
377
|
|
|
209
|
-
###
|
|
378
|
+
### 8. Configure playwright.config.ts
|
|
210
379
|
|
|
211
380
|
If missing → generate from `openspec/schemas/playwright-e2e/templates/playwright.config.ts`.
|
|
212
381
|
|
|
@@ -222,7 +391,7 @@ If missing → generate from `openspec/schemas/playwright-e2e/templates/playwrig
|
|
|
222
391
|
|
|
223
392
|
If playwright.config.ts exists → READ first, preserve ALL existing fields, add only missing `webServer` block.
|
|
224
393
|
|
|
225
|
-
###
|
|
394
|
+
### 9. Execute tests
|
|
226
395
|
|
|
227
396
|
```bash
|
|
228
397
|
openspec-pw run <name> --project=<role>
|
|
@@ -260,7 +429,7 @@ If tests fail → use Playwright MCP tools to inspect UI, fix selectors, re-run.
|
|
|
260
429
|
3. **Attempt heal** (≤3 times): snapshot → fix → re-run
|
|
261
430
|
4. **After 3 failures**: collect evidence checklist → `test.skip()` if app bug, report recommendation if test bug
|
|
262
431
|
|
|
263
|
-
###
|
|
432
|
+
### 10. False Pass Detection
|
|
264
433
|
|
|
265
434
|
Run after test suite completes (even if all pass):
|
|
266
435
|
|
|
@@ -270,7 +439,7 @@ Run after test suite completes (even if all pass):
|
|
|
270
439
|
|
|
271
440
|
Report any gaps in a **⚠️ Coverage Gap** section.
|
|
272
441
|
|
|
273
|
-
###
|
|
442
|
+
### 11. Report results
|
|
274
443
|
|
|
275
444
|
Read report at `openspec/reports/playwright-e2e-<name>-<timestamp>.md`. Present:
|
|
276
445
|
- Summary table (tests, passed, failed, duration, status)
|
|
@@ -324,6 +493,7 @@ Read report at `openspec/reports/playwright-e2e-<name>-<timestamp>.md`. Present:
|
|
|
324
493
|
| No specs | Stop — E2E requires specs |
|
|
325
494
|
| Seed test fails | Stop — fix environment |
|
|
326
495
|
| No auth required | Skip auth setup |
|
|
496
|
+
| app-exploration.md exists | Read and use (never regenerate) |
|
|
327
497
|
| test-plan.md exists | Read and use (never regenerate) |
|
|
328
498
|
| auth.setup.ts exists | Verify format (update only if stale) |
|
|
329
499
|
| playwright.config.ts exists | Preserve all fields (add only missing) |
|
|
@@ -337,6 +507,7 @@ Read report at `openspec/reports/playwright-e2e-<name>-<timestamp>.md`. Present:
|
|
|
337
507
|
- Read specs from `openspec/changes/<name>/specs/` as source of truth
|
|
338
508
|
- Do NOT generate tests that contradict the specs
|
|
339
509
|
- **DO generate real, runnable Playwright test code** — not placeholders or TODOs
|
|
340
|
-
- Do NOT overwrite files outside: `specs/playwright/`, `tests/playwright/`, `openspec/reports/`, `playwright.config.ts`
|
|
510
|
+
- Do NOT overwrite files outside: `specs/playwright/`, `tests/playwright/`, `openspec/reports/`, `playwright.config.ts`, `auth.setup.ts`, `app-exploration.md`
|
|
511
|
+
- **Always explore before generating** — Step 4 is mandatory for accurate selectors
|
|
341
512
|
- Cap auto-heal at 3 attempts
|
|
342
513
|
- 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
|
-
- feat(SKILL): add
|
|
3
|
+
- feat(SKILL): add Step 4 Explore Application with real DOM data
|
|
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.45
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# App Exploration — <change-name>
|
|
2
|
+
|
|
3
|
+
Generated: <timestamp>
|
|
4
|
+
BASE_URL: <from env or seed.spec.ts>
|
|
5
|
+
|
|
6
|
+
## Exploration Summary
|
|
7
|
+
|
|
8
|
+
| Route | Auth | Status | Ready Signal |
|
|
9
|
+
|-------|------|--------|-------------|
|
|
10
|
+
| / | none | ✅ explored | page has heading |
|
|
11
|
+
| /login | none | ✅ explored | [data-testid="login-form"] visible |
|
|
12
|
+
| /dashboard | required (user) | ✅ explored | [data-testid="page-title"] visible |
|
|
13
|
+
| /admin | required (admin) | ✅ explored | [data-testid="admin-panel"] visible |
|
|
14
|
+
|
|
15
|
+
## Route: <path>
|
|
16
|
+
|
|
17
|
+
- **Auth**: none / required (storageState: <path>)
|
|
18
|
+
- **URL**: ${BASE_URL}<path>
|
|
19
|
+
- **Ready signal**: <how to know page is loaded>
|
|
20
|
+
- **Screenshot**: `__screenshots__/<path-slug>.png`
|
|
21
|
+
|
|
22
|
+
### Interactive Elements (from real DOM)
|
|
23
|
+
|
|
24
|
+
| Element | Selector | Notes |
|
|
25
|
+
|---------|----------|-------|
|
|
26
|
+
| heading | `[data-testid="..."]` or `h1` | |
|
|
27
|
+
| submit btn | `getByRole('button', { name: '...' })` | |
|
|
28
|
+
| logout btn | `[data-testid="logout-btn"]` | |
|
|
29
|
+
| form | `form >> input[name="..."]` | |
|
|
30
|
+
| nav link | `a:text("...")` or `nav >> text=...` | |
|
|
31
|
+
|
|
32
|
+
### Navigation Context
|
|
33
|
+
|
|
34
|
+
- How to reach this page: <from homepage / from dashboard / etc.>
|
|
35
|
+
- Redirects: <any redirects observed>
|
|
36
|
+
|
|
37
|
+
### Dynamic Content Notes
|
|
38
|
+
|
|
39
|
+
- <any dynamic content that was observed>
|
|
40
|
+
- <test assertions should use toContainText, not toHaveText for user-specific data>
|
|
41
|
+
|
|
42
|
+
## Exploration Failures
|
|
43
|
+
|
|
44
|
+
| Route | Error | Notes |
|
|
45
|
+
|-------|-------|-------|
|
|
46
|
+
| | | |
|
|
47
|
+
|
|
48
|
+
## Next Steps
|
|
49
|
+
|
|
50
|
+
After exploration, pass this file to Step 5 (Planner) and Step 6 (Generator).
|
|
Binary file
|