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,266 @@
1
+ # Provision API
2
+
3
+ The `provision()` function is the easiest way to set up TestDriver for common applications. It automatically handles TestDriver initialization, application launching, and Dashcam recording.
4
+
5
+ ## Quick Start
6
+
7
+ ```javascript
8
+ import { test } from 'vitest';
9
+ import { provision } from 'testdriverai/presets';
10
+
11
+ test('my test', async (context) => {
12
+ const { testdriver } = await provision('chrome', {
13
+ url: 'https://example.com'
14
+ }, context);
15
+
16
+ await testdriver.find('Login button').click();
17
+ });
18
+ ```
19
+
20
+ ## API
21
+
22
+ ```typescript
23
+ provision(appType, options, context)
24
+ ```
25
+
26
+ **Parameters:**
27
+ - `appType` - Application type: `'chrome'`, `'vscode'`, `'electron'`, or `'webapp'`
28
+ - `options` - Configuration options (varies by app type)
29
+ - `context` - Vitest test context (from your test function parameter)
30
+
31
+ **Returns:**
32
+ - `testdriver` - TestDriver instance ready to use
33
+ - `dashcam` - Dashcam instance (if enabled)
34
+ - Additional app-specific properties (like `vscode`, `app`)
35
+
36
+ ## Application Types
37
+
38
+ ### Chrome Browser
39
+
40
+ ```javascript
41
+ const { testdriver } = await provision('chrome', {
42
+ url: 'https://myapp.com',
43
+ maximized: true, // Start maximized (default: true)
44
+ guest: true, // Use guest mode (default: true)
45
+ dashcam: true, // Enable Dashcam (default: true)
46
+ os: 'linux' // Target OS (default: 'linux')
47
+ }, context);
48
+
49
+ await testdriver.find('username').type('user@example.com');
50
+ await testdriver.find('Login').click();
51
+ ```
52
+
53
+ **Options:**
54
+ - `url` - URL to navigate to (default: 'http://testdriver-sandbox.vercel.app/')
55
+ - `maximized` - Start browser maximized (default: `true`)
56
+ - `guest` - Use guest/incognito mode (default: `true`)
57
+ - `dashcam` - Enable Dashcam recording (default: `true`)
58
+ - `os` - Target OS: `'linux'`, `'mac'`, or `'windows'` (default: `'linux'`)
59
+
60
+ **Returns:**
61
+ - `testdriver` - TestDriver instance
62
+ - `dashcam` - Dashcam instance (if enabled)
63
+
64
+ ### VS Code
65
+
66
+ ```javascript
67
+ const { testdriver, vscode } = await provision('vscode', {
68
+ workspace: '/path/to/project',
69
+ extensions: ['ms-python.python'],
70
+ dashcam: true,
71
+ os: 'linux'
72
+ }, context);
73
+
74
+ await vscode.find('File menu').click();
75
+ await vscode.find('New File').click();
76
+ ```
77
+
78
+ **Options:**
79
+ - `workspace` - Workspace/folder path to open (optional)
80
+ - `extensions` - Array of extension IDs to install (optional)
81
+ - `dashcam` - Enable Dashcam recording (default: `true`)
82
+ - `os` - Target OS (default: `'linux'`)
83
+
84
+ **Returns:**
85
+ - `testdriver` - TestDriver instance
86
+ - `vscode` - Alias for testdriver (semantic clarity)
87
+ - `dashcam` - Dashcam instance (if enabled)
88
+
89
+ ### Electron
90
+
91
+ ```javascript
92
+ const { testdriver, app } = await provision('electron', {
93
+ appPath: '/path/to/app',
94
+ args: ['--enable-logging'],
95
+ dashcam: true,
96
+ os: 'linux'
97
+ }, context);
98
+
99
+ await app.find('main window').click();
100
+ ```
101
+
102
+ **Options:**
103
+ - `appPath` - Path to Electron application (required)
104
+ - `args` - Additional command-line arguments (optional)
105
+ - `dashcam` - Enable Dashcam recording (default: `true`)
106
+ - `os` - Target OS (default: `'linux'`)
107
+
108
+ **Returns:**
109
+ - `testdriver` - TestDriver instance
110
+ - `app` - Alias for testdriver (semantic clarity)
111
+ - `dashcam` - Dashcam instance (if enabled)
112
+
113
+ ### Web App
114
+
115
+ Generic wrapper for web applications (currently uses Chrome):
116
+
117
+ ```javascript
118
+ const { testdriver } = await provision('webapp', {
119
+ url: 'https://example.com',
120
+ browser: 'chrome' // Only 'chrome' supported currently
121
+ }, context);
122
+ ```
123
+
124
+ ## Complete Example
125
+
126
+ ```javascript
127
+ import { describe, it, expect } from 'vitest';
128
+ import { provision } from 'testdriverai/presets';
129
+
130
+ describe('Login Flow', () => {
131
+ it('should login successfully', async (context) => {
132
+ // Provision Chrome with your app
133
+ const { testdriver, dashcam } = await provision('chrome', {
134
+ url: 'https://myapp.com/login',
135
+ maximized: true
136
+ }, context);
137
+
138
+ // Interact with the application
139
+ await testdriver.find('email input').type('user@example.com');
140
+ await testdriver.find('password input').type('password123');
141
+ await testdriver.find('Login button').click();
142
+
143
+ // Verify results
144
+ const result = await testdriver.assert('Welcome message is visible');
145
+ expect(result).toBeTruthy();
146
+
147
+ // Dashcam automatically stops and saves replay at test end
148
+ // No cleanup needed - handled automatically!
149
+ });
150
+ });
151
+ ```
152
+
153
+ ## How It Works
154
+
155
+ When you call `provision()`:
156
+
157
+ 1. **Creates TestDriver client** - Initializes and connects to sandbox
158
+ 2. **Sets up Dashcam** - Authenticates and starts recording (if enabled)
159
+ 3. **Launches application** - Opens the specified app with your configuration
160
+ 4. **Focuses window** - Ensures the app is ready for interaction
161
+ 5. **Returns ready-to-use instances** - Everything is set up and ready
162
+
163
+ At test end:
164
+ - Dashcam automatically stops and saves replay URL
165
+ - TestDriver automatically disconnects
166
+ - All cleanup is handled for you
167
+
168
+ ## Automatic Lifecycle
169
+
170
+ The `provision()` function uses Vitest hooks under the hood to manage the entire lifecycle:
171
+
172
+ ```javascript
173
+ // ✅ This:
174
+ const { testdriver } = await provision('chrome', { url }, context);
175
+
176
+ // Is equivalent to manually doing:
177
+ const client = new TestDriver(apiKey, { os: 'linux' });
178
+ await client.auth();
179
+ await client.connect();
180
+
181
+ const dashcam = new Dashcam(client);
182
+ await dashcam.auth();
183
+ await dashcam.start();
184
+
185
+ await client.exec('sh', 'google-chrome --start-maximized --guest "https://example.com" &', 30000);
186
+ await client.focusApplication('Google Chrome');
187
+
188
+ // ... your test code ...
189
+
190
+ await dashcam.stop();
191
+ await client.disconnect();
192
+ ```
193
+
194
+ That's **15+ lines of boilerplate** reduced to **1 line**!
195
+
196
+ ## TypeScript Support
197
+
198
+ Full TypeScript definitions included:
199
+
200
+ ```typescript
201
+ import { provision } from 'testdriverai/presets';
202
+
203
+ test('typed test', async (context) => {
204
+ const { testdriver } = await provision('chrome', {
205
+ url: 'https://example.com',
206
+ maximized: true,
207
+ os: 'linux' // ✅ Type-safe: only 'linux' | 'mac' | 'windows'
208
+ }, context);
209
+
210
+ // ✅ Full autocomplete for testdriver methods
211
+ await testdriver.find('button').click();
212
+ });
213
+ ```
214
+
215
+ ## Direct Preset Functions
216
+
217
+ You can also use the individual preset functions directly:
218
+
219
+ ```javascript
220
+ import { chrome, vscode, electron } from 'testdriverai/presets';
221
+
222
+ // Same as provision('chrome', options, context)
223
+ const { testdriver } = await chrome(context, {
224
+ url: 'https://example.com'
225
+ });
226
+
227
+ // Same as provision('vscode', options, context)
228
+ const { vscode } = await vscode(context, {
229
+ workspace: '/path/to/project'
230
+ });
231
+ ```
232
+
233
+ These are available for when you prefer explicit function names.
234
+
235
+ ## Best Practices
236
+
237
+ 1. **Always pass context** - Required for automatic cleanup
238
+ 2. **Enable dashcam** - Great for debugging test failures
239
+ 3. **Use descriptive variables** - `testdriver`, `vscode`, `app` based on what you're testing
240
+ 4. **Leverage TypeScript** - Get autocomplete and type safety
241
+ 5. **Keep URLs in config** - Use environment variables for different environments
242
+
243
+ ## Error Handling
244
+
245
+ ```javascript
246
+ test('handles errors gracefully', async (context) => {
247
+ try {
248
+ const { testdriver } = await provision('chrome', {
249
+ url: 'https://example.com'
250
+ }, context);
251
+
252
+ await testdriver.find('button').click();
253
+ } catch (error) {
254
+ // Cleanup still happens automatically
255
+ console.error('Test failed:', error);
256
+ throw error; // Re-throw to mark test as failed
257
+ }
258
+ });
259
+ ```
260
+
261
+ ## See Also
262
+
263
+ - [Hooks API](./HOOKS.md) - For more control over lifecycle
264
+ - [Core Classes](./CORE.md) - For full manual control
265
+ - [Migration Guide](../MIGRATION.md) - Upgrading from v6
266
+ - [Examples](../../testdriver/acceptance-sdk/presets-example.test.mjs) - Working examples