stably 4.8.9 → 4.10.0
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.
- package/dist/index.mjs +1 -1
- package/dist/stably-plugin-cli/.claude-plugin/plugin.json +5 -0
- package/dist/stably-plugin-cli/skills/bash-commands/SKILL.md +65 -0
- package/dist/stably-plugin-cli/skills/browser-interaction-guide/SKILL.md +144 -0
- package/dist/stably-plugin-cli/skills/bulk-test-handling/SKILL.md +104 -0
- package/dist/stably-plugin-cli/skills/debugging-test-failures/SKILL.md +146 -0
- package/dist/{stably-plugin → stably-plugin-cli}/skills/playwright-best-practices/SKILL.md +11 -5
- package/dist/stably-plugin-cli/skills/playwright-config-auth/SKILL.md +217 -0
- package/dist/stably-plugin-cli/skills/stably-sdk-reference/SKILL.md +307 -0
- package/dist/stably-plugin-cli/skills/test-creation-workflow/SKILL.md +311 -0
- package/package.json +4 -1
- package/dist/stably-plugin/.claude-plugin/plugin.json +0 -5
- package/dist/stably-plugin/skills/playwright-best-practices/references/accessibility.md +0 -359
- package/dist/stably-plugin/skills/playwright-best-practices/references/annotations.md +0 -526
- package/dist/stably-plugin/skills/playwright-best-practices/references/assertions-waiting.md +0 -361
- package/dist/stably-plugin/skills/playwright-best-practices/references/browser-apis.md +0 -391
- package/dist/stably-plugin/skills/playwright-best-practices/references/browser-extensions.md +0 -506
- package/dist/stably-plugin/skills/playwright-best-practices/references/canvas-webgl.md +0 -493
- package/dist/stably-plugin/skills/playwright-best-practices/references/ci-cd.md +0 -407
- package/dist/stably-plugin/skills/playwright-best-practices/references/clock-mocking.md +0 -364
- package/dist/stably-plugin/skills/playwright-best-practices/references/component-testing.md +0 -500
- package/dist/stably-plugin/skills/playwright-best-practices/references/console-errors.md +0 -420
- package/dist/stably-plugin/skills/playwright-best-practices/references/debugging.md +0 -491
- package/dist/stably-plugin/skills/playwright-best-practices/references/electron.md +0 -509
- package/dist/stably-plugin/skills/playwright-best-practices/references/error-testing.md +0 -360
- package/dist/stably-plugin/skills/playwright-best-practices/references/file-operations.md +0 -375
- package/dist/stably-plugin/skills/playwright-best-practices/references/fixtures-hooks.md +0 -417
- package/dist/stably-plugin/skills/playwright-best-practices/references/flaky-tests.md +0 -494
- package/dist/stably-plugin/skills/playwright-best-practices/references/global-setup.md +0 -434
- package/dist/stably-plugin/skills/playwright-best-practices/references/i18n.md +0 -508
- package/dist/stably-plugin/skills/playwright-best-practices/references/iframes.md +0 -403
- package/dist/stably-plugin/skills/playwright-best-practices/references/locators.md +0 -242
- package/dist/stably-plugin/skills/playwright-best-practices/references/mobile-testing.md +0 -409
- package/dist/stably-plugin/skills/playwright-best-practices/references/multi-context.md +0 -288
- package/dist/stably-plugin/skills/playwright-best-practices/references/multi-user.md +0 -393
- package/dist/stably-plugin/skills/playwright-best-practices/references/network-advanced.md +0 -452
- package/dist/stably-plugin/skills/playwright-best-practices/references/page-object-model.md +0 -315
- package/dist/stably-plugin/skills/playwright-best-practices/references/performance-testing.md +0 -476
- package/dist/stably-plugin/skills/playwright-best-practices/references/performance.md +0 -453
- package/dist/stably-plugin/skills/playwright-best-practices/references/projects-dependencies.md +0 -456
- package/dist/stably-plugin/skills/playwright-best-practices/references/security-testing.md +0 -430
- package/dist/stably-plugin/skills/playwright-best-practices/references/service-workers.md +0 -504
- package/dist/stably-plugin/skills/playwright-best-practices/references/test-coverage.md +0 -495
- package/dist/stably-plugin/skills/playwright-best-practices/references/test-data.md +0 -492
- package/dist/stably-plugin/skills/playwright-best-practices/references/test-organization.md +0 -361
- package/dist/stably-plugin/skills/playwright-best-practices/references/third-party.md +0 -464
- package/dist/stably-plugin/skills/playwright-best-practices/references/websockets.md +0 -403
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test-creation-workflow
|
|
3
|
+
description: CLI workflow for creating Playwright test files with planning phase, User Prompt comments, linkId guardrails, and helper patterns. Use when creating new tests, planning test implementation, writing test skeletons, or creating helper functions. Triggers on new test, create test, plan test, User Prompt comment, helper function.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!-- CLI-ONLY SKILL: Proceeds directly to implementation after planning.
|
|
7
|
+
The web version uses AskUserQuestion for ambiguity and requires plan approval. -->
|
|
8
|
+
|
|
9
|
+
# Test Creation Workflow
|
|
10
|
+
|
|
11
|
+
Complete workflow for creating high-quality Playwright tests.
|
|
12
|
+
|
|
13
|
+
## Complexity Assessment (Do This First)
|
|
14
|
+
|
|
15
|
+
Before starting, classify the task:
|
|
16
|
+
|
|
17
|
+
| Complexity | Criteria | Planning Approach |
|
|
18
|
+
|------------|----------|-------------------|
|
|
19
|
+
| **Trivial** | ≤5 steps, public site, no auth, no SDK features | Skip formal planning. One-liner plan: "Navigate to X, assert Y, use Z project." |
|
|
20
|
+
| **Moderate** | 6-15 steps, OR auth required, OR SDK features | Lightweight plan: Summary + Assertion Matrix only |
|
|
21
|
+
| **Complex** | 15+ steps, multiple preconditions, helpers needed | Full planning phase (A-F + all matrices) |
|
|
22
|
+
|
|
23
|
+
**For trivial tasks:** Skip the full planning checklist. Just create the test file and implement directly.
|
|
24
|
+
|
|
25
|
+
## Workflow Overview
|
|
26
|
+
|
|
27
|
+
1. **Read context** - Understand existing test files, helpers, and config
|
|
28
|
+
2. **Plan** - Answer planning questions before implementing
|
|
29
|
+
3. **Create test file** - Under `tests/` with descriptive name
|
|
30
|
+
4. **Setup browser** - See `browser-interaction-guide` skill
|
|
31
|
+
5. **Implement flow** - Navigate and interact with browser
|
|
32
|
+
6. **Write intermediate code** - For long flows, checkpoint progress
|
|
33
|
+
7. **Verify with test_run** - Final verification required
|
|
34
|
+
8. **Create helpers** - Extract reusable patterns
|
|
35
|
+
|
|
36
|
+
## Planning Phase
|
|
37
|
+
|
|
38
|
+
Answer these questions before implementation.
|
|
39
|
+
|
|
40
|
+
### Planning Questions
|
|
41
|
+
|
|
42
|
+
**A. Intent Analysis**
|
|
43
|
+
- What is the intended behavior that needs testing?
|
|
44
|
+
- What user journey or feature is being validated?
|
|
45
|
+
- What is the success criteria for this test?
|
|
46
|
+
|
|
47
|
+
**B. Prerequisites Discovery**
|
|
48
|
+
- What test data is required? (users, products, specific states)
|
|
49
|
+
- What authentication/authorization is needed?
|
|
50
|
+
- What navigation steps are needed to reach the test starting point?
|
|
51
|
+
- Are there existing helpers that handle these prerequisites?
|
|
52
|
+
- **Hidden preconditions** (discover from source code):
|
|
53
|
+
* UI state (theme, dark mode, viewport size)
|
|
54
|
+
* Domain/data state (settings, configuration that must exist first)
|
|
55
|
+
* Feature flags, permissions, role/tenant gates
|
|
56
|
+
* Route/query parameters, deep link requirements
|
|
57
|
+
* Persisted client state (localStorage, cookies, session)
|
|
58
|
+
* Email verification steps (OTP codes, magic links, confirmation emails)
|
|
59
|
+
|
|
60
|
+
**C. Test Strategy**
|
|
61
|
+
- Is this test idempotent? (can run multiple times without side effects)
|
|
62
|
+
- How to make this test fast and reliable?
|
|
63
|
+
- What assertions provide the best coverage without being flaky?
|
|
64
|
+
- Are there edge cases worth covering in separate tests?
|
|
65
|
+
|
|
66
|
+
**D. Codebase Patterns**
|
|
67
|
+
- What existing test patterns should be followed?
|
|
68
|
+
- What helper functions can be reused?
|
|
69
|
+
- What naming conventions are used in this project?
|
|
70
|
+
|
|
71
|
+
**E. Assertion Quality & Flakiness Contract**
|
|
72
|
+
- What are the 2-4 critical outcomes that must be verified?
|
|
73
|
+
- For each outcome, what deterministic Playwright assertion will be used?
|
|
74
|
+
- For value-critical outcomes, what is the source of truth for the expected value?
|
|
75
|
+
- If an exact value cannot be known ahead of time, how will you control the value in setup?
|
|
76
|
+
- For each outcome, is `aiAssert` needed? If yes, why is Playwright-only assertion insufficient?
|
|
77
|
+
- Which assertions risk flakiness and how will you avoid it?
|
|
78
|
+
- **Auth setup**: Does the config have auth project dependencies? (See `playwright-config-auth` skill)
|
|
79
|
+
|
|
80
|
+
**BROWSER-VALIDATE BEFORE ASSERTING**: Do not assume text content - verify via browser first.
|
|
81
|
+
- Before writing text assertions, use `test_debug` or `browser_snapshot` to see actual content
|
|
82
|
+
- "I think the heading says X" is not verification - browser inspection is
|
|
83
|
+
- This prevents fix cycles from wrong text assumptions (e.g., "illustrative examples" vs "documentation examples")
|
|
84
|
+
|
|
85
|
+
**ANTI-HEDGING RULE**: If you discovered the expected value, assert that exact value.
|
|
86
|
+
- If the value is "1m 20s", assert `toHaveText("1m 20s")`, NOT a regex like `/\d+m\s+\d+s/`
|
|
87
|
+
- If the computed style is 12px, assert `toBe(12)`, NOT a range like `toBeLessThanOrEqual(14)`
|
|
88
|
+
- If the PR changes a background color, assert the background color, NOT class presence
|
|
89
|
+
- Regex, ranges, and presence checks are ONLY acceptable when the exact value is genuinely unknowable
|
|
90
|
+
|
|
91
|
+
**VERIFY DATA CLAIMS**: Precondition values from backend data must be verified through a source independent of the system under test.
|
|
92
|
+
- "I saw X in the browser" verifies the UI renders something, not that the underlying data is X
|
|
93
|
+
- This does NOT apply to deterministic code outputs (CSS values, hardcoded labels)
|
|
94
|
+
- It DOES apply to values from backend data, configuration, or data-routing decisions
|
|
95
|
+
- Verification must be an assertion: query the source, assert it equals expected, THEN assert UI matches
|
|
96
|
+
- If you cannot verify a precondition value, flag it as UNVERIFIED in ASSERTION MATRIX and OPEN UNKNOWNS
|
|
97
|
+
|
|
98
|
+
**F. Navigation Blueprint**
|
|
99
|
+
- What is the exact ordered navigation path from entry state to each critical assertion point?
|
|
100
|
+
- For each transition, what action triggers it and what locator strategy will be used?
|
|
101
|
+
- What deterministic readiness signal proves each transition succeeded?
|
|
102
|
+
|
|
103
|
+
### Output the Plan
|
|
104
|
+
|
|
105
|
+
Output plan in plain text with these sections:
|
|
106
|
+
- **Plan Summary**
|
|
107
|
+
- **Preconditions Matrix** (precondition, source evidence, setup action, verification check)
|
|
108
|
+
- **Assertion Matrix** (critical outcome, Playwright assertion(s), source of truth)
|
|
109
|
+
- **Flake Controls**
|
|
110
|
+
- **Open Unknowns**
|
|
111
|
+
|
|
112
|
+
### Assertion Type Selection
|
|
113
|
+
|
|
114
|
+
- **Standard Playwright assertions** (`toHaveText`, `toBeVisible`, `toHaveURL`): Use for simple, concrete checks
|
|
115
|
+
- **`aiAssert`**: Use for complex visual layouts, dynamic content, semantic meaning
|
|
116
|
+
|
|
117
|
+
Don't use `aiAssert` for things checkable with standard assertions.
|
|
118
|
+
|
|
119
|
+
### Assertion Timeouts
|
|
120
|
+
|
|
121
|
+
Prefer relying on Playwright's `expect.timeout` config setting rather than adding explicit timeouts.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Preferred - uses expect.timeout from playwright.config.ts
|
|
125
|
+
await expect(page.getByText('Welcome')).toBeVisible();
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Only add explicit timeouts for operations known to be slow (file uploads, video processing).
|
|
129
|
+
|
|
130
|
+
## Creating the Test File
|
|
131
|
+
|
|
132
|
+
Create test file under `tests/` with a descriptive name (e.g., `login-flow.spec.ts`).
|
|
133
|
+
|
|
134
|
+
- Do NOT put test cases in `seed.spec.ts` - it's just a placeholder
|
|
135
|
+
- Match existing test file conventions in the project
|
|
136
|
+
|
|
137
|
+
## User Prompt Comment
|
|
138
|
+
|
|
139
|
+
Every test must have a User Prompt comment recording the user's original request.
|
|
140
|
+
|
|
141
|
+
### Rules
|
|
142
|
+
|
|
143
|
+
- Every test must have one, no exceptions
|
|
144
|
+
- Write user's exact words - do not modify or rephrase
|
|
145
|
+
- Place directly above each test block
|
|
146
|
+
|
|
147
|
+
### Single Test Format
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { test, expect } from '@stablyai/playwright-test';
|
|
151
|
+
|
|
152
|
+
test.describe('User Flow Description', () => {
|
|
153
|
+
/**
|
|
154
|
+
* User Prompt:
|
|
155
|
+
* - <copy user's exact words here - no modifications>
|
|
156
|
+
*
|
|
157
|
+
* [Clarifications: (only include if questions were asked)]
|
|
158
|
+
* - <question topic>: <user's answer>
|
|
159
|
+
*/
|
|
160
|
+
test('descriptive test name', async ({ page }) => {
|
|
161
|
+
// test code
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Multiple Tests from One Prompt
|
|
167
|
+
|
|
168
|
+
When creating multiple tests from a single user prompt, split into common context + specific parts for each test:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
test.describe('User Flow Description', () => {
|
|
172
|
+
/**
|
|
173
|
+
* User Prompt:
|
|
174
|
+
* - <common context from user's prompt>
|
|
175
|
+
* - <specific part for this test>
|
|
176
|
+
*/
|
|
177
|
+
test('first test name', async ({ page }) => {
|
|
178
|
+
// test code
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* User Prompt:
|
|
183
|
+
* - <common context from user's prompt>
|
|
184
|
+
* - <specific part for this test>
|
|
185
|
+
*/
|
|
186
|
+
test('second test name', async ({ page }) => {
|
|
187
|
+
// test code
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### When Modifying Tests
|
|
193
|
+
|
|
194
|
+
- **Intent changed** (e.g., "change this test to also verify X"): Update the User Prompt comment
|
|
195
|
+
- **Intent unchanged** (e.g., "fix this error"): Do not modify the User Prompt comment
|
|
196
|
+
|
|
197
|
+
## linkId Guardrails
|
|
198
|
+
|
|
199
|
+
`@stably.linkId` is runtime-owned metadata in runnable test files (`.spec.*`/`.test.*`) only.
|
|
200
|
+
|
|
201
|
+
- Agent must never invent, rewrite, or delete `@stably.linkId`
|
|
202
|
+
- During regenerate/overwrite flows, preserve existing `@stably.linkId` header line exactly
|
|
203
|
+
- If no `@stably.linkId` exists, proceed with content edits but do not add a guessed ID
|
|
204
|
+
- Runtime finalize is responsible for inserting or validating `@stably.linkId`
|
|
205
|
+
- Do not finish with duplicate or malformed `@stably.linkId` headers
|
|
206
|
+
|
|
207
|
+
## Browser Setup
|
|
208
|
+
|
|
209
|
+
### Tool Decision Tree
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
What do you need to do?
|
|
213
|
+
├── Create/develop a test (keep browser open to see state)
|
|
214
|
+
│ └── Use: generator_setup_page
|
|
215
|
+
│ - Requires: seedFile with top-level test() call
|
|
216
|
+
│ - Browser stays open regardless of pass/fail
|
|
217
|
+
│
|
|
218
|
+
├── Debug a failing test (step through, inspect on failure)
|
|
219
|
+
│ └── Use: test_debug
|
|
220
|
+
│ - Browser closes on success, stays open on failure
|
|
221
|
+
│ - Good for iterative fix cycles
|
|
222
|
+
│
|
|
223
|
+
└── Verify a test passes (final validation)
|
|
224
|
+
└── Use: test_run
|
|
225
|
+
- Browser closes after run
|
|
226
|
+
- Use for final verification before completing task
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Common Mistake
|
|
230
|
+
|
|
231
|
+
`generator_setup_page` requires a seed file with a **top-level `test()` call**. Tests wrapped in `test.describe()` return "seed test not found".
|
|
232
|
+
|
|
233
|
+
**Workaround:** Use `tests/seed.spec.ts` as seedFile, then navigate manually with `browser_navigate`.
|
|
234
|
+
|
|
235
|
+
### Project Selection
|
|
236
|
+
|
|
237
|
+
For auth dependencies, see `playwright-config-auth` skill.
|
|
238
|
+
|
|
239
|
+
## Long User Flows (15+ actions)
|
|
240
|
+
|
|
241
|
+
For flows with more than 15 actions, checkpoint progress:
|
|
242
|
+
|
|
243
|
+
1. Reach a stable intermediate state
|
|
244
|
+
2. Call `generator_read_log` to retrieve action code
|
|
245
|
+
3. Write intermediate code with `generator_write_test`
|
|
246
|
+
- fileName must be a relative path (e.g., `tests/my-test.spec.ts`)
|
|
247
|
+
4. Use `test_debug` to verify intermediate code works
|
|
248
|
+
5. Repeat until entire flow is complete
|
|
249
|
+
|
|
250
|
+
## Helper Functions
|
|
251
|
+
|
|
252
|
+
### When to Create
|
|
253
|
+
|
|
254
|
+
Extract repetitive code patterns: login flows, navigation patterns, form filling, common assertions.
|
|
255
|
+
|
|
256
|
+
### Location & Naming
|
|
257
|
+
|
|
258
|
+
- Place in `tests/helpers/`
|
|
259
|
+
- Use format `<name>.helper.ts` (e.g., `login.helper.ts`)
|
|
260
|
+
|
|
261
|
+
### Requirements
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { Page } from '@playwright/test';
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Logs in a user with the provided credentials.
|
|
268
|
+
*/
|
|
269
|
+
export async function login({
|
|
270
|
+
page,
|
|
271
|
+
email,
|
|
272
|
+
password,
|
|
273
|
+
}: {
|
|
274
|
+
page: Page;
|
|
275
|
+
email: string;
|
|
276
|
+
password: string;
|
|
277
|
+
}): Promise<void> {
|
|
278
|
+
// implementation
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- Export functions with clear, descriptive names
|
|
283
|
+
- Use single-object parameters
|
|
284
|
+
- Include TypeScript types
|
|
285
|
+
- Add JSDoc comments
|
|
286
|
+
|
|
287
|
+
### Using Existing Helpers
|
|
288
|
+
|
|
289
|
+
Before creating new helpers, check `tests/helpers/` for existing ones.
|
|
290
|
+
|
|
291
|
+
### Debugging Helper Errors
|
|
292
|
+
|
|
293
|
+
1. Inspect other test files using the same helper to verify your usage pattern
|
|
294
|
+
2. If your implementation is correct, modify the helper itself
|
|
295
|
+
3. Only if steps 1-2 fail, eject helper code into your test or create new helper
|
|
296
|
+
|
|
297
|
+
## Final Verification
|
|
298
|
+
|
|
299
|
+
You must run `test_run` for final verification before the task is complete.
|
|
300
|
+
|
|
301
|
+
- A test without `test_run` verification is not finished
|
|
302
|
+
- If it fails, fix and run `test_run` again until it passes
|
|
303
|
+
- Use `test_debug` for development and debugging, `test_run` for final verification
|
|
304
|
+
|
|
305
|
+
For project selection guidance, see `playwright-config-auth` skill.
|
|
306
|
+
|
|
307
|
+
## Completion Checklist
|
|
308
|
+
|
|
309
|
+
- [ ] Test file created
|
|
310
|
+
- [ ] `test_run` executed and passed
|
|
311
|
+
- [ ] Self-review completed (if code was modified)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stably",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"packageManager": "pnpm@10.24.0",
|
|
5
5
|
"description": "AI-powered E2E Playwright testing CLI. Stably can understand your codebase, edit/run tests, and handle complex test scenarios for you.",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -91,7 +91,9 @@
|
|
|
91
91
|
"@stablyai/agent-tool-display": "workspace:*",
|
|
92
92
|
"@stablyai/agent-workspace-info": "workspace:*",
|
|
93
93
|
"@stablyai/ci-run-id": "0.1.1",
|
|
94
|
+
"@stablyai/email": "0.1.2",
|
|
94
95
|
"@stablyai/git-diff-tracker": "workspace:*",
|
|
96
|
+
"@stablyai/playwright-test": "2.1.10",
|
|
95
97
|
"@stablyai/playwright-trace-scrubber": "workspace:*",
|
|
96
98
|
"@stablyai/proxy": "workspace:*",
|
|
97
99
|
"@tsconfig/node20": "^20.1.4",
|
|
@@ -102,6 +104,7 @@
|
|
|
102
104
|
"dotenv-cli": "^11.0.0",
|
|
103
105
|
"execa": "^9.5.3",
|
|
104
106
|
"node-pty": "1.2.0-beta.10",
|
|
107
|
+
"playwright": "1.57.0",
|
|
105
108
|
"terser": "^5.44.1",
|
|
106
109
|
"tsup": "^8.5.0",
|
|
107
110
|
"tsx": "^4.20.5",
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
# Accessibility Testing
|
|
2
|
-
|
|
3
|
-
## Table of Contents
|
|
4
|
-
|
|
5
|
-
1. [Axe-Core Integration](#axe-core-integration)
|
|
6
|
-
2. [Keyboard Navigation](#keyboard-navigation)
|
|
7
|
-
3. [ARIA Validation](#aria-validation)
|
|
8
|
-
4. [Focus Management](#focus-management)
|
|
9
|
-
5. [Color & Contrast](#color--contrast)
|
|
10
|
-
|
|
11
|
-
## Axe-Core Integration
|
|
12
|
-
|
|
13
|
-
### Setup
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install -D @axe-core/playwright
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### Basic A11y Test
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { test, expect } from "@playwright/test";
|
|
23
|
-
import AxeBuilder from "@axe-core/playwright";
|
|
24
|
-
|
|
25
|
-
test("homepage should have no a11y violations", async ({ page }) => {
|
|
26
|
-
await page.goto("/");
|
|
27
|
-
|
|
28
|
-
const results = await new AxeBuilder({ page }).analyze();
|
|
29
|
-
|
|
30
|
-
expect(results.violations).toEqual([]);
|
|
31
|
-
});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Scoped Analysis
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
test("form accessibility", async ({ page }) => {
|
|
38
|
-
await page.goto("/contact");
|
|
39
|
-
|
|
40
|
-
// Analyze only the form
|
|
41
|
-
const results = await new AxeBuilder({ page })
|
|
42
|
-
.include("#contact-form")
|
|
43
|
-
.analyze();
|
|
44
|
-
|
|
45
|
-
expect(results.violations).toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("ignore known issues", async ({ page }) => {
|
|
49
|
-
await page.goto("/legacy-page");
|
|
50
|
-
|
|
51
|
-
const results = await new AxeBuilder({ page })
|
|
52
|
-
.exclude(".legacy-widget") // Skip legacy component
|
|
53
|
-
.disableRules(["color-contrast"]) // Disable specific rule
|
|
54
|
-
.analyze();
|
|
55
|
-
|
|
56
|
-
expect(results.violations).toEqual([]);
|
|
57
|
-
});
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### A11y Fixture
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
// fixtures/a11y.fixture.ts
|
|
64
|
-
import { test as base } from "@playwright/test";
|
|
65
|
-
import AxeBuilder from "@axe-core/playwright";
|
|
66
|
-
|
|
67
|
-
type A11yFixtures = {
|
|
68
|
-
makeAxeBuilder: () => AxeBuilder;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const test = base.extend<A11yFixtures>({
|
|
72
|
-
makeAxeBuilder: async ({ page }, use) => {
|
|
73
|
-
await use(() =>
|
|
74
|
-
new AxeBuilder({ page }).withTags([
|
|
75
|
-
"wcag2a",
|
|
76
|
-
"wcag2aa",
|
|
77
|
-
"wcag21a",
|
|
78
|
-
"wcag21aa",
|
|
79
|
-
]),
|
|
80
|
-
);
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Usage
|
|
85
|
-
test("dashboard a11y", async ({ page, makeAxeBuilder }) => {
|
|
86
|
-
await page.goto("/dashboard");
|
|
87
|
-
const results = await makeAxeBuilder().analyze();
|
|
88
|
-
expect(results.violations).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Detailed Violation Reporting
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
test("report a11y issues", async ({ page }) => {
|
|
96
|
-
await page.goto("/");
|
|
97
|
-
|
|
98
|
-
const results = await new AxeBuilder({ page }).analyze();
|
|
99
|
-
|
|
100
|
-
// Custom failure message with details
|
|
101
|
-
const violations = results.violations.map((v) => ({
|
|
102
|
-
id: v.id,
|
|
103
|
-
impact: v.impact,
|
|
104
|
-
description: v.description,
|
|
105
|
-
nodes: v.nodes.map((n) => n.html),
|
|
106
|
-
}));
|
|
107
|
-
|
|
108
|
-
expect(violations, JSON.stringify(violations, null, 2)).toHaveLength(0);
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Keyboard Navigation
|
|
113
|
-
|
|
114
|
-
### Tab Order Testing
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
test("correct tab order in form", async ({ page }) => {
|
|
118
|
-
await page.goto("/signup");
|
|
119
|
-
|
|
120
|
-
// Start from the beginning
|
|
121
|
-
await page.keyboard.press("Tab");
|
|
122
|
-
await expect(page.getByLabel("Email")).toBeFocused();
|
|
123
|
-
|
|
124
|
-
await page.keyboard.press("Tab");
|
|
125
|
-
await expect(page.getByLabel("Password")).toBeFocused();
|
|
126
|
-
|
|
127
|
-
await page.keyboard.press("Tab");
|
|
128
|
-
await expect(page.getByRole("button", { name: "Sign up" })).toBeFocused();
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Keyboard-Only Interaction
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
test("complete flow with keyboard only", async ({ page }) => {
|
|
136
|
-
await page.goto("/products");
|
|
137
|
-
|
|
138
|
-
// Navigate to product with keyboard
|
|
139
|
-
await page.keyboard.press("Tab"); // Skip to main content
|
|
140
|
-
await page.keyboard.press("Tab"); // First product
|
|
141
|
-
await page.keyboard.press("Enter"); // Open product
|
|
142
|
-
|
|
143
|
-
await expect(page).toHaveURL(/\/products\/\d+/);
|
|
144
|
-
|
|
145
|
-
// Add to cart with keyboard
|
|
146
|
-
await page.keyboard.press("Tab");
|
|
147
|
-
await page.keyboard.press("Tab"); // Navigate to "Add to Cart"
|
|
148
|
-
await page.keyboard.press("Enter");
|
|
149
|
-
|
|
150
|
-
await expect(page.getByRole("alert")).toContainText("Added to cart");
|
|
151
|
-
});
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Skip Links
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
test("skip link works", async ({ page }) => {
|
|
158
|
-
await page.goto("/");
|
|
159
|
-
|
|
160
|
-
await page.keyboard.press("Tab");
|
|
161
|
-
const skipLink = page.getByRole("link", { name: /skip to main/i });
|
|
162
|
-
await expect(skipLink).toBeFocused();
|
|
163
|
-
|
|
164
|
-
await page.keyboard.press("Enter");
|
|
165
|
-
|
|
166
|
-
// Focus should move to main content
|
|
167
|
-
await expect(page.getByRole("main")).toBeFocused();
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### Escape Key Handling
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
test("escape closes modal", async ({ page }) => {
|
|
175
|
-
await page.goto("/dashboard");
|
|
176
|
-
await page.getByRole("button", { name: "Settings" }).click();
|
|
177
|
-
|
|
178
|
-
const modal = page.getByRole("dialog");
|
|
179
|
-
await expect(modal).toBeVisible();
|
|
180
|
-
|
|
181
|
-
await page.keyboard.press("Escape");
|
|
182
|
-
|
|
183
|
-
await expect(modal).toBeHidden();
|
|
184
|
-
// Focus should return to trigger
|
|
185
|
-
await expect(page.getByRole("button", { name: "Settings" })).toBeFocused();
|
|
186
|
-
});
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## ARIA Validation
|
|
190
|
-
|
|
191
|
-
### Role Verification
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
test("correct ARIA roles", async ({ page }) => {
|
|
195
|
-
await page.goto("/dashboard");
|
|
196
|
-
|
|
197
|
-
// Verify landmark roles
|
|
198
|
-
await expect(page.getByRole("navigation")).toBeVisible();
|
|
199
|
-
await expect(page.getByRole("main")).toBeVisible();
|
|
200
|
-
await expect(page.getByRole("contentinfo")).toBeVisible(); // footer
|
|
201
|
-
|
|
202
|
-
// Verify interactive roles
|
|
203
|
-
await expect(page.getByRole("button", { name: "Menu" })).toBeVisible();
|
|
204
|
-
await expect(page.getByRole("search")).toBeVisible();
|
|
205
|
-
});
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
### ARIA States
|
|
209
|
-
|
|
210
|
-
```typescript
|
|
211
|
-
test("aria-expanded updates correctly", async ({ page }) => {
|
|
212
|
-
await page.goto("/faq");
|
|
213
|
-
|
|
214
|
-
const accordion = page.getByRole("button", { name: "Shipping" });
|
|
215
|
-
|
|
216
|
-
// Initially collapsed
|
|
217
|
-
await expect(accordion).toHaveAttribute("aria-expanded", "false");
|
|
218
|
-
|
|
219
|
-
await accordion.click();
|
|
220
|
-
|
|
221
|
-
// Now expanded
|
|
222
|
-
await expect(accordion).toHaveAttribute("aria-expanded", "true");
|
|
223
|
-
|
|
224
|
-
// Content is visible
|
|
225
|
-
const panel = page.getByRole("region", { name: "Shipping" });
|
|
226
|
-
await expect(panel).toBeVisible();
|
|
227
|
-
});
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### Live Regions
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
test("live region announces updates", async ({ page }) => {
|
|
234
|
-
await page.goto("/checkout");
|
|
235
|
-
|
|
236
|
-
// Find live region
|
|
237
|
-
const liveRegion = page.locator('[aria-live="polite"]');
|
|
238
|
-
|
|
239
|
-
await page.getByLabel("Quantity").fill("3");
|
|
240
|
-
|
|
241
|
-
// Live region should update with new total
|
|
242
|
-
await expect(liveRegion).toContainText("Total: $29.97");
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
## Focus Management
|
|
247
|
-
|
|
248
|
-
### Focus Trap in Modal
|
|
249
|
-
|
|
250
|
-
```typescript
|
|
251
|
-
test("focus trapped in modal", async ({ page }) => {
|
|
252
|
-
await page.goto("/");
|
|
253
|
-
await page.getByRole("button", { name: "Open Modal" }).click();
|
|
254
|
-
|
|
255
|
-
const modal = page.getByRole("dialog");
|
|
256
|
-
await expect(modal).toBeVisible();
|
|
257
|
-
|
|
258
|
-
// Get all focusable elements in modal
|
|
259
|
-
const focusableElements = modal.locator(
|
|
260
|
-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
|
|
261
|
-
);
|
|
262
|
-
const count = await focusableElements.count();
|
|
263
|
-
|
|
264
|
-
// Tab through all elements, should stay in modal
|
|
265
|
-
for (let i = 0; i < count + 1; i++) {
|
|
266
|
-
await page.keyboard.press("Tab");
|
|
267
|
-
const focused = page.locator(":focus");
|
|
268
|
-
await expect(modal).toContainText((await focused.textContent()) || "");
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Focus Restoration
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
test("focus returns after modal close", async ({ page }) => {
|
|
277
|
-
await page.goto("/");
|
|
278
|
-
|
|
279
|
-
const trigger = page.getByRole("button", { name: "Delete Item" });
|
|
280
|
-
await trigger.click();
|
|
281
|
-
|
|
282
|
-
await page.getByRole("button", { name: "Cancel" }).click();
|
|
283
|
-
|
|
284
|
-
// Focus should return to the trigger
|
|
285
|
-
await expect(trigger).toBeFocused();
|
|
286
|
-
});
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
## Color & Contrast
|
|
290
|
-
|
|
291
|
-
### High Contrast Mode
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
|
-
test("works in high contrast mode", async ({ page }) => {
|
|
295
|
-
await page.emulateMedia({ forcedColors: "active" });
|
|
296
|
-
await page.goto("/");
|
|
297
|
-
|
|
298
|
-
// Verify key elements are visible
|
|
299
|
-
await expect(page.getByRole("navigation")).toBeVisible();
|
|
300
|
-
await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible();
|
|
301
|
-
|
|
302
|
-
// Take screenshot for visual verification
|
|
303
|
-
await expect(page).toHaveScreenshot("high-contrast.png");
|
|
304
|
-
});
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### Reduced Motion
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
test("respects reduced motion preference", async ({ page }) => {
|
|
311
|
-
await page.emulateMedia({ reducedMotion: "reduce" });
|
|
312
|
-
await page.goto("/");
|
|
313
|
-
|
|
314
|
-
// Animations should be disabled
|
|
315
|
-
const hero = page.getByTestId("hero-animation");
|
|
316
|
-
const animation = await hero.evaluate(
|
|
317
|
-
(el) => getComputedStyle(el).animationDuration,
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
expect(animation).toBe("0s");
|
|
321
|
-
});
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
## CI Integration
|
|
325
|
-
|
|
326
|
-
### A11y as CI Gate
|
|
327
|
-
|
|
328
|
-
```typescript
|
|
329
|
-
// playwright.config.ts
|
|
330
|
-
export default defineConfig({
|
|
331
|
-
projects: [
|
|
332
|
-
{
|
|
333
|
-
name: "a11y",
|
|
334
|
-
testMatch: /.*\.a11y\.spec\.ts/,
|
|
335
|
-
use: { ...devices["Desktop Chrome"] },
|
|
336
|
-
},
|
|
337
|
-
],
|
|
338
|
-
});
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
```yaml
|
|
342
|
-
# .github/workflows/a11y.yml
|
|
343
|
-
- name: Run accessibility tests
|
|
344
|
-
run: npx playwright test --project=a11y
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
## Anti-Patterns to Avoid
|
|
348
|
-
|
|
349
|
-
| Anti-Pattern | Problem | Solution |
|
|
350
|
-
| ----------------------------- | ---------------------------- | ------------------------------------------ |
|
|
351
|
-
| Testing a11y only on homepage | Misses issues on other pages | Test all critical user flows |
|
|
352
|
-
| Ignoring all violations | No value from tests | Address or explicitly exclude known issues |
|
|
353
|
-
| Only automated testing | Misses many a11y issues | Combine with manual testing |
|
|
354
|
-
| Testing without screen reader | Misses interaction issues | Test with VoiceOver/NVDA periodically |
|
|
355
|
-
|
|
356
|
-
## Related References
|
|
357
|
-
|
|
358
|
-
- **Locators**: See [locators.md](locators.md) for role-based selectors
|
|
359
|
-
- **Visual testing**: See [test-organization.md](test-organization.md) for screenshot comparison
|