testdriverai 7.2.2 → 7.2.9

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.
@@ -1,266 +1,329 @@
1
1
  # Provision API
2
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.
3
+ The `provision` object provides easy setup methods for common applications. These methods automatically handle TestDriver initialization, Dashcam recording, and application launching.
4
4
 
5
5
  ## Quick Start
6
6
 
7
7
  ```javascript
8
- import { test } from 'vitest';
9
- import { provision } from 'testdriverai/presets';
8
+ import { describe, it, expect } from 'vitest';
9
+ import { TestDriver } from 'testdriverai/lib/vitest/hooks.mjs';
10
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();
11
+ describe('My Test Suite', () => {
12
+ it('should test Chrome browser', async (context) => {
13
+ const testdriver = TestDriver(context, { newSandbox: true });
14
+
15
+ await testdriver.provision.chrome({
16
+ url: 'https://example.com'
17
+ });
18
+
19
+ await testdriver.find('Login button').click();
20
+ });
17
21
  });
18
22
  ```
19
23
 
20
- ## API
21
-
22
- ```typescript
23
- provision(appType, options, context)
24
- ```
24
+ ## Available Methods
25
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)
26
+ - `provision.chrome()` - Launch Chrome browser with URL
27
+ - `provision.vscode()` - Launch VS Code with optional extensions
28
+ - `provision.installer()` - Download and install applications
29
+ - `provision.electron()` - Launch Electron applications
30
30
 
31
- **Returns:**
32
- - `testdriver` - TestDriver instance ready to use
33
- - `dashcam` - Dashcam instance (if enabled)
34
- - Additional app-specific properties (like `vscode`, `app`)
31
+ ---
35
32
 
36
- ## Application Types
33
+ ## provision.chrome()
37
34
 
38
- ### Chrome Browser
35
+ Launch Google Chrome with automatic Dashcam recording.
39
36
 
40
37
  ```javascript
41
- const { testdriver } = await provision('chrome', {
38
+ await testdriver.provision.chrome({
42
39
  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();
40
+ maximized: true,
41
+ extensionPath: '/path/to/extension'
42
+ });
51
43
  ```
52
44
 
53
45
  **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'`)
46
+ | Option | Type | Default | Description |
47
+ |--------|------|---------|-------------|
48
+ | `url` | string | `'http://testdriver-sandbox.vercel.app/'` | URL to navigate to |
49
+ | `maximized` | boolean | `true` | Start browser maximized |
50
+ | `extensionPath` | string | - | Path to Chrome extension to load |
59
51
 
60
- **Returns:**
61
- - `testdriver` - TestDriver instance
62
- - `dashcam` - Dashcam instance (if enabled)
63
-
64
- ### VS Code
52
+ **Example:**
65
53
 
66
54
  ```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();
55
+ it('should login to my app', async (context) => {
56
+ const testdriver = TestDriver(context, { newSandbox: true });
57
+
58
+ await testdriver.provision.chrome({
59
+ url: 'https://myapp.com/login'
60
+ });
61
+
62
+ await testdriver.find('email input').type('user@example.com');
63
+ await testdriver.find('password input').type('password123');
64
+ await testdriver.find('Login button').click();
65
+
66
+ const result = await testdriver.assert('Dashboard is visible');
67
+ expect(result).toBeTruthy();
68
+ });
76
69
  ```
77
70
 
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'`)
71
+ ---
83
72
 
84
- **Returns:**
85
- - `testdriver` - TestDriver instance
86
- - `vscode` - Alias for testdriver (semantic clarity)
87
- - `dashcam` - Dashcam instance (if enabled)
73
+ ## provision.vscode()
88
74
 
89
- ### Electron
75
+ Launch Visual Studio Code with optional extension installation. Automatically starts Dashcam recording.
90
76
 
91
77
  ```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();
78
+ await testdriver.provision.vscode({
79
+ workspace: '/path/to/project',
80
+ extensions: ['esbenp.prettier-vscode', 'ms-python.python']
81
+ });
100
82
  ```
101
83
 
102
84
  **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'`)
85
+ | Option | Type | Default | Description |
86
+ |--------|------|---------|-------------|
87
+ | `workspace` | string | - | Workspace/folder path to open |
88
+ | `extensions` | string[] | `[]` | VS Code extension IDs to install |
107
89
 
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):
90
+ **Example - Basic Launch:**
116
91
 
117
92
  ```javascript
118
- const { testdriver } = await provision('webapp', {
119
- url: 'https://example.com',
120
- browser: 'chrome' // Only 'chrome' supported currently
121
- }, context);
93
+ it('should launch VS Code', async (context) => {
94
+ const testdriver = TestDriver(context, { newSandbox: true });
95
+
96
+ await testdriver.provision.vscode();
97
+
98
+ const result = await testdriver.assert(
99
+ 'Visual Studio Code window is visible on screen'
100
+ );
101
+ expect(result).toBeTruthy();
102
+ });
122
103
  ```
123
104
 
124
- ## Complete Example
105
+ **Example - Install Extensions:**
125
106
 
126
107
  ```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!
108
+ it('should install and use a VS Code extension', async (context) => {
109
+ const testdriver = TestDriver(context, { newSandbox: true });
110
+
111
+ // Launch VS Code with extensions installed
112
+ await testdriver.provision.vscode({
113
+ extensions: ['esbenp.prettier-vscode']
149
114
  });
115
+
116
+ // Open the extensions panel
117
+ await testdriver.pressKeys(['ctrl', 'shift', 'x']);
118
+ await new Promise(resolve => setTimeout(resolve, 2000));
119
+
120
+ const result = await testdriver.assert(
121
+ 'Prettier extension is visible in the extensions panel'
122
+ );
123
+ expect(result).toBeTruthy();
150
124
  });
151
125
  ```
152
126
 
153
- ## How It Works
127
+ ---
154
128
 
155
- When you call `provision()`:
129
+ ## provision.installer()
156
130
 
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
131
+ Download and install applications from a URL. Automatically detects file type and runs the appropriate install command.
162
132
 
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
133
+ ```javascript
134
+ const filePath = await testdriver.provision.installer({
135
+ url: 'https://example.com/app.deb',
136
+ appName: 'MyApp'
137
+ });
138
+ ```
169
139
 
170
- The `provision()` function uses Vitest hooks under the hood to manage the entire lifecycle:
140
+ **Options:**
141
+ | Option | Type | Default | Description |
142
+ |--------|------|---------|-------------|
143
+ | `url` | string | **required** | URL to download the installer from |
144
+ | `filename` | string | auto-detected | Filename to save as |
145
+ | `appName` | string | - | Application name to focus after install |
146
+ | `launch` | boolean | `true` | Whether to launch/focus the app after installation |
147
+
148
+ **Returns:** `Promise<string>` - Path to the downloaded file
149
+
150
+ **Supported File Types:**
151
+
152
+ | Platform | Extensions | Install Command |
153
+ |----------|------------|-----------------|
154
+ | Linux | `.deb` | `sudo dpkg -i && apt-get install -f -y` |
155
+ | Linux | `.rpm` | `sudo rpm -i` |
156
+ | Linux | `.appimage` | `chmod +x` |
157
+ | Linux | `.sh` | `chmod +x && execute` |
158
+ | Windows | `.msi` | `msiexec /i /quiet /norestart` |
159
+ | Windows | `.exe` | `Start-Process /S` |
160
+ | macOS | `.dmg` | `hdiutil attach && cp to /Applications` |
161
+ | macOS | `.pkg` | `installer -pkg -target /` |
162
+
163
+ **Example - Install .deb Package:**
171
164
 
172
165
  ```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();
166
+ it('should install a .deb package', async (context) => {
167
+ const testdriver = TestDriver(context, { newSandbox: true });
168
+
169
+ const filePath = await testdriver.provision.installer({
170
+ url: 'https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_amd64.deb'
171
+ });
172
+
173
+ // Verify installation
174
+ await testdriver.exec('sh', 'bat --version', 10000);
175
+ });
176
+ ```
180
177
 
181
- const dashcam = new Dashcam(client);
182
- await dashcam.auth();
183
- await dashcam.start();
178
+ **Example - Download Only (No Auto-Launch):**
184
179
 
185
- await client.exec('sh', 'google-chrome --start-maximized --guest "https://example.com" &', 30000);
186
- await client.focusApplication('Google Chrome');
180
+ ```javascript
181
+ it('should download a script', async (context) => {
182
+ const testdriver = TestDriver(context, { newSandbox: true });
183
+
184
+ const filePath = await testdriver.provision.installer({
185
+ url: 'https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh',
186
+ launch: false
187
+ });
188
+
189
+ // Run custom post-download commands
190
+ await testdriver.exec('sh', `source "${filePath}"`, 30000);
191
+ });
192
+ ```
187
193
 
188
- // ... your test code ...
194
+ **Example - Custom Post-Install:**
189
195
 
190
- await dashcam.stop();
191
- await client.disconnect();
196
+ ```javascript
197
+ it('should run AppImage with custom flags', async (context) => {
198
+ const testdriver = TestDriver(context, { newSandbox: true });
199
+
200
+ const filePath = await testdriver.provision.installer({
201
+ url: 'https://example.com/app.AppImage',
202
+ launch: false
203
+ });
204
+
205
+ // Run with custom arguments
206
+ await testdriver.exec('sh', `"${filePath}" --no-sandbox &`, 10000);
207
+
208
+ await new Promise(resolve => setTimeout(resolve, 5000));
209
+
210
+ const result = await testdriver.assert('App window is visible');
211
+ expect(result).toBeTruthy();
212
+ });
192
213
  ```
193
214
 
194
- That's **15+ lines of boilerplate** reduced to **1 line**!
215
+ ---
195
216
 
196
- ## TypeScript Support
217
+ ## provision.electron()
197
218
 
198
- Full TypeScript definitions included:
219
+ Launch an Electron application.
199
220
 
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();
221
+ ```javascript
222
+ await testdriver.provision.electron({
223
+ appPath: '/path/to/app',
224
+ args: ['--enable-logging']
212
225
  });
213
226
  ```
214
227
 
215
- ## Direct Preset Functions
228
+ **Options:**
229
+ | Option | Type | Default | Description |
230
+ |--------|------|---------|-------------|
231
+ | `appPath` | string | **required** | Path to Electron application |
232
+ | `args` | string[] | `[]` | Additional command-line arguments |
216
233
 
217
- You can also use the individual preset functions directly:
234
+ **Example:**
218
235
 
219
236
  ```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'
237
+ it('should launch Electron app', async (context) => {
238
+ const testdriver = TestDriver(context, { newSandbox: true });
239
+
240
+ await testdriver.provision.electron({
241
+ appPath: '/path/to/my-electron-app',
242
+ args: ['--enable-logging']
243
+ });
244
+
245
+ await testdriver.find('main window').click();
230
246
  });
231
247
  ```
232
248
 
233
- These are available for when you prefer explicit function names.
249
+ ---
234
250
 
235
- ## Best Practices
251
+ ## How Provision Methods Work
252
+
253
+ When you call a provision method:
236
254
 
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
255
+ 1. **Waits for connection** - Calls `ready()` to ensure sandbox is connected
256
+ 2. **Sets up Dashcam** - Creates log file and adds to Dashcam monitoring
257
+ 3. **Starts recording** - Automatically starts Dashcam if not already recording
258
+ 4. **Launches application** - Opens the specified app with your configuration
259
+ 5. **Focuses window** - Ensures the app is ready for interaction
242
260
 
243
- ## Error Handling
261
+ At test end:
262
+ - Dashcam automatically stops and saves replay URL
263
+ - TestDriver automatically disconnects
264
+ - All cleanup is handled for you
265
+
266
+ ## Complete Example
244
267
 
245
268
  ```javascript
246
- test('handles errors gracefully', async (context) => {
247
- try {
248
- const { testdriver } = await provision('chrome', {
249
- url: 'https://example.com'
250
- }, context);
269
+ import { describe, it, expect } from 'vitest';
270
+ import { TestDriver } from 'testdriverai/lib/vitest/hooks.mjs';
271
+
272
+ describe('Application Testing', () => {
273
+ it('should test Chrome login flow', async (context) => {
274
+ const testdriver = TestDriver(context, { newSandbox: true });
275
+
276
+ await testdriver.provision.chrome({
277
+ url: 'https://myapp.com/login'
278
+ });
279
+
280
+ await testdriver.find('email').type('user@example.com');
281
+ await testdriver.find('password').type('password123');
282
+ await testdriver.find('Login').click();
251
283
 
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
- }
284
+ const result = await testdriver.assert('Welcome message is visible');
285
+ expect(result).toBeTruthy();
286
+ });
287
+
288
+ it('should test VS Code extension', async (context) => {
289
+ const testdriver = TestDriver(context, { newSandbox: true });
290
+
291
+ await testdriver.provision.vscode({
292
+ extensions: ['ms-python.python']
293
+ });
294
+
295
+ await testdriver.pressKeys(['ctrl', 'shift', 'p']);
296
+ await testdriver.type('Python: Select Interpreter');
297
+ await testdriver.pressKeys(['enter']);
298
+
299
+ const result = await testdriver.assert('Python interpreter selector is visible');
300
+ expect(result).toBeTruthy();
301
+ });
302
+
303
+ it('should install and test CLI tool', async (context) => {
304
+ const testdriver = TestDriver(context, { newSandbox: true });
305
+
306
+ await testdriver.provision.installer({
307
+ url: 'https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_amd64.deb'
308
+ });
309
+
310
+ // Verify the tool works
311
+ await testdriver.exec('sh', 'bat --help', 10000);
312
+ });
258
313
  });
259
314
  ```
260
315
 
316
+ ## Best Practices
317
+
318
+ 1. **Use `newSandbox: true`** - Each test gets a clean environment
319
+ 2. **Enable Dashcam** - Great for debugging test failures (enabled by default)
320
+ 3. **Check assertions** - Always verify the expected state after actions
321
+ 4. **Use appropriate provision method** - Match the method to your test target
322
+ 5. **Handle async properly** - All provision methods return Promises
323
+
261
324
  ## See Also
262
325
 
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
326
+ - [Hooks API](./hooks.mdx) - TestDriver initialization
327
+ - [Find API](../api/find.mdx) - Element finding
328
+ - [Exec API](../api/exec.mdx) - Running shell commands
329
+ - [Assert API](../api/assert.mdx) - AI-powered assertions
@@ -185,7 +185,6 @@ await client.completeTestRun({
185
185
  **API (Backend)**
186
186
  - `api/models/TdTestRun.js` - Test run model
187
187
  - `api/models/TdTestCase.js` - Test case model
188
- - `api/models/TdSandbox.js` - Sandbox tracking model
189
188
  - `api/controllers/testdriver/testdriver-test-run-create.js` - Create test run endpoint
190
189
  - `api/controllers/testdriver/testdriver-test-run-complete.js` - Complete test run endpoint
191
190
  - `api/controllers/testdriver/testdriver-test-case-create.js` - Record test case endpoint
@@ -376,12 +376,6 @@ const run2 = await client.createTestRun({
376
376
  - Associated dashcam replay
377
377
  - Timing and duration
378
378
 
379
- ### TdSandbox
380
- - VM/sandbox lifecycle tracking
381
- - Platform and OS information
382
- - Dashcam integration status
383
- - Cost and usage metrics
384
-
385
379
  ### Replay
386
380
  - Dashcam recordings
387
381
  - Linked to test runs and cases
@@ -3,6 +3,7 @@ title: "act()"
3
3
  sidebarTitle: "act"
4
4
  description: "Execute natural language tasks using AI"
5
5
  icon: "wand-magic-sparkles"
6
+ tag: beta
6
7
  ---
7
8
 
8
9
  ## Overview
@@ -1,12 +1,16 @@
1
1
  ---
2
2
  title: "Quick Start"
3
3
  sidebarTitle: "Quickstart"
4
- description: "Get started with the TestDriver JavaScript SDK in minutes."
4
+ description: "Run your first computer-use test in minutes."
5
5
  icon: "rocket"
6
6
  mode: "wide"
7
7
  ---
8
8
 
9
- TestDriver makes it easy to write automated computer-use tests for web browsers, desktop apps, and more. In this quickstart, you'll write and run your first TestDriver test using Vitest in just a few minutes.
9
+ TestDriver makes it easy to write automated computer-use tests for web browsers, desktop apps, and more. Follow the directions below to run your first TestDriver test.
10
+
11
+ <Tip><a href="https://discord.com/invite/cWDFW8DzPm" target="_blank" rel="noreferrer">Join our Discord</a> if you have any questions or need help getting started!</Tip>
12
+
13
+ ## Get Started in 3 Steps
10
14
 
11
15
  <Steps>
12
16
  <Step title="Create a TestDriver Account">
@@ -20,7 +24,7 @@ TestDriver makes it easy to write automated computer-use tests for web browsers,
20
24
  arrow
21
25
  horizontal
22
26
  >
23
- Start for free. No credit-card required!
27
+ No credit-card required!
24
28
  </Card>
25
29
 
26
30
  </Step>
@@ -41,10 +45,10 @@ TestDriver makes it easy to write automated computer-use tests for web browsers,
41
45
  TestDriver uses Vitest as the test runner. To run your test, use:
42
46
 
43
47
  ```bash
44
- npx vitest run
48
+ vitest run
45
49
  ```
46
50
 
47
- This will spawn a sandbox, launch Chrome, navigate to the specified URL, and run your test commands.
51
+ This will spawn a sandbox, launch Chrome, and run the example test!
48
52
 
49
53
  </Step>
50
54
  </Steps>
@@ -84,14 +88,3 @@ TestDriver makes it easy to write automated computer-use tests for web browsers,
84
88
  Choose your complexity level
85
89
  </Card>
86
90
  </CardGroup>
87
-
88
- ## Why TestDriver v7?
89
-
90
- The v7 SDK offers advantages over YAML-based testing:
91
-
92
- - ✅ **Type Safety** - Full TypeScript support with IntelliSense
93
- - ✅ **Programmatic Control** - Use variables, loops, and functions
94
- - ✅ **Better Debugging** - Stack traces point to your actual code
95
- - ✅ **Automatic Lifecycle** - Presets handle setup and cleanup
96
- - ✅ **Framework Integration** - Works with Vitest, Jest, Mocha, etc.
97
- - ✅ **Video Replays** - Automatic Dashcam recording included