stably 4.5.3 → 4.5.4
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.js +1 -1
- package/dist/stably-plugin/.claude-plugin/plugin.json +5 -0
- package/dist/stably-plugin/skills/playwright-best-practices/SKILL.md +235 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/accessibility.md +359 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/annotations.md +423 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/assertions-waiting.md +361 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/browser-apis.md +391 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/browser-extensions.md +506 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/canvas-webgl.md +493 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/ci-cd.md +407 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/clock-mocking.md +364 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/component-testing.md +500 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/console-errors.md +420 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/debugging.md +491 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/electron.md +509 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/error-testing.md +360 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/file-operations.md +375 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/fixtures-hooks.md +417 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/flaky-tests.md +494 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/global-setup.md +434 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/i18n.md +508 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/iframes.md +403 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/locators.md +242 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/mobile-testing.md +409 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/multi-context.md +288 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/multi-user.md +393 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/network-advanced.md +452 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/page-object-model.md +315 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/performance-testing.md +476 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/performance.md +453 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/projects-dependencies.md +456 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/security-testing.md +430 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/service-workers.md +504 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/test-coverage.md +495 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/test-data.md +492 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/test-organization.md +361 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/third-party.md +464 -0
- package/dist/stably-plugin/skills/playwright-best-practices/references/websockets.md +403 -0
- package/package.json +2 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: playwright-best-practices
|
|
3
|
+
description: Provides comprehensive guidance for writing, debugging, and maintaining Playwright tests in TypeScript. Use when writing Playwright tests, fixing flaky tests, debugging failures, implementing Page Object Model, configuring CI/CD, optimizing performance, mocking APIs, handling authentication or OAuth, testing accessibility (axe-core), file uploads/downloads, date/time mocking, WebSockets, geolocation, permissions, multi-tab/popup flows, mobile/responsive layouts, touch gestures, GraphQL, error handling, offline mode, multi-user collaboration, third-party services (payments, email verification), console error monitoring, global setup/teardown, test annotations (skip, fixme, slow), project dependencies, security testing (XSS, CSRF, auth), performance budgets (Web Vitals, Lighthouse), iframes, component testing, canvas/WebGL, service workers/PWA, test coverage, i18n/localization, Electron apps, or browser extension testing. Covers E2E, component, API, visual, accessibility, security, Electron, and extension testing.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: currents.dev
|
|
7
|
+
version: "1.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Playwright Best Practices
|
|
11
|
+
|
|
12
|
+
This skill provides comprehensive guidance for all aspects of Playwright test development, from writing new tests to debugging and maintaining existing test suites.
|
|
13
|
+
|
|
14
|
+
## Activity-Based Reference Guide
|
|
15
|
+
|
|
16
|
+
Consult these references based on what you're doing:
|
|
17
|
+
|
|
18
|
+
### Writing New Tests
|
|
19
|
+
|
|
20
|
+
**When to use**: Creating new test files, writing test cases, implementing test scenarios
|
|
21
|
+
|
|
22
|
+
| Activity | Reference Files |
|
|
23
|
+
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| **Writing E2E tests** | [test-organization.md](references/test-organization.md), [locators.md](references/locators.md), [assertions-waiting.md](references/assertions-waiting.md) |
|
|
25
|
+
| **Writing component tests** | [component-testing.md](references/component-testing.md), [test-organization.md](references/test-organization.md) |
|
|
26
|
+
| **Writing API tests** | [test-organization.md](references/test-organization.md), [assertions-waiting.md](references/assertions-waiting.md) |
|
|
27
|
+
| **Writing visual regression tests** | [test-organization.md](references/test-organization.md), [canvas-webgl.md](references/canvas-webgl.md) |
|
|
28
|
+
| **Structuring test code with POM** | [page-object-model.md](references/page-object-model.md), [test-organization.md](references/test-organization.md) |
|
|
29
|
+
| **Setting up test data/fixtures** | [fixtures-hooks.md](references/fixtures-hooks.md), [test-data.md](references/test-data.md) |
|
|
30
|
+
| **Handling authentication** | [fixtures-hooks.md](references/fixtures-hooks.md), [third-party.md](references/third-party.md) |
|
|
31
|
+
| **Testing date/time features** | [clock-mocking.md](references/clock-mocking.md) |
|
|
32
|
+
| **Testing file upload/download** | [file-operations.md](references/file-operations.md) |
|
|
33
|
+
| **Testing accessibility** | [accessibility.md](references/accessibility.md) |
|
|
34
|
+
| **Testing security (XSS, CSRF)** | [security-testing.md](references/security-testing.md) |
|
|
35
|
+
| **Using test annotations** | [annotations.md](references/annotations.md) |
|
|
36
|
+
| **Testing iframes** | [iframes.md](references/iframes.md) |
|
|
37
|
+
| **Testing canvas/WebGL** | [canvas-webgl.md](references/canvas-webgl.md) |
|
|
38
|
+
| **Internationalization (i18n)** | [i18n.md](references/i18n.md) |
|
|
39
|
+
| **Testing Electron apps** | [electron.md](references/electron.md) |
|
|
40
|
+
| **Testing browser extensions** | [browser-extensions.md](references/browser-extensions.md) |
|
|
41
|
+
|
|
42
|
+
### Mobile & Responsive Testing
|
|
43
|
+
|
|
44
|
+
**When to use**: Testing mobile devices, touch interactions, responsive layouts
|
|
45
|
+
|
|
46
|
+
| Activity | Reference Files |
|
|
47
|
+
| ------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
48
|
+
| **Device emulation** | [mobile-testing.md](references/mobile-testing.md) |
|
|
49
|
+
| **Touch gestures (swipe, tap)** | [mobile-testing.md](references/mobile-testing.md) |
|
|
50
|
+
| **Viewport/breakpoint testing** | [mobile-testing.md](references/mobile-testing.md) |
|
|
51
|
+
| **Mobile-specific UI** | [mobile-testing.md](references/mobile-testing.md), [locators.md](references/locators.md) |
|
|
52
|
+
|
|
53
|
+
### Real-Time & Browser APIs
|
|
54
|
+
|
|
55
|
+
**When to use**: Testing WebSockets, geolocation, permissions, multi-tab flows
|
|
56
|
+
|
|
57
|
+
| Activity | Reference Files |
|
|
58
|
+
| ------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
59
|
+
| **WebSocket/real-time testing** | [websockets.md](references/websockets.md) |
|
|
60
|
+
| **Geolocation mocking** | [browser-apis.md](references/browser-apis.md) |
|
|
61
|
+
| **Permission handling** | [browser-apis.md](references/browser-apis.md) |
|
|
62
|
+
| **Clipboard testing** | [browser-apis.md](references/browser-apis.md) |
|
|
63
|
+
| **Camera/microphone mocking** | [browser-apis.md](references/browser-apis.md) |
|
|
64
|
+
| **Multi-tab/popup flows** | [multi-context.md](references/multi-context.md) |
|
|
65
|
+
| **OAuth popup handling** | [third-party.md](references/third-party.md), [multi-context.md](references/multi-context.md) |
|
|
66
|
+
|
|
67
|
+
### Debugging & Troubleshooting
|
|
68
|
+
|
|
69
|
+
**When to use**: Test failures, element not found, timeouts, unexpected behavior
|
|
70
|
+
|
|
71
|
+
| Activity | Reference Files |
|
|
72
|
+
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| **Debugging test failures** | [debugging.md](references/debugging.md), [assertions-waiting.md](references/assertions-waiting.md) |
|
|
74
|
+
| **Fixing flaky tests** | [flaky-tests.md](references/flaky-tests.md), [debugging.md](references/debugging.md), [assertions-waiting.md](references/assertions-waiting.md) |
|
|
75
|
+
| **Debugging flaky parallel runs** | [flaky-tests.md](references/flaky-tests.md), [performance.md](references/performance.md), [fixtures-hooks.md](references/fixtures-hooks.md) |
|
|
76
|
+
| **Ensuring test isolation / avoiding state leak** | [flaky-tests.md](references/flaky-tests.md), [fixtures-hooks.md](references/fixtures-hooks.md), [performance.md](references/performance.md) |
|
|
77
|
+
| **Fixing selector issues** | [locators.md](references/locators.md), [debugging.md](references/debugging.md) |
|
|
78
|
+
| **Investigating timeout issues** | [assertions-waiting.md](references/assertions-waiting.md), [debugging.md](references/debugging.md) |
|
|
79
|
+
| **Using trace viewer** | [debugging.md](references/debugging.md) |
|
|
80
|
+
| **Debugging race conditions** | [flaky-tests.md](references/flaky-tests.md), [debugging.md](references/debugging.md), [assertions-waiting.md](references/assertions-waiting.md) |
|
|
81
|
+
| **Debugging console/JS errors** | [console-errors.md](references/console-errors.md), [debugging.md](references/debugging.md) |
|
|
82
|
+
|
|
83
|
+
### Error & Edge Case Testing
|
|
84
|
+
|
|
85
|
+
**When to use**: Testing error states, offline mode, network failures, validation
|
|
86
|
+
|
|
87
|
+
| Activity | Reference Files |
|
|
88
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------ |
|
|
89
|
+
| **Error boundary testing** | [error-testing.md](references/error-testing.md) |
|
|
90
|
+
| **Network failure simulation** | [error-testing.md](references/error-testing.md), [network-advanced.md](references/network-advanced.md) |
|
|
91
|
+
| **Offline mode testing** | [error-testing.md](references/error-testing.md), [service-workers.md](references/service-workers.md) |
|
|
92
|
+
| **Service worker testing** | [service-workers.md](references/service-workers.md) |
|
|
93
|
+
| **Loading state testing** | [error-testing.md](references/error-testing.md) |
|
|
94
|
+
| **Form validation testing** | [error-testing.md](references/error-testing.md) |
|
|
95
|
+
|
|
96
|
+
### Multi-User & Collaboration Testing
|
|
97
|
+
|
|
98
|
+
**When to use**: Testing features involving multiple users, roles, or real-time collaboration
|
|
99
|
+
|
|
100
|
+
| Activity | Reference Files |
|
|
101
|
+
| ------------------------------ | ------------------------------------------------------------------------------------ |
|
|
102
|
+
| **Multiple users in one test** | [multi-user.md](references/multi-user.md) |
|
|
103
|
+
| **Real-time collaboration** | [multi-user.md](references/multi-user.md), [websockets.md](references/websockets.md) |
|
|
104
|
+
| **Role-based access testing** | [multi-user.md](references/multi-user.md) |
|
|
105
|
+
| **Concurrent action testing** | [multi-user.md](references/multi-user.md) |
|
|
106
|
+
|
|
107
|
+
### Refactoring & Maintenance
|
|
108
|
+
|
|
109
|
+
**When to use**: Improving existing tests, code review, reducing duplication
|
|
110
|
+
|
|
111
|
+
| Activity | Reference Files |
|
|
112
|
+
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
113
|
+
| **Refactoring to Page Object Model** | [page-object-model.md](references/page-object-model.md), [test-organization.md](references/test-organization.md) |
|
|
114
|
+
| **Improving test organization** | [test-organization.md](references/test-organization.md), [page-object-model.md](references/page-object-model.md) |
|
|
115
|
+
| **Extracting common setup/teardown** | [fixtures-hooks.md](references/fixtures-hooks.md) |
|
|
116
|
+
| **Replacing brittle selectors** | [locators.md](references/locators.md) |
|
|
117
|
+
| **Removing explicit waits** | [assertions-waiting.md](references/assertions-waiting.md) |
|
|
118
|
+
| **Creating test data factories** | [test-data.md](references/test-data.md) |
|
|
119
|
+
|
|
120
|
+
### Infrastructure & Configuration
|
|
121
|
+
|
|
122
|
+
**When to use**: Setting up projects, configuring CI/CD, optimizing performance
|
|
123
|
+
|
|
124
|
+
| Activity | Reference Files |
|
|
125
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
126
|
+
| **Configuring Playwright project** | [test-organization.md](references/test-organization.md), [projects-dependencies.md](references/projects-dependencies.md) |
|
|
127
|
+
| **Setting up CI/CD pipelines** | [ci-cd.md](references/ci-cd.md), [performance.md](references/performance.md) |
|
|
128
|
+
| **Global setup & teardown** | [global-setup.md](references/global-setup.md) |
|
|
129
|
+
| **Project dependencies** | [projects-dependencies.md](references/projects-dependencies.md) |
|
|
130
|
+
| **Optimizing test performance** | [performance.md](references/performance.md), [test-organization.md](references/test-organization.md) |
|
|
131
|
+
| **Configuring parallel execution** | [performance.md](references/performance.md) |
|
|
132
|
+
| **Isolating test data between workers** | [fixtures-hooks.md](references/fixtures-hooks.md), [performance.md](references/performance.md) |
|
|
133
|
+
| **Test coverage** | [test-coverage.md](references/test-coverage.md) |
|
|
134
|
+
|
|
135
|
+
### Advanced Patterns
|
|
136
|
+
|
|
137
|
+
**When to use**: Complex scenarios, API mocking, network interception
|
|
138
|
+
|
|
139
|
+
| Activity | Reference Files |
|
|
140
|
+
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| **Mocking API responses** | [test-organization.md](references/test-organization.md), [network-advanced.md](references/network-advanced.md) |
|
|
142
|
+
| **Network interception** | [network-advanced.md](references/network-advanced.md), [assertions-waiting.md](references/assertions-waiting.md) |
|
|
143
|
+
| **GraphQL mocking** | [network-advanced.md](references/network-advanced.md) |
|
|
144
|
+
| **HAR recording/playback** | [network-advanced.md](references/network-advanced.md) |
|
|
145
|
+
| **Custom fixtures** | [fixtures-hooks.md](references/fixtures-hooks.md) |
|
|
146
|
+
| **Advanced waiting strategies** | [assertions-waiting.md](references/assertions-waiting.md) |
|
|
147
|
+
| **OAuth/SSO mocking** | [third-party.md](references/third-party.md), [multi-context.md](references/multi-context.md) |
|
|
148
|
+
| **Payment gateway mocking** | [third-party.md](references/third-party.md) |
|
|
149
|
+
| **Email/SMS verification mocking** | [third-party.md](references/third-party.md) |
|
|
150
|
+
| **Failing on console errors** | [console-errors.md](references/console-errors.md) |
|
|
151
|
+
| **Security testing (XSS, CSRF)** | [security-testing.md](references/security-testing.md) |
|
|
152
|
+
| **Performance budgets & Web Vitals** | [performance-testing.md](references/performance-testing.md) |
|
|
153
|
+
| **Lighthouse integration** | [performance-testing.md](references/performance-testing.md) |
|
|
154
|
+
| **Test annotations (skip, fixme)** | [annotations.md](references/annotations.md) |
|
|
155
|
+
| **Test steps for reporting** | [annotations.md](references/annotations.md) |
|
|
156
|
+
|
|
157
|
+
## Quick Decision Tree
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
What are you doing?
|
|
161
|
+
│
|
|
162
|
+
├─ Writing a new test?
|
|
163
|
+
│ ├─ E2E test → test-organization.md, locators.md, assertions-waiting.md
|
|
164
|
+
│ ├─ Component test → component-testing.md
|
|
165
|
+
│ ├─ API test → test-organization.md, assertions-waiting.md
|
|
166
|
+
│ ├─ Visual/canvas test → canvas-webgl.md, test-organization.md
|
|
167
|
+
│ ├─ Accessibility test → accessibility.md
|
|
168
|
+
│ ├─ Mobile/responsive test → mobile-testing.md
|
|
169
|
+
│ ├─ i18n/locale test → i18n.md
|
|
170
|
+
│ ├─ Electron app test → electron.md
|
|
171
|
+
│ ├─ Browser extension test → browser-extensions.md
|
|
172
|
+
│ └─ Multi-user test → multi-user.md
|
|
173
|
+
│
|
|
174
|
+
├─ Testing specific features?
|
|
175
|
+
│ ├─ File upload/download → file-operations.md
|
|
176
|
+
│ ├─ Date/time dependent → clock-mocking.md
|
|
177
|
+
│ ├─ WebSocket/real-time → websockets.md
|
|
178
|
+
│ ├─ Geolocation/permissions → browser-apis.md
|
|
179
|
+
│ ├─ OAuth/SSO mocking → third-party.md, multi-context.md
|
|
180
|
+
│ ├─ Payments/email/SMS → third-party.md
|
|
181
|
+
│ ├─ iFrames → iframes.md
|
|
182
|
+
│ ├─ Canvas/WebGL/charts → canvas-webgl.md
|
|
183
|
+
│ ├─ Service workers/PWA → service-workers.md
|
|
184
|
+
│ ├─ i18n/localization → i18n.md
|
|
185
|
+
│ ├─ Security (XSS, CSRF) → security-testing.md
|
|
186
|
+
│ └─ Performance/Web Vitals → performance-testing.md
|
|
187
|
+
│
|
|
188
|
+
├─ Test is failing/flaky?
|
|
189
|
+
│ ├─ Flaky test investigation → flaky-tests.md
|
|
190
|
+
│ ├─ Element not found → locators.md, debugging.md
|
|
191
|
+
│ ├─ Timeout issues → assertions-waiting.md, debugging.md
|
|
192
|
+
│ ├─ Race conditions → flaky-tests.md, debugging.md
|
|
193
|
+
│ ├─ Flaky only with multiple workers → flaky-tests.md, performance.md
|
|
194
|
+
│ ├─ State leak / isolation → flaky-tests.md, fixtures-hooks.md
|
|
195
|
+
│ ├─ Console/JS errors → console-errors.md, debugging.md
|
|
196
|
+
│ └─ General debugging → debugging.md
|
|
197
|
+
│
|
|
198
|
+
├─ Testing error scenarios?
|
|
199
|
+
│ ├─ Network failures → error-testing.md, network-advanced.md
|
|
200
|
+
│ ├─ Offline (unexpected) → error-testing.md
|
|
201
|
+
│ ├─ Offline-first/PWA → service-workers.md
|
|
202
|
+
│ ├─ Error boundaries → error-testing.md
|
|
203
|
+
│ └─ Form validation → error-testing.md
|
|
204
|
+
│
|
|
205
|
+
├─ Refactoring existing code?
|
|
206
|
+
│ ├─ Implementing POM → page-object-model.md
|
|
207
|
+
│ ├─ Improving selectors → locators.md
|
|
208
|
+
│ ├─ Extracting fixtures → fixtures-hooks.md
|
|
209
|
+
│ └─ Creating data factories → test-data.md
|
|
210
|
+
│
|
|
211
|
+
├─ Setting up infrastructure?
|
|
212
|
+
│ ├─ CI/CD → ci-cd.md
|
|
213
|
+
│ ├─ Global setup/teardown → global-setup.md
|
|
214
|
+
│ ├─ Project dependencies → projects-dependencies.md
|
|
215
|
+
│ ├─ Test performance → performance.md
|
|
216
|
+
│ ├─ Test coverage → test-coverage.md
|
|
217
|
+
│ └─ Project config → test-organization.md, projects-dependencies.md
|
|
218
|
+
│
|
|
219
|
+
└─ Organizing tests?
|
|
220
|
+
├─ Skip/fixme/slow tests → annotations.md
|
|
221
|
+
├─ Test steps → annotations.md
|
|
222
|
+
└─ Conditional execution → annotations.md
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Test Validation Loop
|
|
226
|
+
|
|
227
|
+
After writing or modifying tests:
|
|
228
|
+
|
|
229
|
+
1. **Run tests**: `npx playwright test --reporter=list`
|
|
230
|
+
2. **If tests fail**:
|
|
231
|
+
- Review error output and trace (`npx playwright show-trace`)
|
|
232
|
+
- Fix locators, waits, or assertions
|
|
233
|
+
- Re-run tests
|
|
234
|
+
3. **Only proceed when all tests pass**
|
|
235
|
+
4. **Run multiple times** for critical tests: `npx playwright test --repeat-each=5`
|
|
@@ -0,0 +1,359 @@
|
|
|
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
|