testdriverai 7.0.0 → 7.1.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.
Files changed (112) hide show
  1. package/AGENTS.md +550 -0
  2. package/CODEOWNERS +0 -1
  3. package/README.md +126 -0
  4. package/agent/index.js +43 -18
  5. package/agent/lib/commands.js +794 -135
  6. package/agent/lib/redraw.js +124 -39
  7. package/agent/lib/sandbox.js +10 -1
  8. package/agent/lib/sdk.js +21 -0
  9. package/docs/MIGRATION.md +425 -0
  10. package/docs/PRESETS.md +210 -0
  11. package/docs/docs.json +91 -37
  12. package/docs/guide/best-practices-polling.mdx +154 -0
  13. package/docs/v7/api/dashcam.mdx +497 -0
  14. package/docs/v7/api/doubleClick.mdx +102 -0
  15. package/docs/v7/api/mouseDown.mdx +161 -0
  16. package/docs/v7/api/mouseUp.mdx +164 -0
  17. package/docs/v7/api/rightClick.mdx +123 -0
  18. package/docs/v7/getting-started/configuration.mdx +380 -0
  19. package/docs/v7/getting-started/quickstart.mdx +273 -140
  20. package/docs/v7/guides/best-practices.mdx +486 -0
  21. package/docs/v7/guides/caching-ai.mdx +215 -0
  22. package/docs/v7/guides/caching-selectors.mdx +292 -0
  23. package/docs/v7/guides/caching.mdx +366 -0
  24. package/docs/v7/guides/ci-cd/azure.mdx +587 -0
  25. package/docs/v7/guides/ci-cd/circleci.mdx +523 -0
  26. package/docs/v7/guides/ci-cd/github-actions.mdx +457 -0
  27. package/docs/v7/guides/ci-cd/gitlab.mdx +498 -0
  28. package/docs/v7/guides/ci-cd/jenkins.mdx +664 -0
  29. package/docs/v7/guides/ci-cd/travis.mdx +438 -0
  30. package/docs/v7/guides/debugging.mdx +349 -0
  31. package/docs/v7/guides/faq.mdx +393 -0
  32. package/docs/v7/guides/performance.mdx +517 -0
  33. package/docs/v7/guides/troubleshooting.mdx +526 -0
  34. package/docs/v7/guides/vitest-plugin.mdx +477 -0
  35. package/docs/v7/guides/vitest.mdx +535 -0
  36. package/docs/v7/platforms/linux.mdx +308 -0
  37. package/docs/v7/platforms/macos.mdx +433 -0
  38. package/docs/v7/platforms/windows.mdx +430 -0
  39. package/docs/v7/presets/chrome-extension.mdx +223 -0
  40. package/docs/v7/presets/chrome.mdx +287 -0
  41. package/docs/v7/presets/electron.mdx +435 -0
  42. package/docs/v7/presets/vscode.mdx +398 -0
  43. package/docs/v7/presets/webapp.mdx +396 -0
  44. package/docs/v7/progressive-apis/CORE.md +459 -0
  45. package/docs/v7/progressive-apis/HOOKS.md +360 -0
  46. package/docs/v7/progressive-apis/PROGRESSIVE_DISCLOSURE.md +230 -0
  47. package/docs/v7/progressive-apis/PROVISION.md +266 -0
  48. package/interfaces/vitest-plugin.mjs +186 -100
  49. package/package.json +12 -1
  50. package/sdk.d.ts +335 -42
  51. package/sdk.js +756 -95
  52. package/src/core/Dashcam.js +469 -0
  53. package/src/core/index.d.ts +150 -0
  54. package/src/core/index.js +12 -0
  55. package/src/presets/index.mjs +331 -0
  56. package/src/vitest/extended.mjs +108 -0
  57. package/src/vitest/hooks.d.ts +119 -0
  58. package/src/vitest/hooks.mjs +298 -0
  59. package/src/vitest/index.mjs +64 -0
  60. package/src/vitest/lifecycle.mjs +277 -0
  61. package/src/vitest/utils.mjs +150 -0
  62. package/test/dashcam.test.js +137 -0
  63. package/testdriver/acceptance-sdk/assert.test.mjs +13 -31
  64. package/testdriver/acceptance-sdk/auto-cache-key-demo.test.mjs +56 -0
  65. package/testdriver/acceptance-sdk/chrome-extension.test.mjs +89 -0
  66. package/testdriver/acceptance-sdk/drag-and-drop.test.mjs +7 -19
  67. package/testdriver/acceptance-sdk/element-not-found.test.mjs +6 -19
  68. package/testdriver/acceptance-sdk/exec-js.test.mjs +6 -18
  69. package/testdriver/acceptance-sdk/exec-output.test.mjs +8 -20
  70. package/testdriver/acceptance-sdk/exec-pwsh.test.mjs +13 -25
  71. package/testdriver/acceptance-sdk/focus-window.test.mjs +8 -20
  72. package/testdriver/acceptance-sdk/formatted-logging.test.mjs +5 -20
  73. package/testdriver/acceptance-sdk/hooks-example.test.mjs +38 -0
  74. package/testdriver/acceptance-sdk/hover-image.test.mjs +10 -19
  75. package/testdriver/acceptance-sdk/hover-text-with-description.test.mjs +7 -19
  76. package/testdriver/acceptance-sdk/hover-text.test.mjs +5 -19
  77. package/testdriver/acceptance-sdk/match-image.test.mjs +7 -19
  78. package/testdriver/acceptance-sdk/presets-example.test.mjs +87 -0
  79. package/testdriver/acceptance-sdk/press-keys.test.mjs +5 -19
  80. package/testdriver/acceptance-sdk/prompt.test.mjs +6 -18
  81. package/testdriver/acceptance-sdk/scroll-keyboard.test.mjs +6 -20
  82. package/testdriver/acceptance-sdk/scroll-until-image.test.mjs +6 -18
  83. package/testdriver/acceptance-sdk/scroll-until-text.test.mjs +9 -23
  84. package/testdriver/acceptance-sdk/scroll.test.mjs +12 -21
  85. package/testdriver/acceptance-sdk/setup/testHelpers.mjs +124 -352
  86. package/testdriver/acceptance-sdk/sully-ai.test.mjs +234 -0
  87. package/testdriver/acceptance-sdk/test-console-logs.test.mjs +42 -0
  88. package/testdriver/acceptance-sdk/type.test.mjs +19 -58
  89. package/vitest.config.mjs +1 -0
  90. package/.vscode/mcp.json +0 -9
  91. package/MIGRATION.md +0 -389
  92. package/PLUGIN_MIGRATION.md +0 -222
  93. package/PROMPT_CACHE.md +0 -200
  94. package/SDK_LOGGING.md +0 -222
  95. package/SDK_MIGRATION.md +0 -474
  96. package/SDK_README.md +0 -1122
  97. package/debug-screenshot-1763401388589.png +0 -0
  98. package/examples/run-tests-with-recording.sh +0 -70
  99. package/examples/screenshot-example.js +0 -63
  100. package/examples/sdk-awesome-logs-demo.js +0 -177
  101. package/examples/sdk-cache-thresholds.js +0 -96
  102. package/examples/sdk-element-properties.js +0 -155
  103. package/examples/sdk-simple-example.js +0 -65
  104. package/examples/test-recording-example.test.js +0 -166
  105. package/mcp-server/AI_GUIDELINES.md +0 -57
  106. package/test-find-api.js +0 -73
  107. package/test-prompt-cache.js +0 -96
  108. package/test-sandbox-render.js +0 -28
  109. package/test-sdk-methods.js +0 -15
  110. package/test-sdk-refactor.js +0 -53
  111. package/test-stack-trace.mjs +0 -57
  112. package/testdriver/acceptance-sdk/setup/lifecycleHelpers.mjs +0 -239
@@ -0,0 +1,430 @@
1
+ ---
2
+ title: "Windows"
3
+ description: "Run TestDriver tests on Windows sandboxes (Enterprise)"
4
+ icon: "windows"
5
+ ---
6
+
7
+ <Info>
8
+ Windows sandboxes are available on **Enterprise plans only**. [Contact sales](https://testdriver.ai/contact) to enable Windows testing.
9
+ </Info>
10
+
11
+ ## Overview
12
+
13
+ Windows sandboxes enable testing of Windows-specific applications, desktop software, and Windows-only workflows.
14
+
15
+ Windows sandboxes provide:
16
+ - Windows Server 2019/2022
17
+ - Full desktop environment
18
+ - PowerShell and Command Prompt
19
+ - Support for all TestDriver commands
20
+ - Custom AMI support for pre-installed software
21
+ - RDP access for debugging
22
+
23
+ ## Usage
24
+
25
+ Specify Windows as the operating system:
26
+
27
+ ```javascript
28
+ import { TestDriver } from '@testdriverai/testdriver';
29
+
30
+ const testdriver = await TestDriver.create({
31
+ apiKey: process.env.TD_API_KEY,
32
+ os: 'windows' // Requires Enterprise plan
33
+ });
34
+ ```
35
+
36
+ ### With Lifecycle Helpers
37
+
38
+ ```javascript
39
+ import { chrome } from './setup/lifecycleHelpers.mjs';
40
+ import { test } from 'vitest';
41
+
42
+ test('windows app test', async (context) => {
43
+ const { testdriver } = await chrome(context, {
44
+ url: 'https://example.com',
45
+ os: 'windows'
46
+ });
47
+
48
+ await testdriver.find('login button').then(el => el.click());
49
+ });
50
+ ```
51
+
52
+ ## System Details
53
+
54
+ ### Operating System
55
+ - **OS**: Windows Server 2019 or 2022
56
+ - **Architecture**: x86_64 (64-bit)
57
+ - **Desktop**: Windows Desktop Experience
58
+
59
+ ### Pre-installed Software
60
+ - **Browsers**: Chrome, Edge, Firefox
61
+ - **Runtimes**: .NET Framework, .NET Core
62
+ - **Languages**: Node.js, Python (optional)
63
+ - **Tools**: PowerShell 5.1+, Git, Visual Studio Build Tools (optional)
64
+
65
+ ### Default Resolution
66
+ - **1920x1080** (configurable via `resolution` parameter)
67
+
68
+ ## Configuration
69
+
70
+ ### Custom Resolution
71
+
72
+ Set screen resolution:
73
+
74
+ ```javascript
75
+ const testdriver = await TestDriver.create({
76
+ apiKey: process.env.TD_API_KEY,
77
+ os: 'windows',
78
+ resolution: '1280x720'
79
+ });
80
+ ```
81
+
82
+ ### Environment Variables
83
+
84
+ ```javascript
85
+ const testdriver = await TestDriver.create({
86
+ apiKey: process.env.TD_API_KEY,
87
+ os: 'windows',
88
+ env: {
89
+ NODE_ENV: 'test',
90
+ DEBUG: 'true'
91
+ }
92
+ });
93
+ ```
94
+
95
+ ## Custom AMI
96
+
97
+ Enterprise plans support **custom Windows AMIs** with pre-installed software, reducing test setup time.
98
+
99
+ ### Benefits
100
+ - Pre-install proprietary software
101
+ - Configure system settings
102
+ - Install custom certificates
103
+ - Set up development tools
104
+
105
+ ### Setup
106
+
107
+ 1. Contact TestDriver support to create custom AMI
108
+ 2. Provide installation scripts and requirements
109
+ 3. Reference AMI in tests:
110
+
111
+ ```javascript
112
+ const testdriver = await TestDriver.create({
113
+ apiKey: process.env.TD_API_KEY,
114
+ os: 'windows',
115
+ ami: 'ami-custom-windows-123' // Your custom AMI ID
116
+ });
117
+ ```
118
+
119
+ See [Self-Hosting Guide](/v7/guides/self-hosting) for details on managing custom AMIs.
120
+
121
+ ## Common Use Cases
122
+
123
+ ### Windows Desktop Applications
124
+
125
+ Test native Windows applications:
126
+
127
+ ```javascript
128
+ import { test } from 'vitest';
129
+
130
+ test('windows desktop app', async (context) => {
131
+ const { testdriver } = await chrome(context, { os: 'windows' });
132
+
133
+ // Launch application
134
+ await testdriver.exec('pwsh',
135
+ 'Start-Process "C:\\Program Files\\MyApp\\MyApp.exe"',
136
+ 5000
137
+ );
138
+
139
+ // Wait for app to load
140
+ await new Promise(r => setTimeout(r, 3000));
141
+
142
+ // Interact with app
143
+ await testdriver.find('main menu').then(el => el.click());
144
+ await testdriver.find('file open').then(el => el.click());
145
+ });
146
+ ```
147
+
148
+ ### .NET Applications
149
+
150
+ Test .NET Framework or .NET Core apps:
151
+
152
+ ```javascript
153
+ test('dotnet app', async (context) => {
154
+ const { testdriver } = await chrome(context, { os: 'windows' });
155
+
156
+ // Run .NET application
157
+ await testdriver.exec('pwsh',
158
+ 'dotnet run --project C:\\app\\MyApp.csproj',
159
+ 10000
160
+ );
161
+
162
+ await testdriver.find('window title').then(el => el.click());
163
+ });
164
+ ```
165
+
166
+ ### Registry Operations
167
+
168
+ Modify Windows Registry:
169
+
170
+ ```javascript
171
+ test('registry test', async (context) => {
172
+ const { testdriver } = await chrome(context, { os: 'windows' });
173
+
174
+ // Set registry value
175
+ await testdriver.exec('pwsh',
176
+ 'Set-ItemProperty -Path "HKCU:\\Software\\MyApp" -Name "Setting" -Value "Test"',
177
+ 5000
178
+ );
179
+
180
+ // Read registry value
181
+ const result = await testdriver.exec('pwsh',
182
+ 'Get-ItemProperty -Path "HKCU:\\Software\\MyApp" -Name "Setting"',
183
+ 5000
184
+ );
185
+ console.log('Registry value:', result);
186
+ });
187
+ ```
188
+
189
+ ### File Operations
190
+
191
+ Work with Windows file system:
192
+
193
+ ```javascript
194
+ test('file operations', async (context) => {
195
+ const { testdriver } = await chrome(context, { os: 'windows' });
196
+
197
+ // Create directory
198
+ await testdriver.exec('pwsh', 'New-Item -Path "C:\\Test" -ItemType Directory', 5000);
199
+
200
+ // Download file
201
+ await testdriver.exec('pwsh',
202
+ 'Invoke-WebRequest -Uri "https://example.com/file.zip" -OutFile "C:\\Test\\file.zip"',
203
+ 30000
204
+ );
205
+
206
+ // Extract archive
207
+ await testdriver.exec('pwsh',
208
+ 'Expand-Archive -Path "C:\\Test\\file.zip" -DestinationPath "C:\\Test"',
209
+ 10000
210
+ );
211
+ });
212
+ ```
213
+
214
+ ## Command Execution
215
+
216
+ ### PowerShell
217
+
218
+ Execute PowerShell commands:
219
+
220
+ ```javascript
221
+ // PowerShell Core (pwsh)
222
+ await testdriver.exec('pwsh', 'Get-Process', 5000);
223
+
224
+ // PowerShell 5.1 (powershell)
225
+ await testdriver.exec('powershell', 'Get-Service', 5000);
226
+ ```
227
+
228
+ ### Command Prompt
229
+
230
+ Execute CMD commands:
231
+
232
+ ```javascript
233
+ await testdriver.exec('cmd', 'dir C:\\', 5000);
234
+ ```
235
+
236
+ ### Batch Scripts
237
+
238
+ Run batch files:
239
+
240
+ ```javascript
241
+ // Create batch file
242
+ await testdriver.exec('cmd',
243
+ 'echo @echo off > C:\\test.bat && echo echo Hello >> C:\\test.bat',
244
+ 5000
245
+ );
246
+
247
+ // Execute batch file
248
+ await testdriver.exec('cmd', 'C:\\test.bat', 5000);
249
+ ```
250
+
251
+ ## Package Management
252
+
253
+ ### Chocolatey
254
+
255
+ Install packages with Chocolatey (if pre-installed on AMI):
256
+
257
+ ```javascript
258
+ // Install package
259
+ await testdriver.exec('pwsh',
260
+ 'choco install -y git',
261
+ 60000
262
+ );
263
+
264
+ // Use installed software
265
+ await testdriver.exec('pwsh', 'git --version', 5000);
266
+ ```
267
+
268
+ ### NPM
269
+
270
+ Install Node.js packages:
271
+
272
+ ```javascript
273
+ await testdriver.exec('pwsh', 'npm install -g typescript', 30000);
274
+ ```
275
+
276
+ ### NuGet
277
+
278
+ Install .NET packages:
279
+
280
+ ```javascript
281
+ await testdriver.exec('pwsh',
282
+ 'Install-Package Newtonsoft.Json -Force',
283
+ 30000
284
+ );
285
+ ```
286
+
287
+ ## Debugging
288
+
289
+ ### RDP Access
290
+
291
+ Connect via Remote Desktop Protocol:
292
+
293
+ ```javascript
294
+ const instance = testdriver.getInstance();
295
+ console.log('RDP:', `${instance.ip}:${instance.rdpPort || 3389}`);
296
+
297
+ // Use RDP client to connect and watch tests
298
+ ```
299
+
300
+ ### Screenshots
301
+
302
+ Capture screenshots:
303
+
304
+ ```javascript
305
+ // Windows screenshot via PowerShell
306
+ await testdriver.exec('pwsh',
307
+ 'Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait("{PRTSC}"); Start-Sleep -Seconds 1',
308
+ 5000
309
+ );
310
+ ```
311
+
312
+ ### Event Logs
313
+
314
+ Access Windows Event Logs:
315
+
316
+ ```javascript
317
+ const logs = await testdriver.exec('pwsh',
318
+ 'Get-EventLog -LogName Application -Newest 10',
319
+ 5000
320
+ );
321
+ console.log('Event logs:', logs);
322
+ ```
323
+
324
+ ## Performance
325
+
326
+ ### Startup Time
327
+ - **First test**: 60-120s (Windows boots slower than Linux)
328
+ - **Subsequent tests**: 0s (sandbox reuse)
329
+ - **Custom AMI**: Faster (pre-installed software)
330
+
331
+ ### Optimization Tips
332
+ - Use custom AMI with pre-installed software
333
+ - Reuse sandboxes across tests
334
+ - Enable caching
335
+ - Minimize software installation during tests
336
+
337
+ See [Performance Guide](/v7/guides/performance) for details.
338
+
339
+ ## Limitations
340
+
341
+ ### Slower Startup
342
+ Windows sandboxes take longer to boot than Linux (60-120s vs 20-60s).
343
+
344
+ ### Higher Cost
345
+ Windows sandboxes consume more test minutes due to licensing.
346
+
347
+ ### Limited Free Tier
348
+ Windows sandboxes not available on free tier.
349
+
350
+ ## Troubleshooting
351
+
352
+ ### Application Won't Launch
353
+
354
+ ```javascript
355
+ // Try launching with full path
356
+ await testdriver.exec('pwsh',
357
+ 'Start-Process -FilePath "C:\\Program Files\\App\\app.exe"',
358
+ 5000
359
+ );
360
+
361
+ // Or use cmd
362
+ await testdriver.exec('cmd',
363
+ 'start "" "C:\\Program Files\\App\\app.exe"',
364
+ 5000
365
+ );
366
+ ```
367
+
368
+ ### Permission Denied
369
+
370
+ ```javascript
371
+ // Run as administrator (if AMI configured)
372
+ await testdriver.exec('pwsh',
373
+ 'Start-Process -FilePath "app.exe" -Verb RunAs',
374
+ 5000
375
+ );
376
+ ```
377
+
378
+ ### Timeout Issues
379
+
380
+ Increase timeout for slower Windows operations:
381
+
382
+ ```javascript
383
+ await testdriver.exec('pwsh', 'command', 120000); // 2 minutes
384
+ ```
385
+
386
+ ## Enterprise Features
387
+
388
+ ### Custom AMI Management
389
+ - Pre-install proprietary software
390
+ - Configure system settings
391
+ - Install certificates and licenses
392
+ - Set up development environments
393
+
394
+ ### Dedicated Sandboxes
395
+ - Reserved Windows instances
396
+ - Faster startup (always-on)
397
+ - Guaranteed availability
398
+
399
+ ### Support
400
+ - Priority support for Windows issues
401
+ - Custom AMI creation assistance
402
+ - Windows-specific troubleshooting
403
+
404
+ ## Contact Sales
405
+
406
+ Ready to enable Windows testing?
407
+
408
+ <Card title="Contact Sales" icon="envelope" href="https://testdriver.ai/contact">
409
+ Get Enterprise access to Windows sandboxes
410
+ </Card>
411
+
412
+ ## See Also
413
+
414
+ <CardGroup cols={2}>
415
+ <Card title="Linux" icon="linux" href="/v7/platforms/linux">
416
+ Linux sandboxes (default)
417
+ </Card>
418
+
419
+ <Card title="macOS" icon="apple" href="/v7/platforms/macos">
420
+ macOS sandboxes (Beta)
421
+ </Card>
422
+
423
+ <Card title="Self-Hosting" icon="server" href="/v7/guides/self-hosting">
424
+ Custom AMI management
425
+ </Card>
426
+
427
+ <Card title="Configuration" icon="gear" href="/v7/getting-started/configuration">
428
+ Sandbox configuration
429
+ </Card>
430
+ </CardGroup>
@@ -0,0 +1,223 @@
1
+ ---
2
+ title: "Chrome Extension Testing"
3
+ sidebarTitle: "Chrome Extensions"
4
+ description: "Test Chrome extensions with Chrome for Testing"
5
+ icon: "puzzle-piece"
6
+ ---
7
+
8
+ ## Overview
9
+
10
+ Test Chrome extensions by loading them into Chrome for Testing. This preset uses the `launchChromeExtension()` helper to launch Chrome with a specific extension loaded by its Chrome Web Store ID.
11
+
12
+ ## Quick Start
13
+
14
+ ```javascript
15
+ import { test } from 'vitest';
16
+ import TestDriver from 'testdriverai';
17
+ import {
18
+ runPrerunChromeExtension,
19
+ runPostrun
20
+ } from 'testdriverai/testdriver/acceptance-sdk/setup/lifecycleHelpers.mjs';
21
+
22
+ test('test chrome extension', async () => {
23
+ const client = await TestDriver.create({
24
+ apiKey: process.env.TD_API_KEY,
25
+ os: "linux",
26
+ verbosity: 1,
27
+ });
28
+
29
+ // Launch Chrome with extension loaded
30
+ // Extension ID from Chrome Web Store
31
+ await runPrerunChromeExtension(client, "cjpalhdlnbpafiamejdnhcphjbkeiagm");
32
+
33
+ // Your test code here
34
+ await client.focusApplication("Google Chrome");
35
+
36
+ // ... test extension functionality
37
+
38
+ await runPostrun(client);
39
+ await client.cleanup();
40
+ });
41
+ ```
42
+
43
+ ## Finding Extension IDs
44
+
45
+ Extension IDs can be found in the Chrome Web Store URL:
46
+
47
+ ```
48
+ https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm
49
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50
+ This is the extension ID
51
+ ```
52
+
53
+ ## Popular Extensions
54
+
55
+ | Extension | ID |
56
+ |-----------|---|
57
+ | uBlock Origin | `cjpalhdlnbpafiamejdnhcphjbkeiagm` |
58
+ | React Developer Tools | `fmkadmapgofadopljbjfkapdkoienihi` |
59
+ | Redux DevTools | `lmhkpmbekcpmknklioeibfkpmmfibljd` |
60
+ | Bitwarden | `nngceckbapebfimnlniiiahkandclblb` |
61
+
62
+ ## Loading Multiple Extensions
63
+
64
+ Load multiple extensions by separating IDs with commas:
65
+
66
+ ```javascript
67
+ await launchChromeExtension(
68
+ client,
69
+ "cjpalhdlnbpafiamejdnhcphjbkeiagm,nngceckbapebfimnlniiiahkandclblb"
70
+ );
71
+ ```
72
+
73
+ ## Complete Example
74
+
75
+ ```javascript
76
+ import { describe, it, beforeAll, afterAll } from 'vitest';
77
+ import TestDriver from 'testdriverai';
78
+ import {
79
+ runPrerunChromeExtension,
80
+ runPostrun
81
+ } from 'testdriverai/testdriver/acceptance-sdk/setup/lifecycleHelpers.mjs';
82
+
83
+ describe('Chrome Extension Testing', () => {
84
+ let client;
85
+ let dashcamUrl;
86
+
87
+ beforeAll(async () => {
88
+ client = await TestDriver.create({
89
+ apiKey: process.env.TD_API_KEY,
90
+ os: "linux",
91
+ verbosity: 1,
92
+ });
93
+
94
+ // Load uBlock Origin extension
95
+ await runPrerunChromeExtension(client, "cjpalhdlnbpafiamejdnhcphjbkeiagm");
96
+ });
97
+
98
+ afterAll(async () => {
99
+ if (client) {
100
+ dashcamUrl = await runPostrun(client);
101
+ await client.cleanup();
102
+ }
103
+ });
104
+
105
+ it('should verify extension is loaded', async () => {
106
+ await client.focusApplication("Google Chrome");
107
+
108
+ // Navigate to a page
109
+ const element = await client.find("TestDriver.ai Sandbox");
110
+ expect(element.found()).toBe(true);
111
+
112
+ // Test extension-specific functionality
113
+ // For example, checking if ads are blocked with uBlock
114
+ });
115
+
116
+ it('should access extension popup', async () => {
117
+ await client.focusApplication("Google Chrome");
118
+
119
+ // Open extension management
120
+ await client.exec(
121
+ "sh",
122
+ `xdotool key --clearmodifiers ctrl+shift+e`,
123
+ 5000,
124
+ true
125
+ );
126
+
127
+ // Wait for extensions page
128
+ await new Promise((resolve) => setTimeout(resolve, 2000));
129
+ });
130
+ });
131
+ ```
132
+
133
+ ## Environment Setup
134
+
135
+ Chrome for Testing is pre-installed in the E2B sandbox environment at:
136
+
137
+ ```
138
+ /opt/chrome-for-testing/chrome
139
+ /usr/local/bin/chrome-for-testing (symlink)
140
+ ```
141
+
142
+ ## Direct API Usage
143
+
144
+ Use the lower-level API for more control:
145
+
146
+ ```javascript
147
+ import { launchChromeExtension } from 'testdriverai/testdriver/acceptance-sdk/setup/lifecycleHelpers.mjs';
148
+
149
+ // Launch with specific extension and URL
150
+ await launchChromeExtension(
151
+ client,
152
+ "cjpalhdlnbpafiamejdnhcphjbkeiagm",
153
+ "https://example.com"
154
+ );
155
+ ```
156
+
157
+ ## Testing Extension Features
158
+
159
+ ### Test Extension Popup
160
+
161
+ ```javascript
162
+ it('opens extension popup', async () => {
163
+ // Click extension icon (varies by extension)
164
+ await client.click('extension icon in toolbar');
165
+
166
+ // Interact with popup
167
+ const popup = await client.find('extension popup window');
168
+ expect(popup.found()).toBe(true);
169
+ });
170
+ ```
171
+
172
+ ### Test Extension Settings
173
+
174
+ ```javascript
175
+ it('configures extension settings', async () => {
176
+ // Right-click extension icon
177
+ await client.rightClick('extension icon');
178
+
179
+ // Click options
180
+ await client.click('Options');
181
+
182
+ // Configure settings
183
+ await client.click('Enable feature X');
184
+ await client.click('Save');
185
+ });
186
+ ```
187
+
188
+ ### Test Content Scripts
189
+
190
+ ```javascript
191
+ it('verifies content script injection', async () => {
192
+ // Navigate to a page
193
+ await client.exec('sh', 'xdotool key ctrl+l', 5000, true);
194
+ await client.type('https://example.com');
195
+ await client.pressKeys('Enter');
196
+
197
+ // Check for extension-injected elements
198
+ const injected = await client.find('element added by extension');
199
+ expect(injected.found()).toBe(true);
200
+ });
201
+ ```
202
+
203
+ ## Troubleshooting
204
+
205
+ ### Extension Not Loading
206
+
207
+ 1. Verify the extension ID is correct
208
+ 2. Check Chrome for Testing is installed in the sandbox
209
+ 3. Ensure extension is compatible with Chrome for Testing version
210
+
211
+ ### Extension Permissions
212
+
213
+ Some extensions may require additional permissions or setup. You may need to:
214
+
215
+ 1. Navigate to `chrome://extensions/`
216
+ 2. Enable developer mode
217
+ 3. Grant required permissions
218
+
219
+ ## See Also
220
+
221
+ - [Web Apps (Chrome)](/v7/presets/chrome) - Regular Chrome browser testing
222
+ - [Desktop Apps (Electron)](/v7/presets/electron) - Electron app testing
223
+ - [Lifecycle Helpers](/v7/guides/lifecycle) - Prerun/postrun functions