0
# Advanced Features
1
2
Advanced testing capabilities including performance monitoring, accessibility testing, mobile support, logging, and network operations.
3
4
## Capabilities
5
6
### Performance Monitoring
7
8
Monitor and capture browser performance metrics for performance testing.
9
10
```javascript { .api }
11
/**
12
* Take memory heap snapshot
13
* @returns Promise resolving when snapshot captured
14
*/
15
browser.takeHeapSnapshot();
16
17
/**
18
* Enable performance metrics collection
19
* @returns Promise resolving when metrics enabled
20
*/
21
browser.enablePerformanceMetrics();
22
23
/**
24
* Get collected performance metrics
25
* @returns Promise resolving with performance data
26
*/
27
browser.getPerformanceMetrics(): Promise<PerformanceMetrics>;
28
29
/**
30
* Performance metrics interface
31
*/
32
interface PerformanceMetrics {
33
Timestamp: number;
34
Documents: number;
35
Frames: number;
36
JSEventListeners: number;
37
Nodes: number;
38
LayoutCount: number;
39
RecalcStyleCount: number;
40
LayoutDuration: number;
41
RecalcStyleDuration: number;
42
ScriptDuration: number;
43
TaskDuration: number;
44
}
45
```
46
47
**Usage Examples:**
48
49
```javascript
50
// Monitor page performance
51
browser
52
.url('https://example.com')
53
.enablePerformanceMetrics()
54
.waitForElementVisible('body', 5000)
55
.getPerformanceMetrics()
56
.then(metrics => {
57
console.log('Layout count:', metrics.LayoutCount);
58
console.log('Script duration:', metrics.ScriptDuration);
59
})
60
.takeHeapSnapshot();
61
```
62
63
### Accessibility Testing
64
65
Integrate accessibility testing using the aXe accessibility engine.
66
67
```javascript { .api }
68
/**
69
* Inject aXe accessibility testing library into page
70
* @returns Promise resolving when aXe injected
71
*/
72
browser.axeInject();
73
74
/**
75
* Run accessibility audit tests
76
* @param options - aXe testing options
77
* @returns Promise resolving with accessibility results
78
*/
79
browser.axeRun(options?: AxeOptions): Promise<AxeResults>;
80
81
/**
82
* aXe testing options interface
83
*/
84
interface AxeOptions {
85
// CSS selector or elements to include/exclude
86
include?: string[] | Element[];
87
exclude?: string[] | Element[];
88
89
// Accessibility rules to run
90
rules?: Record<string, {enabled: boolean}>;
91
92
// Result types to return
93
resultTypes?: ('violations' | 'incomplete' | 'passes' | 'inapplicable')[];
94
95
// Tags to filter rules
96
tags?: string[];
97
}
98
99
/**
100
* aXe results interface
101
*/
102
interface AxeResults {
103
violations: AxeViolation[];
104
passes: AxeResult[];
105
incomplete: AxeResult[];
106
inapplicable: AxeResult[];
107
timestamp: string;
108
url: string;
109
}
110
111
/**
112
* aXe violation interface
113
*/
114
interface AxeViolation {
115
id: string;
116
impact: 'minor' | 'moderate' | 'serious' | 'critical';
117
description: string;
118
help: string;
119
helpUrl: string;
120
nodes: AxeNode[];
121
}
122
```
123
124
**Usage Examples:**
125
126
```javascript
127
// Basic accessibility testing
128
browser
129
.url('https://example.com')
130
.axeInject()
131
.axeRun()
132
.then(results => {
133
if (results.violations.length > 0) {
134
console.log('Accessibility violations found:', results.violations.length);
135
results.violations.forEach(violation => {
136
console.log(`${violation.impact}: ${violation.description}`);
137
});
138
}
139
});
140
141
// Targeted accessibility testing
142
browser
143
.url('https://example.com/form')
144
.axeInject()
145
.axeRun({
146
include: ['#main-form'],
147
exclude: ['.advertisement'],
148
tags: ['wcag2a', 'wcag21aa'],
149
rules: {
150
'color-contrast': { enabled: true },
151
'keyboard-navigation': { enabled: true }
152
}
153
})
154
.then(results => {
155
console.log('Form accessibility check:', results.violations.length, 'violations');
156
});
157
```
158
159
### Mobile Testing Support
160
161
Detect and control mobile platform capabilities.
162
163
```javascript { .api }
164
/**
165
* Check if running on iOS platform
166
* @returns Boolean indicating iOS platform
167
*/
168
browser.isIOS(): boolean;
169
170
/**
171
* Check if running on Android platform
172
* @returns Boolean indicating Android platform
173
*/
174
browser.isAndroid(): boolean;
175
176
/**
177
* Check if running on mobile platform (iOS or Android)
178
* @returns Boolean indicating mobile platform
179
*/
180
browser.isMobile(): boolean;
181
182
/**
183
* Set device dimensions for mobile testing
184
* @param width - Device width in pixels
185
* @param height - Device height in pixels
186
* @returns Promise resolving when dimensions set
187
*/
188
browser.setDeviceDimensions(width: number, height: number);
189
190
/**
191
* Set GPS coordinates for location testing
192
* @param latitude - Latitude coordinate
193
* @param longitude - Longitude coordinate
194
* @returns Promise resolving when location set
195
*/
196
browser.setGeolocation(latitude: number, longitude: number);
197
```
198
199
**Usage Examples:**
200
201
```javascript
202
// Platform-specific testing
203
if (browser.isMobile()) {
204
console.log('Running on mobile platform');
205
206
if (browser.isIOS()) {
207
console.log('iOS-specific testing');
208
browser.setDeviceDimensions(375, 812); // iPhone X dimensions
209
} else if (browser.isAndroid()) {
210
console.log('Android-specific testing');
211
browser.setDeviceDimensions(360, 640); // Android dimensions
212
}
213
214
// Set location for mobile testing
215
browser.setGeolocation(37.7749, -122.4194); // San Francisco
216
}
217
218
// Responsive testing
219
browser
220
.url('https://example.com')
221
.setDeviceDimensions(320, 568) // Mobile
222
.assert.visible('.mobile-menu')
223
.setDeviceDimensions(1024, 768) // Tablet
224
.assert.visible('.tablet-layout')
225
.resizeWindow(1920, 1080) // Desktop
226
.assert.visible('.desktop-header');
227
```
228
229
### Browser Logging
230
231
Access and manage browser logs for debugging and monitoring.
232
233
```javascript { .api }
234
/**
235
* Get browser logs by type
236
* @param type - Log type ('browser', 'driver', 'client', 'server')
237
* @returns Promise resolving with log entries
238
*/
239
browser.getLog(type: LogType): Promise<LogEntry[]>;
240
241
/**
242
* Get available log types
243
* @returns Promise resolving with array of log types
244
*/
245
browser.getLogTypes(): Promise<LogType[]>;
246
247
/**
248
* Check if specific log type is available
249
* @param type - Log type to check
250
* @returns Promise resolving with availability boolean
251
*/
252
browser.isLogAvailable(type: LogType): Promise<boolean>;
253
254
/**
255
* Log type options
256
*/
257
type LogType = 'browser' | 'driver' | 'client' | 'server' | 'performance';
258
259
/**
260
* Log entry interface
261
*/
262
interface LogEntry {
263
level: 'SEVERE' | 'WARNING' | 'INFO' | 'DEBUG';
264
message: string;
265
timestamp: number;
266
source: string;
267
}
268
```
269
270
**Usage Examples:**
271
272
```javascript
273
// Check browser console logs
274
browser
275
.url('https://example.com')
276
.getLogTypes()
277
.then(types => {
278
console.log('Available log types:', types);
279
})
280
.getLog('browser')
281
.then(logs => {
282
logs.forEach(log => {
283
if (log.level === 'SEVERE') {
284
console.log('Browser error:', log.message);
285
}
286
});
287
});
288
289
// Monitor performance logs
290
browser
291
.isLogAvailable('performance')
292
.then(available => {
293
if (available) {
294
return browser.getLog('performance');
295
}
296
})
297
.then(perfLogs => {
298
if (perfLogs) {
299
console.log('Performance entries:', perfLogs.length);
300
}
301
});
302
```
303
304
### Authentication
305
306
Handle HTTP authentication for secured applications.
307
308
```javascript { .api }
309
/**
310
* Register HTTP basic authentication credentials
311
* @param username - Username for authentication
312
* @param password - Password for authentication
313
* @returns Promise resolving when credentials registered
314
*/
315
browser.registerBasicAuth(username: string, password: string);
316
```
317
318
**Usage Examples:**
319
320
```javascript
321
// Set up basic authentication
322
browser
323
.registerBasicAuth('testuser', 'secret123')
324
.url('https://secured.example.com')
325
.waitForElementVisible('body', 5000)
326
.assert.titleContains('Secured Area');
327
```
328
329
### Network Operations
330
331
Monitor and control network behavior for testing network conditions.
332
333
```javascript { .api }
334
/**
335
* Mock HTTP responses for testing
336
* @param url - URL pattern to mock
337
* @param response - Mock response configuration
338
* @returns Promise resolving when mock configured
339
*/
340
browser.mockResponse(url: string | RegExp, response: MockResponse);
341
342
/**
343
* Set network conditions for testing
344
* @param conditions - Network condition parameters
345
* @returns Promise resolving when conditions set
346
*/
347
browser.setConditions(conditions: NetworkConditions);
348
349
/**
350
* Capture network requests for analysis
351
* @param callback - Function to handle captured requests
352
* @returns Promise resolving when capture configured
353
*/
354
browser.captureRequests(callback: (request: NetworkRequest) => void);
355
356
/**
357
* Mock response configuration
358
*/
359
interface MockResponse {
360
status: number;
361
headers?: Record<string, string>;
362
body?: string | object;
363
delay?: number;
364
}
365
366
/**
367
* Network conditions configuration
368
*/
369
interface NetworkConditions {
370
offline: boolean;
371
downloadThroughput: number; // bytes/sec
372
uploadThroughput: number; // bytes/sec
373
latency: number; // milliseconds
374
}
375
376
/**
377
* Network request information
378
*/
379
interface NetworkRequest {
380
url: string;
381
method: string;
382
headers: Record<string, string>;
383
body?: string;
384
timestamp: number;
385
}
386
```
387
388
**Usage Examples:**
389
390
```javascript
391
// Mock API responses
392
browser
393
.mockResponse('/api/users', {
394
status: 200,
395
headers: { 'Content-Type': 'application/json' },
396
body: { users: [{ id: 1, name: 'Test User' }] }
397
})
398
.url('https://example.com/users')
399
.waitForElementVisible('.user-list', 5000);
400
401
// Test slow network conditions
402
browser
403
.setConditions({
404
offline: false,
405
downloadThroughput: 1024 * 1024, // 1MB/s
406
uploadThroughput: 512 * 1024, // 512KB/s
407
latency: 100 // 100ms
408
})
409
.url('https://example.com')
410
.waitForElementVisible('body', 10000);
411
412
// Capture and analyze requests
413
browser
414
.captureRequests(request => {
415
console.log(`${request.method} ${request.url}`);
416
if (request.url.includes('/api/')) {
417
console.log('API request captured:', request);
418
}
419
})
420
.url('https://example.com')
421
.click('#load-data-button');
422
```
423
424
### Debug and Development Tools
425
426
Tools for debugging tests and development workflow.
427
428
```javascript { .api }
429
/**
430
* Enter interactive debug mode
431
* @returns Promise resolving when debug session ends
432
*/
433
browser.debug();
434
435
/**
436
* Pause test execution for specified duration
437
* @param ms - Milliseconds to pause
438
* @returns Promise resolving after pause
439
*/
440
browser.pause(ms: number);
441
```
442
443
**Usage Examples:**
444
445
```javascript
446
// Debug test execution
447
browser
448
.url('https://example.com')
449
.debug() // Pauses here for manual inspection
450
.click('#submit-button')
451
.pause(2000) // Wait 2 seconds
452
.assert.visible('#success-message');
453
```
454
455
### Screenshot and Snapshot Utilities
456
457
Enhanced screenshot and DOM snapshot capabilities.
458
459
```javascript { .api }
460
/**
461
* Capture and save screenshot with custom options
462
* @param filename - Path to save screenshot
463
* @param options - Screenshot options
464
* @returns Promise resolving when screenshot saved
465
*/
466
browser.saveScreenshot(filename: string, options?: ScreenshotOptions);
467
468
/**
469
* Save DOM snapshot to file
470
* @param filename - Path to save snapshot
471
* @param options - Snapshot options
472
* @returns Promise resolving when snapshot saved
473
*/
474
browser.saveSnapshot(filename: string, options?: SnapshotOptions);
475
476
/**
477
* Screenshot options
478
*/
479
interface ScreenshotOptions {
480
// Element to screenshot (default: full page)
481
element?: string;
482
483
// Include element padding
484
padding?: number;
485
486
// Hide elements before screenshot
487
hideElements?: string[];
488
}
489
490
/**
491
* Snapshot options
492
*/
493
interface SnapshotOptions {
494
// Include inline styles
495
includeStyles?: boolean;
496
497
// Include script tags
498
includeScripts?: boolean;
499
500
// Pretty print HTML
501
prettyPrint?: boolean;
502
}
503
```
504
505
**Usage Examples:**
506
507
```javascript
508
// Enhanced screenshots
509
browser
510
.url('https://example.com')
511
.saveScreenshot('./screenshots/full-page.png')
512
.saveScreenshot('./screenshots/header-only.png', {
513
element: '#header',
514
padding: 10,
515
hideElements: ['.advertisement', '.popup']
516
});
517
518
// DOM snapshots with options
519
browser
520
.saveSnapshot('./snapshots/page-state.html', {
521
includeStyles: true,
522
includeScripts: false,
523
prettyPrint: true
524
});
525
```
526
527
### Global Browser Detection
528
529
Utility methods for detecting browser capabilities and versions.
530
531
```javascript { .api }
532
/**
533
* Check if current browser is Chrome
534
* @returns Boolean indicating Chrome browser
535
*/
536
browser.isChrome(): boolean;
537
538
/**
539
* Check if current browser is Firefox
540
* @returns Boolean indicating Firefox browser
541
*/
542
browser.isFirefox(): boolean;
543
544
/**
545
* Check if current browser is Safari
546
* @returns Boolean indicating Safari browser
547
*/
548
browser.isSafari(): boolean;
549
550
/**
551
* Check if current browser is Edge
552
* @returns Boolean indicating Edge browser
553
*/
554
browser.isEdge(): boolean;
555
556
/**
557
* Check if current browser is Internet Explorer
558
* @returns Boolean indicating IE browser
559
*/
560
browser.isInternetExplorer(): boolean;
561
```
562
563
**Usage Examples:**
564
565
```javascript
566
// Browser-specific testing
567
if (browser.isChrome()) {
568
console.log('Running Chrome-specific tests');
569
browser.enablePerformanceMetrics();
570
} else if (browser.isFirefox()) {
571
console.log('Running Firefox-specific tests');
572
// Firefox-specific configuration
573
} else if (browser.isSafari()) {
574
console.log('Running Safari-specific tests');
575
// Safari-specific workarounds
576
}
577
578
// Cross-browser feature detection
579
const features = {
580
performanceMetrics: browser.isChrome(),
581
advancedDebugging: browser.isChrome() || browser.isFirefox(),
582
touchEvents: browser.isMobile()
583
};
584
585
console.log('Available features:', features);
586
```