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
@@ -1,199 +1,332 @@
1
1
  ---
2
- title: "SDK Quickstart"
2
+ title: "Quick Start"
3
3
  sidebarTitle: "Quickstart"
4
- description: "Get started with the TestDriver JavaScript SDK in minutes."
5
- icon: "gauge-high"
4
+ description: "Get started with the TestDriver JavaScript SDK in 2 minutes."
5
+ icon: "rocket"
6
6
  mode: "wide"
7
7
  ---
8
8
 
9
- TestDriver v7 introduces a powerful JavaScript SDK that lets you write tests in JavaScript/TypeScript instead of YAML. This gives you full programmatic control over your tests with IDE autocomplete, type safety, and all the benefits of modern development tooling.
9
+ TestDriver v7 lets you write AI-powered tests in JavaScript/TypeScript with full IDE support, type safety, and automatic lifecycle management.
10
10
 
11
11
  <Steps>
12
- <Step title="Create a TestDriver Account">
12
+ <Step title="Install TestDriver">
13
13
 
14
- You will need a [TestDriver Pro](https://app.testdriver.ai/team) account ($20/month) to get an API key.
15
-
16
- <Card
17
- title="Sign Up for TestDriver"
18
- icon="user-plus"
19
- href="https://app.testdriver.ai/team"
20
- />
21
-
22
- </Step>
23
-
24
- <Step title="Install TestDriver SDK">
25
-
26
- Install the TestDriver SDK package in your project:
14
+ Install the TestDriver SDK and Vitest test runner:
27
15
 
28
16
  ```bash
29
- npm install testdriverai
17
+ npm install --save-dev testdriverai vitest
30
18
  ```
31
-
32
- Or using other package managers:
33
-
34
- <Tabs>
35
- <Tab title="npm">
36
- ```bash
37
- npm install testdriverai
38
- ```
39
- </Tab>
40
- <Tab title="yarn">
41
- ```bash
42
- yarn add testdriverai
43
- ```
44
- </Tab>
45
- <Tab title="pnpm">
46
- ```bash
47
- pnpm add testdriverai
48
- ```
49
- </Tab>
50
- </Tabs>
51
19
 
52
20
  </Step>
53
21
 
54
- <Step title="Set up your environment">
22
+ <Step title="Write Your First Test">
55
23
 
56
- Copy your API key from [the TestDriver dashboard](https://app.testdriver.ai/team), and set it as an environment variable.
57
-
24
+ Create `test.test.js` and add your API key from [app.testdriver.ai](https://app.testdriver.ai):
25
+
58
26
  <Tabs>
59
- <Tab title="macOS / Linux">
60
- ```bash
61
- export TD_API_KEY="your_api_key_here"
62
- ```
63
- </Tab>
64
- <Tab title="Windows (PowerShell)">
65
- ```powershell
66
- $env:TD_API_KEY="your_api_key_here"
67
- ```
68
- </Tab>
69
- <Tab title="Windows (CMD)">
70
- ```cmd
71
- set TD_API_KEY=your_api_key_here
27
+ <Tab title="Fast">
28
+ ```javascript test.test.js
29
+ import { test } from 'vitest';
30
+ import { chrome } from 'testdriverai/presets';
31
+
32
+ test('my first test', async (context) => {
33
+ const { testdriver } = await chrome(context, {
34
+ url: 'https://example.com',
35
+ apiKey: 'tdai-1234567890abcdef' // Your API key from app.testdriver.ai
36
+ });
37
+
38
+ await testdriver.find('More information link').click();
39
+ await testdriver.assert('IANA page is visible');
40
+ });
72
41
  ```
42
+
43
+ <Warning>
44
+ Don't commit API keys to version control!
45
+ </Warning>
73
46
  </Tab>
74
- </Tabs>
75
-
76
- </Step>
77
-
78
- <Step title="Write your first test">
79
47
 
80
- Create a new test file (e.g., `login.test.mjs`):
81
-
82
- ```javascript login.test.mjs
83
- import { beforeAll, afterAll, describe, it, expect } from 'vitest';
84
- import TestDriver from 'testdriverai';
85
-
86
- describe('Login Test', () => {
87
- let testdriver;
88
-
89
- beforeAll(async () => {
90
- // Create a new TestDriver client
91
- client = new TestDriver(process.env.TD_API_KEY, {
92
- os: 'windows', // 'windows' or 'linux'
93
- resolution: '1366x768'
94
- });
48
+ <Tab title="Secure with .env (Recommended)">
49
+ Create `.env`:
95
50
 
96
- // Authenticate and connect to a sandbox
97
- await testdriver.auth();
98
- await testdriver.connect({ newSandbox: true });
99
- });
100
-
101
- afterAll(async () => {
102
- // Clean up after tests
103
- await testdriver.disconnect();
104
- });
105
-
106
- it('should verify the login page is displayed', async () => {
107
- // Use AI to assert the login page is visible
108
- const result = await testdriver.assert('the TestDriver.ai Sandbox login page is displayed');
109
- expect(result).toBeTruthy();
110
- });
111
-
112
- it('should enter username and password', async () => {
113
- // Focus the browser
114
- await testdriver.focusApplication('Google Chrome');
51
+ ```bash .env
52
+ TD_API_KEY=tdai-1234567890abcdef
53
+ ```
115
54
 
116
- // Find and click the username field
117
- const usernameField = await testdriver.find('Username input field');
118
- await usernameField.click();
119
- await testdriver.type('standard_user');
55
+ Then create `test.test.js`:
120
56
 
121
- // Tab to password field and enter password
122
- await testdriver.pressKeys(['tab']);
123
- await testdriver.type('secret_sauce');
57
+ ```javascript test.test.js
58
+ import { test } from 'vitest';
59
+ import { chrome } from 'testdriverai/presets';
60
+
61
+ test('my first test', async (context) => {
62
+ const { testdriver } = await chrome(context, {
63
+ url: 'https://example.com'
64
+ // apiKey automatically read from process.env.TD_API_KEY
65
+ });
66
+
67
+ await testdriver.find('More information link').click();
68
+ await testdriver.assert('IANA page is visible');
69
+ });
70
+ ```
124
71
 
125
- // Verify the credentials were entered
126
- const result = await testdriver.assert('username field contains "standard_user"');
127
- expect(result).toBeTruthy();
128
- });
129
- });
130
- ```
72
+ <Tip>
73
+ Add `.env` to your `.gitignore` file!
74
+ </Tip>
75
+ </Tab>
76
+ </Tabs>
131
77
 
132
78
  </Step>
133
79
 
134
- <Step title="Run your test">
80
+ <Step title="Run Your Test">
135
81
 
136
- Run your test using Vitest (or your preferred test runner):
137
-
138
82
  ```bash
139
- npx vitest run login.test.mjs
83
+ npx vitest run
140
84
  ```
141
85
 
142
- TestDriver will:
143
- 1. Authenticate with the API
144
- 2. Spin up a virtual machine sandbox
145
- 3. Execute your test steps
146
- 4. Return results to your test runner
86
+ That's it! 🎉
147
87
 
148
88
  <Tip>
149
- The SDK automatically connects to TestDriver's cloud infrastructure. You can also [self-host](/getting-started/self-hosting) the sandbox environment.
89
+ The `chrome()` preset automatically handles authentication, browser launch, and cleanup.
150
90
  </Tip>
151
91
 
152
92
  </Step>
153
93
  </Steps>
154
94
 
95
+ ## What Just Happened?
96
+
97
+ The `chrome()` preset automatically:
98
+ 1. ✅ Connected to a TestDriver sandbox
99
+ 2. ✅ Launched Chrome browser
100
+ 3. ✅ Navigated to your URL
101
+ 4. ✅ Started recording with Dashcam
102
+ 5. ✅ Cleaned up everything when done
103
+
104
+ No manual setup or teardown needed!
105
+
106
+ ## More Examples
107
+
108
+ ### Login Flow
109
+
110
+ ```javascript login.test.js
111
+ import { test, expect } from 'vitest';
112
+ import { chrome } from 'testdriverai/presets';
113
+
114
+ test('user can login', async (context) => {
115
+ const { testdriver } = await chrome(context, {
116
+ url: 'https://myapp.com/login'
117
+ });
118
+
119
+ await testdriver.find('email input').type('user@example.com');
120
+ await testdriver.find('password input').type('password123');
121
+ await testdriver.find('Login button').click();
122
+
123
+ const result = await testdriver.assert('Dashboard is visible');
124
+ expect(result).toBeTruthy();
125
+ });
126
+ ```
127
+
128
+ ### VS Code Extension
129
+
130
+ ```javascript extension.test.js
131
+ import { test } from 'vitest';
132
+ import { vscode } from 'testdriverai/presets';
133
+
134
+ test('create python file', async (context) => {
135
+ const { vscode } = await vscode(context, {
136
+ workspace: '/tmp/project',
137
+ extensions: ['ms-python.python']
138
+ });
139
+
140
+ await vscode.pressKeys(['cmd', 'shift', 'p']);
141
+ await vscode.type('Python: Create New File');
142
+ await vscode.pressKeys(['enter']);
143
+
144
+ await vscode.assert('Untitled Python file is open');
145
+ });
146
+ ```
147
+
148
+ ### Electron App
149
+
150
+ ```javascript electron.test.js
151
+ import { test } from 'vitest';
152
+ import { electron } from 'testdriverai/presets';
153
+
154
+ test('electron app menu', async (context) => {
155
+ const { app } = await electron(context, {
156
+ appPath: './dist/my-app'
157
+ });
158
+
159
+ await app.find('File menu').click();
160
+ await app.find('New Document').click();
161
+
162
+ await app.assert('New document window opens');
163
+ });
164
+ ```
165
+
166
+ ## Three Levels of Control
167
+
168
+ Choose your complexity level:
169
+
170
+ <CardGroup cols={3}>
171
+ <Card title="Presets (Easiest)" icon="rocket" href="/v7/progressive-apis/PROVISION">
172
+ **One-line setup**
173
+ ```javascript
174
+ const { testdriver } = await chrome(context, { url });
175
+ ```
176
+ </Card>
177
+
178
+ <Card title="Hooks (Flexible)" icon="link" href="/v7/progressive-apis/HOOKS">
179
+ **More control**
180
+ ```javascript
181
+ const client = useTestDriver(context);
182
+ const dashcam = useDashcam(context, client);
183
+ ```
184
+ </Card>
185
+
186
+ <Card title="Core (Full Control)" icon="code" href="/v7/progressive-apis/CORE">
187
+ **Manual everything**
188
+ ```javascript
189
+ const client = new TestDriver(apiKey);
190
+ await client.connect();
191
+ ```
192
+ </Card>
193
+ </CardGroup>
194
+
195
+ ## Video Replays
196
+
197
+ Tests automatically record with Dashcam for easy debugging:
198
+
199
+ ```javascript
200
+ test('with replay', async (context) => {
201
+ const { testdriver, dashcam } = await chrome(context, {
202
+ url: 'https://example.com'
203
+ });
204
+
205
+ await testdriver.find('button').click();
206
+
207
+ // After test, check the replay
208
+ console.log('Watch replay:', dashcam.url);
209
+ });
210
+ ```
211
+
212
+ View all replays at [app.testdriver.ai](https://app.testdriver.ai)
213
+
214
+ ## Optional Configuration
215
+
216
+ For better developer experience, create `vitest.config.mjs`:
217
+
218
+ ```javascript vitest.config.mjs
219
+ import { defineConfig } from 'vitest/config';
220
+
221
+ export default defineConfig({
222
+ test: {
223
+ testTimeout: 120000, // 2 minutes per test
224
+ hookTimeout: 120000, // 2 minutes for setup
225
+ },
226
+ });
227
+ ```
228
+
229
+ ## Common Commands
230
+
231
+ ```bash
232
+ # Run all tests
233
+ npx vitest run
234
+
235
+ # Run all tests in watch mode
236
+ npx vitest
237
+
238
+ # Run specific file
239
+ npx vitest run login.test.js
240
+
241
+ # Run in watch mode
242
+ npx vitest --watch
243
+
244
+ # Run tests matching pattern
245
+ npx vitest run --grep "login"
246
+ ```
247
+
248
+ ## Troubleshooting
249
+
250
+ ### Test times out
251
+
252
+ Increase the timeout in your config:
253
+
254
+ ```javascript vitest.config.mjs
255
+ export default defineConfig({
256
+ test: {
257
+ testTimeout: 180000, // 3 minutes
258
+ },
259
+ });
260
+ ```
261
+
262
+ ### API key not found
263
+
264
+ Either pass it directly to the preset:
265
+
266
+ ```javascript
267
+ const { testdriver } = await chrome(context, {
268
+ url: 'https://example.com',
269
+ apiKey: 'tdai-your-api-key-here'
270
+ });
271
+ ```
272
+
273
+ Or create a `.env` file in your project root:
274
+
275
+ ```bash .env
276
+ TD_API_KEY=tdai-your-api-key-here
277
+ ```
278
+
279
+ ### Import errors
280
+
281
+ Make sure you installed testdriverai:
282
+
283
+ ```bash
284
+ npm install --save-dev testdriverai
285
+ ```
286
+
155
287
  ## Next Steps
156
288
 
157
289
  <CardGroup cols={2}>
158
290
  <Card
159
- title="API Reference"
160
- icon="book"
161
- href="/v7/api/client"
291
+ title="Complete Vitest Guide"
292
+ icon="flask-vial"
293
+ href="/v7/guides/vitest"
162
294
  >
163
- Explore all available SDK methods and options
295
+ Everything about TestDriver + Vitest integration
164
296
  </Card>
165
297
 
166
298
  <Card
167
- title="Element Finding"
168
- icon="search"
169
- href="/v7/api/elements"
299
+ title="All Presets"
300
+ icon="rocket"
301
+ href="/v7/progressive-apis/PROVISION"
170
302
  >
171
- Learn how to locate and interact with UI elements
303
+ Chrome, VS Code, Electron, and more
172
304
  </Card>
173
305
 
174
306
  <Card
175
- title="Sandbox Management"
176
- icon="server"
177
- href="/v7/api/sandbox"
307
+ title="API Reference"
308
+ icon="book"
309
+ href="/v7/api/client"
178
310
  >
179
- Manage sandbox lifecycle and connections
311
+ All available methods and options
180
312
  </Card>
181
313
 
182
314
  <Card
183
- title="Assertions & Testing"
184
- icon="check"
185
- href="/v7/api/assertions"
315
+ title="Progressive APIs"
316
+ icon="gauge-high"
317
+ href="/v7/progressive-apis/PROGRESSIVE_DISCLOSURE"
186
318
  >
187
- Use AI-powered assertions in your tests
319
+ Choose your complexity level
188
320
  </Card>
189
321
  </CardGroup>
190
322
 
191
- ## Key Differences from v6
323
+ ## Why TestDriver v7?
192
324
 
193
- The v7 SDK offers several advantages over the YAML-based approach:
325
+ The v7 SDK offers advantages over YAML-based testing:
194
326
 
195
- - **Type Safety**: Full TypeScript support with IntelliSense
196
- - **Programmatic Control**: Use variables, loops, and functions
197
- - **Better Debugging**: Stack traces point to your actual code
198
- - **Integration**: Works with any JavaScript test framework (Vitest, Jest, Mocha, etc.)
199
- - **Flexibility**: Combine TestDriver with other testing tools seamlessly
327
+ - **Type Safety** - Full TypeScript support with IntelliSense
328
+ - **Programmatic Control** - Use variables, loops, and functions
329
+ - **Better Debugging** - Stack traces point to your actual code
330
+ - **Automatic Lifecycle** - Presets handle setup and cleanup
331
+ - **Framework Integration** - Works with Vitest, Jest, Mocha, etc.
332
+ - ✅ **Video Replays** - Automatic Dashcam recording included