testdriverai 7.1.4 → 7.2.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.
- package/.github/workflows/acceptance.yaml +81 -0
- package/.github/workflows/publish.yaml +44 -0
- package/agent/index.js +18 -19
- package/agent/lib/commands.js +321 -121
- package/agent/lib/redraw.js +99 -39
- package/agent/lib/sandbox.js +98 -6
- package/agent/lib/sdk.js +25 -0
- package/agent/lib/system.js +2 -1
- package/agent/lib/validation.js +6 -6
- package/docs/docs.json +211 -101
- package/docs/snippets/tests/type-repeated-replay.mdx +1 -1
- package/docs/v7/_drafts/caching-selectors.mdx +24 -0
- package/docs/v7/api/act.mdx +1 -1
- package/docs/v7/api/assert.mdx +1 -1
- package/docs/v7/api/assertions.mdx +7 -7
- package/docs/v7/api/elements.mdx +78 -0
- package/docs/v7/api/find.mdx +38 -0
- package/docs/v7/api/focusApplication.mdx +2 -2
- package/docs/v7/api/hover.mdx +2 -2
- package/docs/v7/features/ai-native.mdx +57 -71
- package/docs/v7/features/application-logs.mdx +353 -0
- package/docs/v7/features/browser-logs.mdx +414 -0
- package/docs/v7/features/cache-management.mdx +402 -0
- package/docs/v7/features/continuous-testing.mdx +346 -0
- package/docs/v7/features/coverage.mdx +508 -0
- package/docs/v7/features/data-driven-testing.mdx +441 -0
- package/docs/v7/features/easy-to-write.mdx +2 -73
- package/docs/v7/features/enterprise.mdx +155 -39
- package/docs/v7/features/fast.mdx +63 -81
- package/docs/v7/features/managed-sandboxes.mdx +384 -0
- package/docs/v7/features/network-monitoring.mdx +568 -0
- package/docs/v7/features/observable.mdx +3 -22
- package/docs/v7/features/parallel-execution.mdx +381 -0
- package/docs/v7/features/powerful.mdx +1 -1
- package/docs/v7/features/reports.mdx +414 -0
- package/docs/v7/features/sandbox-customization.mdx +229 -0
- package/docs/v7/features/scalable.mdx +217 -2
- package/docs/v7/features/stable.mdx +106 -147
- package/docs/v7/features/system-performance.mdx +616 -0
- package/docs/v7/features/test-analytics.mdx +373 -0
- package/docs/v7/features/test-cases.mdx +393 -0
- package/docs/v7/features/test-replays.mdx +408 -0
- package/docs/v7/features/test-reports.mdx +308 -0
- package/docs/v7/getting-started/{running-and-debugging.mdx → debugging-tests.mdx} +12 -142
- package/docs/v7/getting-started/quickstart.mdx +22 -305
- package/docs/v7/getting-started/running-tests.mdx +173 -0
- package/docs/v7/overview/what-is-testdriver.mdx +2 -14
- package/docs/v7/presets/chrome-extension.mdx +147 -122
- package/interfaces/cli/commands/init.js +3 -3
- package/interfaces/cli/lib/base.js +3 -2
- package/interfaces/logger.js +0 -2
- package/interfaces/shared-test-state.mjs +0 -5
- package/interfaces/vitest-plugin.mjs +69 -42
- package/lib/core/Dashcam.js +65 -66
- package/lib/vitest/hooks.mjs +42 -50
- package/package.json +1 -1
- package/sdk-log-formatter.js +350 -175
- package/sdk.js +431 -116
- package/setup/aws/cloudformation.yaml +2 -2
- package/setup/aws/self-hosted.yml +1 -1
- package/test/testdriver/chrome-extension.test.mjs +55 -72
- package/test/testdriver/element-not-found.test.mjs +2 -1
- package/test/testdriver/hover-image.test.mjs +1 -1
- package/test/testdriver/scroll-until-text.test.mjs +10 -6
- package/test/testdriver/setup/lifecycleHelpers.mjs +19 -24
- package/test/testdriver/setup/testHelpers.mjs +18 -23
- package/vitest.config.mjs +3 -3
- package/.github/workflows/linux-tests.yml +0 -28
- package/docs/v7/getting-started/generating-tests.mdx +0 -525
- package/test/testdriver/auto-cache-key-demo.test.mjs +0 -56
|
@@ -1,97 +1,10 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
description: "
|
|
4
|
-
icon: "
|
|
2
|
+
title: "Debugging Tests"
|
|
3
|
+
description: "Debug test failures with Dashcam replays, logs, and error analysis"
|
|
4
|
+
icon: "bug"
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Learn how to
|
|
8
|
-
|
|
9
|
-
## Running Tests
|
|
10
|
-
|
|
11
|
-
TestDriver works with Vitest's powerful test runner:
|
|
12
|
-
|
|
13
|
-
<Tabs>
|
|
14
|
-
<Tab title="Run All Tests">
|
|
15
|
-
```bash
|
|
16
|
-
# Run all tests once
|
|
17
|
-
npx vitest run
|
|
18
|
-
|
|
19
|
-
# Run in watch mode
|
|
20
|
-
npx vitest
|
|
21
|
-
|
|
22
|
-
# Run with coverage
|
|
23
|
-
npx vitest run --coverage
|
|
24
|
-
```
|
|
25
|
-
</Tab>
|
|
26
|
-
|
|
27
|
-
<Tab title="Run Specific Tests">
|
|
28
|
-
```bash
|
|
29
|
-
# Run specific file
|
|
30
|
-
npx vitest run login.test.js
|
|
31
|
-
|
|
32
|
-
# Run multiple files
|
|
33
|
-
npx vitest run login.test.js checkout.test.js
|
|
34
|
-
|
|
35
|
-
# Run tests matching pattern
|
|
36
|
-
npx vitest run --grep "login"
|
|
37
|
-
|
|
38
|
-
# Run tests in specific folder
|
|
39
|
-
npx vitest run tests/e2e/
|
|
40
|
-
```
|
|
41
|
-
</Tab>
|
|
42
|
-
|
|
43
|
-
<Tab title="Watch Mode">
|
|
44
|
-
```bash
|
|
45
|
-
# Watch mode - reruns on file changes
|
|
46
|
-
npx vitest
|
|
47
|
-
|
|
48
|
-
# Watch only changed tests
|
|
49
|
-
npx vitest --changed
|
|
50
|
-
|
|
51
|
-
# Watch specific file
|
|
52
|
-
npx vitest login.test.js
|
|
53
|
-
```
|
|
54
|
-
</Tab>
|
|
55
|
-
|
|
56
|
-
<Tab title="Parallel Execution">
|
|
57
|
-
```bash
|
|
58
|
-
# Control concurrency
|
|
59
|
-
npx vitest run --maxConcurrency=5
|
|
60
|
-
|
|
61
|
-
# Run with specific thread count
|
|
62
|
-
npx vitest run --threads --minThreads=2 --maxThreads=8
|
|
63
|
-
```
|
|
64
|
-
</Tab>
|
|
65
|
-
</Tabs>
|
|
66
|
-
|
|
67
|
-
## Test Output
|
|
68
|
-
|
|
69
|
-
Understanding test output:
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
$ npx vitest run
|
|
73
|
-
|
|
74
|
-
✓ login.test.js (3) 23.4s
|
|
75
|
-
✓ user can login with valid credentials 12.3s
|
|
76
|
-
✓ shows error for invalid email 5.6s
|
|
77
|
-
✓ shows error for wrong password 5.5s
|
|
78
|
-
|
|
79
|
-
✓ checkout.test.js (2) 34.7s
|
|
80
|
-
✓ user can complete checkout 28.9s
|
|
81
|
-
✓ validates credit card format 5.8s
|
|
82
|
-
|
|
83
|
-
Test Files 2 passed (2)
|
|
84
|
-
Tests 5 passed (5)
|
|
85
|
-
Duration 58.12s
|
|
86
|
-
|
|
87
|
-
📹 Dashcam Replays:
|
|
88
|
-
- https://console.testdriver.ai/dashcam/abc123
|
|
89
|
-
- https://console.testdriver.ai/dashcam/def456
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
<Tip>
|
|
93
|
-
Click the Dashcam URLs to watch video replays of your tests!
|
|
94
|
-
</Tip>
|
|
7
|
+
Learn how to debug TestDriver test failures using video replays, logs, and rich error information.
|
|
95
8
|
|
|
96
9
|
## Debugging with Dashcam
|
|
97
10
|
|
|
@@ -389,33 +302,6 @@ test('check network', async (context) => {
|
|
|
389
302
|
});
|
|
390
303
|
```
|
|
391
304
|
|
|
392
|
-
## Performance Profiling
|
|
393
|
-
|
|
394
|
-
Identify slow tests:
|
|
395
|
-
|
|
396
|
-
```bash
|
|
397
|
-
# Run with reporter showing timing
|
|
398
|
-
npx vitest run --reporter=verbose
|
|
399
|
-
|
|
400
|
-
# Output shows duration per test:
|
|
401
|
-
✓ slow-test.test.js > user can checkout (34.7s)
|
|
402
|
-
→ find('product') (2.1s)
|
|
403
|
-
→ click() (0.4s)
|
|
404
|
-
→ find('add to cart') (1.8s)
|
|
405
|
-
→ click() (0.3s)
|
|
406
|
-
→ find('checkout') (28.9s) ← SLOW!
|
|
407
|
-
→ click() (0.5s)
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
Optimize slow operations:
|
|
411
|
-
|
|
412
|
-
1. **Enable caching** - First run is slow, subsequent runs are fast
|
|
413
|
-
2. **Use parallel execution** - Run tests concurrently
|
|
414
|
-
3. **Check network delays** - Look for slow API calls in Dashcam
|
|
415
|
-
4. **Optimize selectors** - More specific = faster matching
|
|
416
|
-
|
|
417
|
-
[Performance optimization guide](/v7/guides/performance)
|
|
418
|
-
|
|
419
305
|
## Debugging in CI/CD
|
|
420
306
|
|
|
421
307
|
When tests fail in CI:
|
|
@@ -459,39 +345,23 @@ When tests fail in CI:
|
|
|
459
345
|
</Step>
|
|
460
346
|
</Steps>
|
|
461
347
|
|
|
462
|
-
## Vitest UI
|
|
463
|
-
|
|
464
|
-
Use Vitest UI for interactive debugging:
|
|
465
|
-
|
|
466
|
-
```bash
|
|
467
|
-
# Start Vitest UI
|
|
468
|
-
npx vitest --ui
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
Open http://localhost:51204 to see:
|
|
472
|
-
- Test file tree
|
|
473
|
-
- Test status and duration
|
|
474
|
-
- Console output
|
|
475
|
-
- Re-run individual tests
|
|
476
|
-
- Filter and search tests
|
|
477
|
-
|
|
478
348
|
## Next Steps
|
|
479
349
|
|
|
480
350
|
<CardGroup cols={2}>
|
|
481
351
|
<Card
|
|
482
|
-
title="
|
|
483
|
-
icon="
|
|
484
|
-
href="/v7/getting-started/
|
|
352
|
+
title="Running Tests"
|
|
353
|
+
icon="play"
|
|
354
|
+
href="/v7/getting-started/running-tests"
|
|
485
355
|
>
|
|
486
|
-
|
|
356
|
+
Learn how to run tests efficiently
|
|
487
357
|
</Card>
|
|
488
358
|
|
|
489
359
|
<Card
|
|
490
|
-
title="
|
|
491
|
-
icon="
|
|
492
|
-
href="/v7/
|
|
360
|
+
title="Setting Up in CI"
|
|
361
|
+
icon="arrows-spin"
|
|
362
|
+
href="/v7/getting-started/setting-up-in-ci"
|
|
493
363
|
>
|
|
494
|
-
|
|
364
|
+
Run tests in CI/CD pipelines
|
|
495
365
|
</Card>
|
|
496
366
|
|
|
497
367
|
<Card
|
|
@@ -1,337 +1,54 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Quick Start"
|
|
3
3
|
sidebarTitle: "Quickstart"
|
|
4
|
-
description: "Get started with the TestDriver JavaScript SDK in
|
|
4
|
+
description: "Get started with the TestDriver JavaScript SDK in minutes."
|
|
5
5
|
icon: "rocket"
|
|
6
6
|
mode: "wide"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
TestDriver
|
|
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.
|
|
10
10
|
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
- Create package.json with test scripts
|
|
14
|
-
- Set up Vitest configuration
|
|
15
|
-
- Create example tests
|
|
16
|
-
- Add GitHub Actions workflow
|
|
17
|
-
- Install dependencies automatically
|
|
18
|
-
- Prompt for your API key (saved to .env)
|
|
11
|
+
<Steps>
|
|
12
|
+
<Step title="Create a TestDriver Account">
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
npm install -g testdriverai
|
|
22
|
-
testdriverai init
|
|
23
|
-
```
|
|
14
|
+
You will need a TestDriver account to get an API key.
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
<Card
|
|
17
|
+
title="Sign Up for TestDriver"
|
|
18
|
+
icon="user-plus"
|
|
19
|
+
href="https://app.testdriver.ai/team"
|
|
20
|
+
arrow
|
|
21
|
+
horizontal
|
|
22
|
+
>
|
|
23
|
+
Start for free. No credit-card required!
|
|
24
|
+
</Card>
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
</Step>
|
|
29
27
|
<Step title="Install TestDriver">
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
Use `npx` to quickly set up an example project:
|
|
32
30
|
|
|
33
31
|
```bash
|
|
34
|
-
|
|
32
|
+
npx testdriverai@beta init
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<Step title="Write Your First Test">
|
|
40
|
-
|
|
41
|
-
Create `test.test.js` and add your API key from [console.testdriver.ai](https://console.testdriver.ai):
|
|
42
|
-
|
|
43
|
-
<Tabs>
|
|
44
|
-
<Tab title="Fast">
|
|
45
|
-
```javascript test.test.js
|
|
46
|
-
import { test } from 'vitest';
|
|
47
|
-
import { TestDriver } from 'testdriverai/vitest/hooks';
|
|
48
|
-
|
|
49
|
-
test('my first test', async (context) => {
|
|
50
|
-
const testdriver = TestDriver(context, {
|
|
51
|
-
headless: true,
|
|
52
|
-
apiKey: 'tdai-1234567890abcdef' // Your API key from console.testdriver.ai
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
await testdriver.provision.chrome({ url: 'https://example.com' });
|
|
56
|
-
|
|
57
|
-
await testdriver.find('More information link').click();
|
|
58
|
-
await testdriver.assert('IANA page is visible');
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
<Warning>
|
|
63
|
-
Don't commit API keys to version control!
|
|
64
|
-
</Warning>
|
|
65
|
-
</Tab>
|
|
66
|
-
|
|
67
|
-
<Tab title="Secure with .env (Recommended)">
|
|
68
|
-
Create `.env`:
|
|
69
|
-
|
|
70
|
-
```bash .env
|
|
71
|
-
TD_API_KEY=tdai-1234567890abcdef
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Then create `test.test.js`:
|
|
75
|
-
|
|
76
|
-
```javascript test.test.js
|
|
77
|
-
import { test } from 'vitest';
|
|
78
|
-
import { TestDriver } from 'testdriverai/vitest/hooks';
|
|
79
|
-
|
|
80
|
-
test('my first test', async (context) => {
|
|
81
|
-
const testdriver = TestDriver(context, { headless: true });
|
|
82
|
-
// apiKey automatically read from process.env.TD_API_KEY
|
|
83
|
-
|
|
84
|
-
await testdriver.provision.chrome({ url: 'https://example.com' });
|
|
85
|
-
|
|
86
|
-
await testdriver.find('More information link').click();
|
|
87
|
-
await testdriver.assert('IANA page is visible');
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
<Tip>
|
|
92
|
-
Add `.env` to your `.gitignore` file!
|
|
93
|
-
</Tip>
|
|
94
|
-
</Tab>
|
|
95
|
-
</Tabs>
|
|
35
|
+
This will walk you through creating a new project folder, installing dependencies, and setting up your API key.
|
|
96
36
|
|
|
97
37
|
</Step>
|
|
98
38
|
|
|
99
39
|
<Step title="Run Your Test">
|
|
40
|
+
|
|
41
|
+
TestDriver uses Vitest as the test runner. To run your test, use:
|
|
100
42
|
|
|
101
43
|
```bash
|
|
102
44
|
npx vitest run
|
|
103
45
|
```
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<Tip>
|
|
108
|
-
The `chrome()` preset automatically handles authentication, browser launch, and cleanup.
|
|
109
|
-
</Tip>
|
|
46
|
+
|
|
47
|
+
This will spawn a sandbox, launch Chrome, navigate to the specified URL, and run your test commands.
|
|
110
48
|
|
|
111
49
|
</Step>
|
|
112
50
|
</Steps>
|
|
113
51
|
|
|
114
|
-
## What Just Happened?
|
|
115
|
-
|
|
116
|
-
The TestDriver hook with `provision.chrome()` automatically:
|
|
117
|
-
1. ✅ Connected to a TestDriver sandbox
|
|
118
|
-
2. ✅ Launched Chrome browser
|
|
119
|
-
3. ✅ Navigated to your URL
|
|
120
|
-
4. ✅ Started recording with Dashcam
|
|
121
|
-
5. ✅ Cleaned up everything when done
|
|
122
|
-
|
|
123
|
-
No manual setup or teardown needed!
|
|
124
|
-
|
|
125
|
-
## Chainable API
|
|
126
|
-
|
|
127
|
-
TestDriver uses a chainable promise API for elegant test writing:
|
|
128
|
-
|
|
129
|
-
```javascript
|
|
130
|
-
// ✅ Chainable - find and interact in one line
|
|
131
|
-
await testdriver.find('submit button').click();
|
|
132
|
-
await testdriver.find('menu item').hover();
|
|
133
|
-
await testdriver.find('checkbox').doubleClick();
|
|
134
|
-
|
|
135
|
-
// ✅ Also works - traditional two-step
|
|
136
|
-
const button = await testdriver.find('submit button');
|
|
137
|
-
await button.click();
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**Available chainable methods:**
|
|
141
|
-
- `.click()` - Click the element
|
|
142
|
-
- `.hover()` - Hover over the element
|
|
143
|
-
- `.doubleClick()` - Double-click the element
|
|
144
|
-
- `.rightClick()` - Right-click the element
|
|
145
|
-
- `.mouseDown()` - Press mouse button down
|
|
146
|
-
- `.mouseUp()` - Release mouse button
|
|
147
|
-
- `.type(text)` - Type text (for input elements)
|
|
148
|
-
|
|
149
|
-
<Tip>
|
|
150
|
-
Use chainable syntax for cleaner, more readable test code!
|
|
151
|
-
</Tip>
|
|
152
|
-
|
|
153
|
-
## More Examples
|
|
154
|
-
|
|
155
|
-
### Login Flow
|
|
156
|
-
|
|
157
|
-
```javascript login.test.js
|
|
158
|
-
import { test, expect } from 'vitest';
|
|
159
|
-
import { chrome } from 'testdriverai/presets';
|
|
160
|
-
|
|
161
|
-
test('user can login', async (context) => {
|
|
162
|
-
const { testdriver } = await chrome(context, {
|
|
163
|
-
url: 'https://myapp.com/login'
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// Use chainable syntax for cleaner code
|
|
167
|
-
await testdriver.find('email input').type('user@example.com');
|
|
168
|
-
await testdriver.find('password input').type('password123');
|
|
169
|
-
await testdriver.find('Login button').click();
|
|
170
|
-
|
|
171
|
-
const result = await testdriver.assert('Dashboard is visible');
|
|
172
|
-
expect(result).toBeTruthy();
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### VS Code Extension
|
|
177
|
-
|
|
178
|
-
```javascript extension.test.js
|
|
179
|
-
import { test } from 'vitest';
|
|
180
|
-
import { vscode } from 'testdriverai/presets';
|
|
181
|
-
|
|
182
|
-
test('create python file', async (context) => {
|
|
183
|
-
const { vscode } = await vscode(context, {
|
|
184
|
-
workspace: '/tmp/project',
|
|
185
|
-
extensions: ['ms-python.python']
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
await vscode.pressKeys(['cmd', 'shift', 'p']);
|
|
189
|
-
await vscode.type('Python: Create New File');
|
|
190
|
-
await vscode.pressKeys(['enter']);
|
|
191
|
-
|
|
192
|
-
await vscode.assert('Untitled Python file is open');
|
|
193
|
-
});
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Electron App
|
|
197
|
-
|
|
198
|
-
```javascript electron.test.js
|
|
199
|
-
import { test } from 'vitest';
|
|
200
|
-
import { electron } from 'testdriverai/presets';
|
|
201
|
-
|
|
202
|
-
test('electron app menu', async (context) => {
|
|
203
|
-
const { app } = await electron(context, {
|
|
204
|
-
appPath: './dist/my-app'
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
await app.find('File menu').click();
|
|
208
|
-
await app.find('New Document').click();
|
|
209
|
-
|
|
210
|
-
await app.assert('New document window opens');
|
|
211
|
-
});
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
## Three Levels of Control
|
|
215
|
-
|
|
216
|
-
Choose your complexity level:
|
|
217
|
-
|
|
218
|
-
<CardGroup cols={3}>
|
|
219
|
-
<Card title="Presets (Easiest)" icon="rocket" href="/v7/progressive-apis/PROVISION">
|
|
220
|
-
**One-line setup**
|
|
221
|
-
```javascript
|
|
222
|
-
const { testdriver } = await chrome(context, { url });
|
|
223
|
-
```
|
|
224
|
-
</Card>
|
|
225
|
-
|
|
226
|
-
<Card title="Hooks (Flexible)" icon="link" href="/v7/progressive-apis/HOOKS">
|
|
227
|
-
**More control**
|
|
228
|
-
```javascript
|
|
229
|
-
const client = useTestDriver(context);
|
|
230
|
-
const dashcam = useDashcam(context, client);
|
|
231
|
-
```
|
|
232
|
-
</Card>
|
|
233
|
-
|
|
234
|
-
<Card title="Core (Full Control)" icon="code" href="/v7/progressive-apis/CORE">
|
|
235
|
-
**Manual everything**
|
|
236
|
-
```javascript
|
|
237
|
-
const client = new TestDriver(apiKey);
|
|
238
|
-
await client.connect();
|
|
239
|
-
```
|
|
240
|
-
</Card>
|
|
241
|
-
</CardGroup>
|
|
242
|
-
|
|
243
|
-
## Video Replays
|
|
244
|
-
|
|
245
|
-
Tests automatically record with Dashcam for easy debugging:
|
|
246
|
-
|
|
247
|
-
```javascript
|
|
248
|
-
test('with replay', async (context) => {
|
|
249
|
-
const { testdriver, dashcam } = await chrome(context, {
|
|
250
|
-
url: 'https://example.com'
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
await testdriver.find('button').click();
|
|
254
|
-
|
|
255
|
-
// After test, check the replay
|
|
256
|
-
console.log('Watch replay:', dashcam.url);
|
|
257
|
-
});
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
View all replays at [console.testdriver.ai](https://console.testdriver.ai)
|
|
261
|
-
|
|
262
|
-
## Optional Configuration
|
|
263
|
-
|
|
264
|
-
For better developer experience, create `vitest.config.mjs`:
|
|
265
|
-
|
|
266
|
-
```javascript vitest.config.mjs
|
|
267
|
-
import { defineConfig } from 'vitest/config';
|
|
268
|
-
|
|
269
|
-
export default defineConfig({
|
|
270
|
-
test: {
|
|
271
|
-
testTimeout: 120000, // 2 minutes per test
|
|
272
|
-
hookTimeout: 120000, // 2 minutes for setup
|
|
273
|
-
},
|
|
274
|
-
});
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
## Common Commands
|
|
278
|
-
|
|
279
|
-
```bash
|
|
280
|
-
# Run all tests
|
|
281
|
-
npx vitest run
|
|
282
|
-
|
|
283
|
-
# Run all tests in watch mode
|
|
284
|
-
npx vitest
|
|
285
|
-
|
|
286
|
-
# Run specific file
|
|
287
|
-
npx vitest run login.test.js
|
|
288
|
-
|
|
289
|
-
# Run in watch mode
|
|
290
|
-
npx vitest --watch
|
|
291
|
-
|
|
292
|
-
# Run tests matching pattern
|
|
293
|
-
npx vitest run --grep "login"
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Troubleshooting
|
|
297
|
-
|
|
298
|
-
### Test times out
|
|
299
|
-
|
|
300
|
-
Increase the timeout in your config:
|
|
301
|
-
|
|
302
|
-
```javascript vitest.config.mjs
|
|
303
|
-
export default defineConfig({
|
|
304
|
-
test: {
|
|
305
|
-
testTimeout: 180000, // 3 minutes
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### API key not found
|
|
311
|
-
|
|
312
|
-
Either pass it directly to the preset:
|
|
313
|
-
|
|
314
|
-
```javascript
|
|
315
|
-
const { testdriver } = await chrome(context, {
|
|
316
|
-
url: 'https://example.com',
|
|
317
|
-
apiKey: 'tdai-your-api-key-here'
|
|
318
|
-
});
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
Or create a `.env` file in your project root:
|
|
322
|
-
|
|
323
|
-
```bash .env
|
|
324
|
-
TD_API_KEY=tdai-your-api-key-here
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Import errors
|
|
328
|
-
|
|
329
|
-
Make sure you installed testdriverai:
|
|
330
|
-
|
|
331
|
-
```bash
|
|
332
|
-
npm install --save-dev testdriverai
|
|
333
|
-
```
|
|
334
|
-
|
|
335
52
|
## Next Steps
|
|
336
53
|
|
|
337
54
|
<CardGroup cols={2}>
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Running Tests"
|
|
3
|
+
description: "Run TestDriver tests with Vitest test runner"
|
|
4
|
+
icon: "play"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Learn how to run TestDriver tests efficiently with Vitest's powerful test runner.
|
|
8
|
+
|
|
9
|
+
## Running Tests
|
|
10
|
+
|
|
11
|
+
TestDriver works with Vitest's powerful test runner:
|
|
12
|
+
|
|
13
|
+
<Tabs>
|
|
14
|
+
<Tab title="Run All Tests">
|
|
15
|
+
```bash
|
|
16
|
+
# Run all tests once
|
|
17
|
+
npx vitest run
|
|
18
|
+
|
|
19
|
+
# Run in watch mode
|
|
20
|
+
npx vitest
|
|
21
|
+
|
|
22
|
+
# Run with coverage
|
|
23
|
+
npx vitest run --coverage
|
|
24
|
+
```
|
|
25
|
+
</Tab>
|
|
26
|
+
|
|
27
|
+
<Tab title="Run Specific Tests">
|
|
28
|
+
```bash
|
|
29
|
+
# Run specific file
|
|
30
|
+
npx vitest run login.test.js
|
|
31
|
+
|
|
32
|
+
# Run multiple files
|
|
33
|
+
npx vitest run login.test.js checkout.test.js
|
|
34
|
+
|
|
35
|
+
# Run tests matching pattern
|
|
36
|
+
npx vitest run --grep "login"
|
|
37
|
+
|
|
38
|
+
# Run tests in specific folder
|
|
39
|
+
npx vitest run tests/e2e/
|
|
40
|
+
```
|
|
41
|
+
</Tab>
|
|
42
|
+
|
|
43
|
+
<Tab title="Watch Mode">
|
|
44
|
+
```bash
|
|
45
|
+
# Watch mode - reruns on file changes
|
|
46
|
+
npx vitest
|
|
47
|
+
|
|
48
|
+
# Watch only changed tests
|
|
49
|
+
npx vitest --changed
|
|
50
|
+
|
|
51
|
+
# Watch specific file
|
|
52
|
+
npx vitest login.test.js
|
|
53
|
+
```
|
|
54
|
+
</Tab>
|
|
55
|
+
|
|
56
|
+
<Tab title="Parallel Execution">
|
|
57
|
+
```bash
|
|
58
|
+
# Control concurrency
|
|
59
|
+
npx vitest run --maxConcurrency=5
|
|
60
|
+
|
|
61
|
+
# Run with specific thread count
|
|
62
|
+
npx vitest run --threads --minThreads=2 --maxThreads=8
|
|
63
|
+
```
|
|
64
|
+
</Tab>
|
|
65
|
+
</Tabs>
|
|
66
|
+
|
|
67
|
+
## Test Output
|
|
68
|
+
|
|
69
|
+
Understanding test output:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
$ npx vitest run
|
|
73
|
+
|
|
74
|
+
✓ login.test.js (3) 23.4s
|
|
75
|
+
✓ user can login with valid credentials 12.3s
|
|
76
|
+
✓ shows error for invalid email 5.6s
|
|
77
|
+
✓ shows error for wrong password 5.5s
|
|
78
|
+
|
|
79
|
+
✓ checkout.test.js (2) 34.7s
|
|
80
|
+
✓ user can complete checkout 28.9s
|
|
81
|
+
✓ validates credit card format 5.8s
|
|
82
|
+
|
|
83
|
+
Test Files 2 passed (2)
|
|
84
|
+
Tests 5 passed (5)
|
|
85
|
+
Duration 58.12s
|
|
86
|
+
|
|
87
|
+
📹 Dashcam Replays:
|
|
88
|
+
- https://console.testdriver.ai/dashcam/abc123
|
|
89
|
+
- https://console.testdriver.ai/dashcam/def456
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
<Tip>
|
|
93
|
+
Click the Dashcam URLs to watch video replays of your tests!
|
|
94
|
+
</Tip>
|
|
95
|
+
|
|
96
|
+
## Performance Profiling
|
|
97
|
+
|
|
98
|
+
Identify slow tests:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Run with reporter showing timing
|
|
102
|
+
npx vitest run --reporter=verbose
|
|
103
|
+
|
|
104
|
+
# Output shows duration per test:
|
|
105
|
+
✓ slow-test.test.js > user can checkout (34.7s)
|
|
106
|
+
→ find('product') (2.1s)
|
|
107
|
+
→ click() (0.4s)
|
|
108
|
+
→ find('add to cart') (1.8s)
|
|
109
|
+
→ click() (0.3s)
|
|
110
|
+
→ find('checkout') (28.9s) ← SLOW!
|
|
111
|
+
→ click() (0.5s)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Optimize slow operations:
|
|
115
|
+
|
|
116
|
+
1. **Enable caching** - First run is slow, subsequent runs are fast
|
|
117
|
+
2. **Use parallel execution** - Run tests concurrently
|
|
118
|
+
3. **Check network delays** - Look for slow API calls in Dashcam
|
|
119
|
+
4. **Optimize selectors** - More specific = faster matching
|
|
120
|
+
|
|
121
|
+
[Performance optimization guide](/v7/guides/performance)
|
|
122
|
+
|
|
123
|
+
## Vitest UI
|
|
124
|
+
|
|
125
|
+
Use Vitest UI for interactive debugging:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Start Vitest UI
|
|
129
|
+
npx vitest --ui
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Open http://localhost:51204 to see:
|
|
133
|
+
- Test file tree
|
|
134
|
+
- Test status and duration
|
|
135
|
+
- Console output
|
|
136
|
+
- Re-run individual tests
|
|
137
|
+
- Filter and search tests
|
|
138
|
+
|
|
139
|
+
## Next Steps
|
|
140
|
+
|
|
141
|
+
<CardGroup cols={2}>
|
|
142
|
+
<Card
|
|
143
|
+
title="Debugging Tests"
|
|
144
|
+
icon="bug"
|
|
145
|
+
href="/v7/getting-started/debugging-tests"
|
|
146
|
+
>
|
|
147
|
+
Debug test failures with Dashcam replays
|
|
148
|
+
</Card>
|
|
149
|
+
|
|
150
|
+
<Card
|
|
151
|
+
title="Setting Up in CI"
|
|
152
|
+
icon="arrows-spin"
|
|
153
|
+
href="/v7/getting-started/setting-up-in-ci"
|
|
154
|
+
>
|
|
155
|
+
Run tests in CI/CD pipelines
|
|
156
|
+
</Card>
|
|
157
|
+
|
|
158
|
+
<Card
|
|
159
|
+
title="Observable Features"
|
|
160
|
+
icon="microscope"
|
|
161
|
+
href="/v7/features/observable"
|
|
162
|
+
>
|
|
163
|
+
Complete observability guide
|
|
164
|
+
</Card>
|
|
165
|
+
|
|
166
|
+
<Card
|
|
167
|
+
title="Performance Guide"
|
|
168
|
+
icon="gauge-high"
|
|
169
|
+
href="/v7/guides/performance"
|
|
170
|
+
>
|
|
171
|
+
Optimize test performance
|
|
172
|
+
</Card>
|
|
173
|
+
</CardGroup>
|