@sridharkikkeri/playwright-common 1.0.22 → 1.0.24

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.
Files changed (38) hide show
  1. package/api-docs/assets/hierarchy.js +1 -0
  2. package/api-docs/assets/highlight.css +71 -0
  3. package/api-docs/assets/icons.js +18 -0
  4. package/api-docs/assets/icons.svg +1 -0
  5. package/api-docs/assets/main.js +60 -0
  6. package/api-docs/assets/navigation.js +1 -0
  7. package/api-docs/assets/search.js +1 -0
  8. package/api-docs/assets/style.css +1633 -0
  9. package/api-docs/classes/ActionOrchestrator.html +9 -0
  10. package/api-docs/classes/AllureUtil.html +12 -0
  11. package/api-docs/classes/ApiClient.html +28 -0
  12. package/api-docs/classes/BasePage.html +14 -0
  13. package/api-docs/classes/ConfigManager.html +6 -0
  14. package/api-docs/classes/CookieAuth.html +6 -0
  15. package/api-docs/classes/ElementProfileStore.html +11 -0
  16. package/api-docs/classes/ElementWrapper.html +35 -0
  17. package/api-docs/classes/ErrorUtils.html +7 -0
  18. package/api-docs/classes/Localization.html +8 -0
  19. package/api-docs/classes/LocatorHealing.html +14 -0
  20. package/api-docs/classes/Logger.html +7 -0
  21. package/api-docs/classes/LoginPage.html +19 -0
  22. package/api-docs/classes/OAuth2Auth.html +5 -0
  23. package/api-docs/hierarchy.html +1 -0
  24. package/api-docs/index.html +85 -0
  25. package/api-docs/interfaces/ApiRequestOptions.html +14 -0
  26. package/api-docs/interfaces/ApiResponse.html +13 -0
  27. package/api-docs/interfaces/AuthStrategy.html +4 -0
  28. package/api-docs/interfaces/ElementProfile.html +7 -0
  29. package/api-docs/interfaces/FileAttachment.html +8 -0
  30. package/api-docs/interfaces/FrameworkConfig.html +4 -0
  31. package/api-docs/modules.html +1 -0
  32. package/api-docs/types/FrameworkFixtures.html +12 -0
  33. package/api-docs/types/HttpMethod.html +2 -0
  34. package/api-docs/variables/test.html +2 -0
  35. package/create-healthedge-tests.js +46 -24
  36. package/package.json +7 -2
  37. package/HEALING_CACHE_STRATEGY.md +0 -222
  38. package/VISUAL_TESTING.md +0 -319
package/VISUAL_TESTING.md DELETED
@@ -1,319 +0,0 @@
1
- # Visual Regression Testing
2
-
3
- ## Overview
4
- The framework includes built-in visual regression testing using Playwright's snapshot comparison, wrapped in `VisualTesting` utility with Allure integration.
5
-
6
- ---
7
-
8
- ## Quick Start
9
-
10
- ### 1. Basic Usage
11
-
12
- ```typescript
13
- import { test } from '@healthedge/common';
14
- import { VisualTesting } from '@healthedge/common';
15
-
16
- test('Visual regression - Homepage', async ({ page }) => {
17
- const visual = new VisualTesting(page);
18
-
19
- await page.goto('https://example.com');
20
-
21
- // Compare full page
22
- await visual.compareFullPage({ name: 'homepage' });
23
- });
24
- ```
25
-
26
- ### 2. Element-Specific Comparison
27
-
28
- ```typescript
29
- test('Visual regression - Login button', async ({ page }) => {
30
- const visual = new VisualTesting(page);
31
- const loginBtn = page.locator('#login-btn');
32
-
33
- await visual.compareElement(loginBtn, {
34
- name: 'login-button',
35
- threshold: 0.02 // Allow 2% difference
36
- });
37
- });
38
- ```
39
-
40
- ### 3. Masking Dynamic Content
41
-
42
- ```typescript
43
- test('Visual regression - Mask timestamps', async ({ page }) => {
44
- const visual = new VisualTesting(page);
45
-
46
- await page.goto('/dashboard');
47
-
48
- // Mask elements that change frequently
49
- await visual.compareFullPage({
50
- name: 'dashboard',
51
- mask: [
52
- page.locator('.timestamp'),
53
- page.locator('.user-avatar'),
54
- page.locator('[data-dynamic="true"]')
55
- ]
56
- });
57
- });
58
- ```
59
-
60
- ---
61
-
62
- ## API Reference
63
-
64
- ### compareFullPage(options?)
65
- Compare entire page screenshot against baseline.
66
-
67
- **Options:**
68
- - `name`: Snapshot filename (default: 'full-page')
69
- - `threshold`: Max pixel difference ratio 0-1 (default: 0.01)
70
- - `mask`: Array of locators to mask
71
- - `fullPage`: Capture full scrollable page (default: true)
72
-
73
- ### compareElement(locator, options?)
74
- Compare specific element screenshot.
75
-
76
- **Options:**
77
- - `name`: Snapshot filename (default: 'element')
78
- - `threshold`: Max pixel difference ratio 0-1 (default: 0.01)
79
-
80
- ### compareViewport(options?)
81
- Compare visible viewport only (no scrolling).
82
-
83
- **Options:**
84
- - `name`: Snapshot filename (default: 'viewport')
85
- - `threshold`: Max pixel difference ratio 0-1 (default: 0.01)
86
- - `mask`: Array of locators to mask
87
-
88
- ### captureBaseline(name, fullPage?)
89
- Manually capture baseline (for documentation purposes).
90
-
91
- ---
92
-
93
- ## Workflow
94
-
95
- ### 1. Create Baselines (First Run)
96
- ```bash
97
- # Generate baseline snapshots
98
- npx playwright test --update-snapshots
99
- ```
100
-
101
- Baselines are stored in `**/__snapshots__/` directories.
102
-
103
- ### 2. Run Visual Tests
104
- ```bash
105
- # Compare against baselines
106
- npx playwright test
107
- ```
108
-
109
- ### 3. Review Failures
110
- When visual tests fail, Playwright generates:
111
- - **Actual**: Current screenshot
112
- - **Expected**: Baseline screenshot
113
- - **Diff**: Highlighted differences
114
-
115
- Located in: `test-results/*/`
116
-
117
- ### 4. Update Baselines
118
- ```bash
119
- # Update specific test
120
- npx playwright test visual.spec.ts --update-snapshots
121
-
122
- # Update all
123
- npx playwright test --update-snapshots
124
- ```
125
-
126
- ---
127
-
128
- ## Configuration
129
-
130
- ### Playwright Config
131
- ```typescript
132
- // playwright.config.ts
133
- export default defineConfig({
134
- expect: {
135
- toHaveScreenshot: {
136
- maxDiffPixels: 100, // Max different pixels
137
- threshold: 0.2, // Per-pixel color threshold
138
- animations: 'disabled', // Disable CSS animations
139
- }
140
- }
141
- });
142
- ```
143
-
144
- ### Per-Test Override
145
- ```typescript
146
- await visual.compareFullPage({
147
- threshold: 0.05, // Allow 5% difference for this test
148
- });
149
- ```
150
-
151
- ---
152
-
153
- ## Best Practices
154
-
155
- ### 1. Stable Test Data
156
- ```typescript
157
- // ❌ Bad: Random data causes failures
158
- await page.fill('#name', Math.random().toString());
159
-
160
- // ✅ Good: Fixed test data
161
- await page.fill('#name', 'Test User');
162
- ```
163
-
164
- ### 2. Mask Dynamic Content
165
- ```typescript
166
- // Mask timestamps, user-specific data, ads
167
- await visual.compareFullPage({
168
- mask: [
169
- page.locator('.timestamp'),
170
- page.locator('.ad-banner'),
171
- page.locator('[data-user-id]')
172
- ]
173
- });
174
- ```
175
-
176
- ### 3. Wait for Stability
177
- ```typescript
178
- // Wait for animations/loading
179
- await page.waitForLoadState('networkidle');
180
- await page.waitForTimeout(500); // Allow CSS transitions
181
-
182
- await visual.compareFullPage();
183
- ```
184
-
185
- ### 4. Descriptive Names
186
- ```typescript
187
- // ❌ Bad
188
- await visual.compareFullPage({ name: 'test1' });
189
-
190
- // ✅ Good
191
- await visual.compareFullPage({ name: 'checkout-page-logged-in' });
192
- ```
193
-
194
- ### 5. Cross-Browser Baselines
195
- ```bash
196
- # Generate baselines per browser
197
- npx playwright test --update-snapshots --project=chromium
198
- npx playwright test --update-snapshots --project=firefox
199
- ```
200
-
201
- Snapshots are stored separately: `homepage-chromium.png`, `homepage-firefox.png`
202
-
203
- ---
204
-
205
- ## CI/CD Integration
206
-
207
- ### GitHub Actions
208
- ```yaml
209
- - name: Run Visual Tests
210
- run: npx playwright test
211
-
212
- - name: Upload Visual Diffs
213
- if: failure()
214
- uses: actions/upload-artifact@v3
215
- with:
216
- name: visual-diffs
217
- path: test-results/
218
- ```
219
-
220
- ### Baseline Management
221
- **Option 1**: Commit baselines to Git
222
- ```bash
223
- git add **/__snapshots__/
224
- git commit -m "Update visual baselines"
225
- ```
226
-
227
- **Option 2**: Store in artifact repository (S3, Artifactory)
228
-
229
- ---
230
-
231
- ## Troubleshooting
232
-
233
- ### Issue: Flaky Visual Tests
234
- **Causes:**
235
- - Animations not disabled
236
- - Fonts not loaded
237
- - Network requests pending
238
-
239
- **Solution:**
240
- ```typescript
241
- await page.waitForLoadState('networkidle');
242
- await page.evaluate(() => document.fonts.ready);
243
- await page.waitForTimeout(500);
244
- ```
245
-
246
- ### Issue: Cross-Platform Differences
247
- **Cause**: Font rendering differs between OS
248
-
249
- **Solution**: Run tests in Docker with consistent environment
250
- ```dockerfile
251
- FROM mcr.microsoft.com/playwright:v1.42.0-focal
252
- ```
253
-
254
- ### Issue: Large Snapshot Files
255
- **Solution**: Use viewport comparison instead of full page
256
- ```typescript
257
- await visual.compareViewport({ name: 'above-fold' });
258
- ```
259
-
260
- ---
261
-
262
- ## Example Test Suite
263
-
264
- ```typescript
265
- import { test } from '@healthedge/common';
266
- import { VisualTesting } from '@healthedge/common';
267
-
268
- test.describe('Visual Regression Suite', () => {
269
- test.beforeEach(async ({ page }) => {
270
- await page.goto('/');
271
- await page.waitForLoadState('networkidle');
272
- });
273
-
274
- test('Homepage - Desktop', async ({ page }) => {
275
- const visual = new VisualTesting(page);
276
- await visual.compareFullPage({ name: 'homepage-desktop' });
277
- });
278
-
279
- test('Homepage - Mobile', async ({ page }) => {
280
- await page.setViewportSize({ width: 375, height: 667 });
281
- const visual = new VisualTesting(page);
282
- await visual.compareFullPage({ name: 'homepage-mobile' });
283
- });
284
-
285
- test('Login Modal', async ({ page }) => {
286
- const visual = new VisualTesting(page);
287
- await page.click('#login-btn');
288
-
289
- const modal = page.locator('.login-modal');
290
- await visual.compareElement(modal, { name: 'login-modal' });
291
- });
292
-
293
- test('Dashboard - Mask Dynamic', async ({ page }) => {
294
- const visual = new VisualTesting(page);
295
- await page.goto('/dashboard');
296
-
297
- await visual.compareFullPage({
298
- name: 'dashboard',
299
- mask: [
300
- page.locator('.last-login-time'),
301
- page.locator('.notification-badge')
302
- ]
303
- });
304
- });
305
- });
306
- ```
307
-
308
- ---
309
-
310
- ## Allure Integration
311
-
312
- Visual test results automatically appear in Allure reports:
313
- - ✅ **Passed**: Green checkmark
314
- - ❌ **Failed**: Diff image attached
315
- - 📸 **Baseline**: Attached for reference
316
-
317
- ```bash
318
- npm run report # View in Allure
319
- ```