@capillarytech/cap-ui-dev-tools 1.0.0 → 1.3.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.
@@ -0,0 +1,488 @@
1
+ # CapVision Session Recording - Usage Guide
2
+
3
+ Part of `@capillarytech/cap-ui-dev-tools` v1.1.0+
4
+
5
+ ## 📖 Overview
6
+
7
+ The CapVision module provides automatic session recording for WebdriverIO tests. Record user interactions, console logs, and DOM changes during test execution, then replay them in your HTML reports.
8
+
9
+ ## 🚀 Quick Start
10
+
11
+ ### Installation
12
+
13
+ ```bash
14
+ npm install --save-dev @capillarytech/cap-ui-dev-tools
15
+ ```
16
+
17
+ ### Basic Usage (WebdriverIO)
18
+
19
+ ```javascript
20
+ // wdio.conf.js
21
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools/capvision');
22
+
23
+ const capVisionHooks = createWDIOCapVisionHooks({
24
+ recordingsOutputDir: './reports/recordings',
25
+ enabledClusters: ['staging', 'production']
26
+ });
27
+
28
+ exports.config = {
29
+ // ... your existing WebdriverIO config
30
+
31
+ onPrepare: function(config, capabilities) {
32
+ capVisionHooks.onPrepare();
33
+ },
34
+
35
+ beforeTest: async function(test, context) {
36
+ await capVisionHooks.beforeTest(test, context, browser);
37
+ },
38
+
39
+ afterTest: async function(test, context, result) {
40
+ await capVisionHooks.afterTest(test, context, result);
41
+ },
42
+
43
+ onComplete: async function(exitCode, config, capabilities, results) {
44
+ await capVisionHooks.onComplete();
45
+ }
46
+ };
47
+ ```
48
+
49
+ That's it! Your tests will now be automatically recorded.
50
+
51
+ ## 📦 Import Options
52
+
53
+ ### Option 1: From CapVision Sub-Module (Recommended)
54
+
55
+ ```javascript
56
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools/capvision');
57
+ ```
58
+
59
+ ### Option 2: From Main Package
60
+
61
+ ```javascript
62
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools');
63
+ ```
64
+
65
+ ### Option 3: Access Full CapVision Module
66
+
67
+ ```javascript
68
+ const capVision = require('@capillarytech/cap-ui-dev-tools').capVisionRecorder;
69
+
70
+ const {
71
+ CapVisionRecorder,
72
+ ReportEnhancer,
73
+ WebdriverIOCapVisionRecorder,
74
+ createWDIOCapVisionHooks
75
+ } = capVision;
76
+ ```
77
+
78
+ ### Option 4: TypeScript/ESM
79
+
80
+ ```typescript
81
+ import { createWDIOCapVisionHooks } from '@capillarytech/cap-ui-dev-tools/capvision';
82
+ ```
83
+
84
+ ## ⚙️ Configuration
85
+
86
+ ### Full Configuration Example
87
+
88
+ ```javascript
89
+ const capVisionHooks = createWDIOCapVisionHooks({
90
+ // === Filtering Options ===
91
+ enabledClusters: ['crm-staging-new', 'crm-nightly-new'],
92
+ enabledModules: ['creatives', 'loyalty'],
93
+ enabledTestTypes: ['smoke', 'sanity', 'regression'],
94
+
95
+ // === Storage ===
96
+ recordingsOutputDir: './reports/recordings',
97
+ useTempFile: true, // Recommended for large tests
98
+
99
+ // === Recording Options ===
100
+ saveIntervalMs: 60000, // Auto-save every 60 seconds
101
+ checkoutIntervalMs: 30000, // Snapshot every 30 seconds
102
+ recordCanvas: false, // Don't record canvas (saves space)
103
+ maskAllInputs: true, // Mask sensitive inputs
104
+ collectFonts: true, // Capture custom fonts
105
+ recordCrossOriginIframes: false,
106
+
107
+ // === Console Recording ===
108
+ recordConsole: true,
109
+ consoleRecordOptions: {
110
+ level: ['log', 'info', 'warn', 'error'],
111
+ lengthThreshold: 10000
112
+ }
113
+ }, {
114
+ // === Report Enhancer Configuration ===
115
+ reportsDir: './reports/html-reports',
116
+ playerWidth: 800,
117
+ playerHeight: 460,
118
+ autoPlay: false
119
+ });
120
+ ```
121
+
122
+ ### Environment-Based Configuration
123
+
124
+ ```javascript
125
+ const isCI = process.env.CI === 'true';
126
+ const cluster = process.env.CLUSTER || 'staging';
127
+
128
+ const capVisionHooks = createWDIOCapVisionHooks({
129
+ enabledClusters: [cluster],
130
+ enabledTestTypes: isCI ? ['smoke'] : ['smoke', 'sanity'],
131
+ saveIntervalMs: isCI ? 120000 : 60000,
132
+ recordingsOutputDir: './reports/recordings'
133
+ });
134
+ ```
135
+
136
+ ## 🎯 Usage Patterns
137
+
138
+ ### Pattern 1: Automatic Recording (Recommended)
139
+
140
+ All tests recorded automatically:
141
+
142
+ ```javascript
143
+ // wdio.conf.js
144
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools/capvision');
145
+ const hooks = createWDIOCapVisionHooks({ /* config */ });
146
+
147
+ exports.config = {
148
+ onPrepare: hooks.onPrepare,
149
+ beforeTest: hooks.beforeTest,
150
+ afterTest: hooks.afterTest,
151
+ onComplete: hooks.onComplete
152
+ };
153
+ ```
154
+
155
+ ### Pattern 2: Manual Control
156
+
157
+ Control when recording starts/stops:
158
+
159
+ ```javascript
160
+ const { WebdriverIOCapVisionRecorder } = require('@capillarytech/cap-ui-dev-tools/capvision');
161
+
162
+ describe('Test Suite', function() {
163
+ let recorder;
164
+
165
+ before(function() {
166
+ recorder = new WebdriverIOCapVisionRecorder({
167
+ recordingsOutputDir: './recordings'
168
+ });
169
+ recorder.init(browser);
170
+ });
171
+
172
+ it('Critical test', async function() {
173
+ // Start recording manually
174
+ await recorder.startRecording();
175
+
176
+ // Perform test actions
177
+ await criticalPage.doSomething();
178
+
179
+ // Stop and save
180
+ await recorder.stopRecordingAndSave('critical_test');
181
+ });
182
+ });
183
+ ```
184
+
185
+ ### Pattern 3: Record Only Failures
186
+
187
+ Save recordings only when tests fail:
188
+
189
+ ```javascript
190
+ const { WebdriverIOCapVisionRecorder } = require('@capillarytech/cap-ui-dev-tools/capvision');
191
+ const recorder = new WebdriverIOCapVisionRecorder();
192
+
193
+ exports.config = {
194
+ beforeTest: async function(test, context) {
195
+ recorder.init(browser);
196
+ await recorder.startRecording();
197
+ },
198
+
199
+ afterTest: async function(test, context, { passed }) {
200
+ if (!passed) {
201
+ // Only save if test failed
202
+ await recorder.stopRecordingAndSave(`FAILED_${test.title}`);
203
+ }
204
+ }
205
+ };
206
+ ```
207
+
208
+ ### Pattern 4: With Page Refresh
209
+
210
+ Handle page refreshes correctly:
211
+
212
+ ```javascript
213
+ it('Test with navigation', async function() {
214
+ await homePage.open();
215
+
216
+ // Navigate to another page
217
+ await browser.url('/other-page');
218
+
219
+ // Re-activate recording after navigation
220
+ await recorder.ensureCapVisionIsActive();
221
+
222
+ await otherPage.doSomething();
223
+ });
224
+ ```
225
+
226
+ ## 📊 Viewing Recordings
227
+
228
+ ### In HTML Reports (Automatic)
229
+
230
+ If you have HTML reports, recordings are automatically embedded with a player:
231
+
232
+ ```bash
233
+ npm test
234
+ # Open reports/html-reports/index.html
235
+ # Recordings will appear inline with test results
236
+ ```
237
+
238
+ ### Standalone Viewer
239
+
240
+ Create a simple HTML file to view recordings:
241
+
242
+ ```html
243
+ <!DOCTYPE html>
244
+ <html>
245
+ <head>
246
+ <link rel="stylesheet" href="node_modules/@capillarytech/cap-ui-dev-tools/src/capvision-recorder/assets/capvision-player.css">
247
+ </head>
248
+ <body>
249
+ <div id="player"></div>
250
+ <script src="node_modules/@capillarytech/cap-ui-dev-tools/src/capvision-recorder/assets/capvision-player.min.js"></script>
251
+ <script>
252
+ fetch('./reports/recordings/your-test-1.json')
253
+ .then(res => res.json())
254
+ .then(data => {
255
+ new rrwebPlayer({ // Note: rrwebPlayer is the underlying library class name
256
+ target: document.getElementById('player'),
257
+ props: {
258
+ events: data.events,
259
+ width: 800,
260
+ height: 600
261
+ }
262
+ });
263
+ });
264
+ </script>
265
+ </body>
266
+ </html>
267
+ ```
268
+
269
+ ## 🔧 Advanced Usage
270
+
271
+ ### Custom Browser Executor
272
+
273
+ For non-WebdriverIO frameworks (Playwright, Puppeteer):
274
+
275
+ ```javascript
276
+ const { CapVisionRecorder } = require('@capillarytech/cap-ui-dev-tools/capvision');
277
+
278
+ // Create custom executor for Playwright
279
+ class PlaywrightExecutor {
280
+ constructor(page) {
281
+ this.page = page;
282
+ }
283
+
284
+ async execute(script, ...args) {
285
+ return this.page.evaluate(script, ...args);
286
+ }
287
+
288
+ async pause(ms) {
289
+ return new Promise(resolve => setTimeout(resolve, ms));
290
+ }
291
+ }
292
+
293
+ // Use with recorder
294
+ const recorder = new CapVisionRecorder({
295
+ recordingsOutputDir: './recordings'
296
+ });
297
+
298
+ recorder.setBrowserExecutor(new PlaywrightExecutor(page));
299
+ await recorder.startRecording();
300
+ // ... test execution
301
+ await recorder.stopRecordingAndSave('test_name');
302
+ ```
303
+
304
+ ### Report Enhancement Only
305
+
306
+ If you have existing recordings and just want to enhance reports:
307
+
308
+ ```javascript
309
+ const { ReportEnhancer } = require('@capillarytech/cap-ui-dev-tools/capvision');
310
+
311
+ const enhancer = new ReportEnhancer({
312
+ recordingsDir: './reports/recordings',
313
+ reportsDir: './reports/html-reports'
314
+ });
315
+
316
+ await enhancer.enhanceAllReports();
317
+ ```
318
+
319
+ ## 🐛 Troubleshooting
320
+
321
+ ### No Recordings Created
322
+
323
+ **Check:**
324
+ 1. Is recording enabled for your cluster/module/test type?
325
+ 2. Is the output directory writable?
326
+ 3. Check console logs for errors
327
+
328
+ ```javascript
329
+ // Add debug logging
330
+ const recorder = hooks.getRecorder();
331
+ console.log('Recording enabled?', recorder.isCapVisionEnabled());
332
+ console.log('Cluster:', process.env.CLUSTER);
333
+ console.log('Module:', process.env.MODULE);
334
+ ```
335
+
336
+ ### Recording Stops After Page Refresh
337
+
338
+ **Solution:** Always call `ensureCapVisionIsActive()` after page navigation:
339
+
340
+ ```javascript
341
+ await browser.refresh();
342
+ await recorder.ensureCapVisionIsActive(); // Essential!
343
+ ```
344
+
345
+ ### Large File Sizes
346
+
347
+ **Solutions:**
348
+ 1. Reduce checkout interval: `checkoutIntervalMs: 15000`
349
+ 2. Don't record canvas: `recordCanvas: false`
350
+ 3. Record only critical tests: Use selective filtering
351
+
352
+ ### Recordings Not in HTML Report
353
+
354
+ **Check:**
355
+ 1. Are recordings in the correct directory?
356
+ 2. Is `onComplete` hook being called?
357
+ 3. Do recording filenames match test names?
358
+
359
+ ## 📚 API Reference
360
+
361
+ ### createWDIOCapVisionHooks(recorderConfig, enhancerConfig)
362
+
363
+ Creates WebdriverIO hooks for automatic recording.
364
+
365
+ **Returns:** Object with `onPrepare`, `beforeTest`, `afterTest`, `onComplete`, `getRecorder` methods
366
+
367
+ ### CapVisionRecorder
368
+
369
+ Core recorder class (framework-agnostic).
370
+
371
+ **Methods:**
372
+ - `setBrowserExecutor(executor)` - Set custom browser executor
373
+ - `startRecording()` - Start recording session
374
+ - `stopRecordingAndSave(testName, testPassed)` - Stop and save recording (only saves if testPassed=false)
375
+ - `ensureCapVisionIsActive()` - Re-initialize after page refresh
376
+ - `isCapVisionEnabled()` - Check if recording is enabled
377
+ - `clearRecordingsFolder()` - Clear old recordings
378
+
379
+ ### WebdriverIOCapVisionRecorder
380
+
381
+ WebdriverIO-specific wrapper.
382
+
383
+ **Methods:**
384
+ - `init(browser)` - Initialize with browser instance
385
+ - `getRecorder()` - Get underlying recorder
386
+ - `getEnhancer()` - Get report enhancer
387
+ - All methods from CapVisionRecorder
388
+
389
+ ### ReportEnhancer
390
+
391
+ Enhances HTML reports with CapVision player.
392
+
393
+ **Methods:**
394
+ - `enhanceReport(reportPath)` - Enhance single report
395
+ - `enhanceAllReports()` - Enhance all reports in directory
396
+
397
+ ## 📦 Package Usage Summary
398
+
399
+ ```javascript
400
+ // All available imports from @capillarytech/cap-ui-dev-tools
401
+
402
+ // 1. Webpack Plugin (existing)
403
+ const LibraryWatcherPlugin = require('@capillarytech/cap-ui-dev-tools');
404
+ // or
405
+ const LibraryWatcherPlugin = require('@capillarytech/cap-ui-dev-tools/webpack');
406
+
407
+ // 2. CapVision Recorder (new)
408
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools/capvision');
409
+ // or
410
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools');
411
+
412
+ // 3. Full CapVision Module
413
+ const capVision = require('@capillarytech/cap-ui-dev-tools').capVisionRecorder;
414
+ ```
415
+
416
+ ## 🎓 Examples
417
+
418
+ ### Example 1: Basic Capillary Project
419
+
420
+ ```javascript
421
+ // wdio.conf.js
422
+ const { createWDIOCapVisionHooks } = require('@capillarytech/cap-ui-dev-tools/capvision');
423
+
424
+ const capVisionHooks = createWDIOCapVisionHooks({
425
+ enabledClusters: ['crm-staging-new'],
426
+ enabledModules: ['creatives'],
427
+ recordingsOutputDir: './reports/recordings'
428
+ });
429
+
430
+ exports.config = {
431
+ onPrepare: capVisionHooks.onPrepare,
432
+ beforeTest: (test, context) => capVisionHooks.beforeTest(test, context, browser),
433
+ afterTest: capVisionHooks.afterTest,
434
+ onComplete: capVisionHooks.onComplete
435
+ };
436
+ ```
437
+
438
+ ### Example 2: CI/CD Integration
439
+
440
+ ```javascript
441
+ const isCI = process.env.CI === 'true';
442
+
443
+ const capVisionHooks = createWDIOCapVisionHooks({
444
+ enabledClusters: process.env.CLUSTER ? [process.env.CLUSTER] : [],
445
+ enabledTestTypes: isCI ? ['smoke'] : ['smoke', 'sanity', 'regression'],
446
+ recordingsOutputDir: './reports/recordings',
447
+ saveIntervalMs: isCI ? 120000 : 60000
448
+ });
449
+ ```
450
+
451
+ ### Example 3: With Page Objects
452
+
453
+ ```javascript
454
+ // pages/BasePage.js
455
+ class BasePage {
456
+ constructor(recorder) {
457
+ this.recorder = recorder;
458
+ }
459
+
460
+ async navigateTo(url) {
461
+ await browser.url(url);
462
+ await this.recorder.ensureCapVisionIsActive();
463
+ }
464
+
465
+ async refresh() {
466
+ await browser.refresh();
467
+ await this.recorder.ensureCapVisionIsActive();
468
+ }
469
+ }
470
+
471
+ module.exports = BasePage;
472
+ ```
473
+
474
+ ## 📄 License
475
+
476
+ ISC License - Part of @capillarytech/cap-ui-dev-tools
477
+
478
+ ## 🆘 Support
479
+
480
+ - **Issues**: [GitHub Issues](https://github.com/cap-ui-dev-tools/cap-ui-dev-tools/issues)
481
+ - **Internal**: Contact Cap Automation Team
482
+
483
+ ---
484
+
485
+ **Version**: 1.1.0+
486
+ **Module**: `@capillarytech/cap-ui-dev-tools/capvision`
487
+ **Compatibility**: WebdriverIO 7.x, 8.x+
488
+