testdriverai 7.9.32-test → 7.9.34-test

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 (77) hide show
  1. package/ai/skills/testdriver:ai/SKILL.md +204 -0
  2. package/ai/skills/testdriver:assert/SKILL.md +315 -0
  3. package/ai/skills/testdriver:aws-setup/SKILL.md +448 -0
  4. package/ai/skills/testdriver:cache/SKILL.md +221 -0
  5. package/ai/skills/testdriver:caching/SKILL.md +124 -0
  6. package/ai/skills/testdriver:captcha/SKILL.md +158 -0
  7. package/ai/skills/testdriver:ci-cd/SKILL.md +602 -0
  8. package/ai/skills/testdriver:click/SKILL.md +286 -0
  9. package/ai/skills/testdriver:client/SKILL.md +477 -0
  10. package/ai/skills/testdriver:customizing-devices/SKILL.md +319 -0
  11. package/ai/skills/testdriver:dashcam/SKILL.md +451 -0
  12. package/ai/skills/testdriver:debugging-with-screenshots/SKILL.md +415 -0
  13. package/ai/skills/testdriver:device-config/SKILL.md +317 -0
  14. package/ai/skills/testdriver:double-click/SKILL.md +102 -0
  15. package/ai/skills/testdriver:elements/SKILL.md +605 -0
  16. package/ai/skills/testdriver:enterprise/SKILL.md +7 -0
  17. package/ai/skills/testdriver:errors/SKILL.md +246 -0
  18. package/ai/skills/testdriver:events/SKILL.md +356 -0
  19. package/ai/skills/testdriver:exec/SKILL.md +317 -0
  20. package/ai/skills/testdriver:find/SKILL.md +860 -0
  21. package/ai/skills/testdriver:focus-application/SKILL.md +293 -0
  22. package/ai/skills/testdriver:generating-tests/SKILL.md +36 -0
  23. package/ai/skills/testdriver:hosted/SKILL.md +156 -0
  24. package/ai/skills/testdriver:hover/SKILL.md +278 -0
  25. package/ai/skills/testdriver:locating-elements/SKILL.md +71 -0
  26. package/ai/skills/testdriver:making-assertions/SKILL.md +32 -0
  27. package/ai/skills/testdriver:mcp/SKILL.md +7 -0
  28. package/ai/skills/testdriver:mouse-down/SKILL.md +161 -0
  29. package/ai/skills/testdriver:mouse-up/SKILL.md +164 -0
  30. package/ai/skills/testdriver:parse/SKILL.md +236 -0
  31. package/ai/skills/testdriver:performing-actions/SKILL.md +53 -0
  32. package/ai/skills/testdriver:press-keys/SKILL.md +348 -0
  33. package/ai/skills/testdriver:provision/SKILL.md +331 -0
  34. package/ai/skills/testdriver:quickstart/SKILL.md +172 -0
  35. package/ai/skills/testdriver:redraw/SKILL.md +214 -0
  36. package/ai/skills/testdriver:reusable-code/SKILL.md +249 -0
  37. package/ai/skills/testdriver:right-click/SKILL.md +123 -0
  38. package/ai/skills/testdriver:running-tests/SKILL.md +185 -0
  39. package/ai/skills/testdriver:screenshot/SKILL.md +248 -0
  40. package/ai/skills/testdriver:screenshots/SKILL.md +184 -0
  41. package/ai/skills/testdriver:scroll/SKILL.md +205 -0
  42. package/ai/skills/testdriver:secrets/SKILL.md +115 -0
  43. package/ai/skills/testdriver:self-hosted/SKILL.md +147 -0
  44. package/ai/skills/testdriver:test-results-json/SKILL.md +257 -0
  45. package/ai/skills/testdriver:testdriver/SKILL.md +624 -0
  46. package/ai/skills/testdriver:type/SKILL.md +357 -0
  47. package/ai/skills/testdriver:variables/SKILL.md +111 -0
  48. package/ai/skills/testdriver:wait/SKILL.md +50 -0
  49. package/ai/skills/testdriver:waiting-for-elements/SKILL.md +90 -0
  50. package/ai/skills/testdriver:what-is-testdriver/SKILL.md +54 -0
  51. package/docs/_data/examples-manifest.json +42 -42
  52. package/docs/v7/debugging-with-screenshots.mdx +14 -0
  53. package/docs/v7/examples/ai.mdx +1 -1
  54. package/docs/v7/examples/assert.mdx +1 -1
  55. package/docs/v7/examples/chrome-extension.mdx +2 -2
  56. package/docs/v7/examples/element-not-found.mdx +1 -1
  57. package/docs/v7/examples/exec-output.mdx +1 -1
  58. package/docs/v7/examples/exec-pwsh.mdx +1 -1
  59. package/docs/v7/examples/findall-coffee-icons.mdx +1 -1
  60. package/docs/v7/examples/focus-window.mdx +1 -1
  61. package/docs/v7/examples/hover-image.mdx +1 -1
  62. package/docs/v7/examples/hover-text-with-description.mdx +1 -1
  63. package/docs/v7/examples/hover-text.mdx +1 -1
  64. package/docs/v7/examples/installer.mdx +1 -1
  65. package/docs/v7/examples/launch-vscode-linux.mdx +1 -1
  66. package/docs/v7/examples/parse.mdx +1 -1
  67. package/docs/v7/examples/press-keys.mdx +1 -1
  68. package/docs/v7/examples/prompt.mdx +1 -1
  69. package/docs/v7/examples/scroll-keyboard.mdx +1 -1
  70. package/docs/v7/examples/scroll-until-image.mdx +1 -1
  71. package/docs/v7/examples/scroll.mdx +1 -1
  72. package/docs/v7/examples/type.mdx +1 -1
  73. package/docs/v7/examples/windows-installer.mdx +1 -1
  74. package/docs/v7/find.mdx +33 -0
  75. package/examples/chrome-extension.test.mjs +1 -1
  76. package/package.json +1 -1
  77. package/setup/aws/spawn-runner.sh +24 -3
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: testdriver:running-tests
3
+ description: Run TestDriver tests with Vitest test runner
4
+ ---
5
+ <!-- Generated from running-tests.mdx. DO NOT EDIT. -->
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
+ <Info>
14
+ Install Vitest globally for best results: `npm install vitest -g`
15
+ </Info>
16
+
17
+ ### Run All Tests
18
+
19
+ ```bash
20
+ vitest run
21
+ ```
22
+
23
+ Executes all test files in your project once and exits. Vitest automatically discovers files matching patterns like `*.test.js`, `*.test.mjs`, or `*.spec.js`.
24
+
25
+ ### Run with Coverage
26
+
27
+ ```bash
28
+ vitest run --coverage
29
+ ```
30
+
31
+ Generates a code coverage report showing which lines of your source code were executed during tests. Coverage helps identify untested code paths. Results are displayed in the terminal and saved to a `coverage/` directory.
32
+
33
+ <Info>
34
+ Coverage requires the `@vitest/coverage-v8` package. Install it with `npm install -D @vitest/coverage-v8`.
35
+ </Info>
36
+
37
+ ### Run Specific Tests
38
+
39
+ ```bash
40
+ vitest run login.test.js
41
+ ```
42
+
43
+ Runs only the specified test file. Useful when debugging a single test or working on a specific feature.
44
+
45
+ ```bash
46
+ vitest run login.test.js checkout.test.js
47
+ ```
48
+
49
+ Runs multiple specific test files. List as many files as needed, separated by spaces.
50
+
51
+ ### Filter Tests by Name
52
+
53
+ ```bash
54
+ vitest run --grep "login"
55
+ ```
56
+
57
+ The `--grep` flag filters tests by their name (the string passed to `it()` or `test()`). Only tests whose names match the pattern will run. Supports regex patterns for complex matching.
58
+
59
+ ### Run Tests in a Folder
60
+
61
+ ```bash
62
+ vitest run tests/e2e/
63
+ ```
64
+
65
+ Runs all test files within a specific directory. Great for organizing tests by type (unit, integration, e2e) and running them separately.
66
+
67
+ ## Parallel Execution
68
+
69
+ TestDriver runs each test in its own cloud sandbox, enabling true parallel execution. Run your entire test suite in minutes instead of hours.
70
+
71
+ ### Control Concurrency
72
+
73
+ ```bash
74
+ vitest run --maxConcurrency=5
75
+ ```
76
+
77
+ The `--maxConcurrency` flag limits how many tests run simultaneously. This should match your TestDriver license slots to avoid failures from exhausted slots.
78
+
79
+ ### Thread Configuration
80
+
81
+ ```bash
82
+ vitest run --pool=threads --minThreads=2 --maxThreads=8
83
+ ```
84
+
85
+ Fine-tune thread allocation for optimal performance:
86
+ - `--pool=threads` — Uses worker threads for test isolation
87
+ - `--minThreads` — Minimum number of threads to keep alive (reduces startup overhead)
88
+ - `--maxThreads` — Maximum threads to spawn (limits resource usage)
89
+
90
+ ### License Slots
91
+
92
+ Your TestDriver plan includes a set number of **license slots** that determine how many tests can run simultaneously. Each running test occupies one slot—when the test completes and the sandbox is destroyed, the slot is immediately available for the next test.
93
+
94
+ <Info>
95
+ View your available slots at [console.testdriver.ai](https://console.testdriver.ai). Upgrade anytime to increase parallelization.
96
+ </Info>
97
+
98
+ ### Configuring Concurrency
99
+
100
+ Set `maxConcurrency` in your Vitest config to match your license slot limit:
101
+
102
+ ```javascript vitest.config.mjs
103
+ import { defineConfig } from 'vitest/config';
104
+ import TestDriver from 'testdriverai/vitest';
105
+
106
+ export default defineConfig({
107
+ test: {
108
+ testTimeout: 900000,
109
+ hookTimeout: 900000,
110
+ maxConcurrency: 5, // Match your license slot limit
111
+ reporters: ['default', TestDriver()],
112
+ setupFiles: ['testdriverai/vitest/setup'],
113
+ },
114
+ });
115
+ ```
116
+
117
+ <Warning>
118
+ Setting `maxConcurrency` higher than your license slots will cause tests to fail when slots are exhausted. Always match this value to your plan's limit.
119
+ </Warning>
120
+
121
+ ### Why Parallelization Matters
122
+
123
+ | Test Suite | Sequential (1 slot) | Parallel (5 slots) | Parallel (10 slots) |
124
+ |------------|--------------------|--------------------|---------------------|
125
+ | 10 tests @ 2min each | 20 min | 4 min | 2 min |
126
+ | 50 tests @ 2min each | 100 min | 20 min | 10 min |
127
+ | 100 tests @ 2min each | 200 min | 40 min | 20 min |
128
+
129
+ <Tip>
130
+ **Pro tip:** Upgrading your plan doesn't just increase speed—it enables faster CI/CD feedback loops, letting your team ship with confidence.
131
+ </Tip>
132
+
133
+ <Card
134
+ title="View Plans & Pricing"
135
+ icon="credit-card"
136
+ href="/v7/hosted"
137
+ >
138
+ Compare plans and find the right level of parallelization for your team.
139
+ </Card>
140
+
141
+ ## Vitest UI
142
+
143
+ Use Vitest UI for interactive debugging:
144
+
145
+ ```bash
146
+ vitest --ui
147
+ ```
148
+
149
+ The `--ui` flag launches a web-based interface for managing your test suite. Unlike `vitest run`, this starts in watch mode by default.
150
+
151
+ Open http://localhost:51204 to see:
152
+ - **Test file tree** — Browse and navigate your test structure
153
+ - **Test status and duration** — See pass/fail states and timing at a glance
154
+ - **Console output** — View logs and errors inline with each test
155
+ - **Re-run individual tests** — Click to re-execute specific tests without restarting
156
+ - **Filter and search** — Quickly find tests by name or status
157
+
158
+ <Tip>
159
+ Combine with `--open` to automatically open the UI in your browser: `vitest --ui --open`
160
+ </Tip>
161
+
162
+
163
+ ## Test Reports
164
+
165
+ After running tests, view detailed reports and video replays at [console.testdriver.ai](https://console.testdriver.ai).
166
+
167
+ Reports include:
168
+ - **Video replays** - Watch exactly what happened during each test
169
+ - **Screenshots** - See the state at each step
170
+ - **Timing breakdown** - Identify slow operations
171
+ - **Error details** - Debug failures with full context
172
+
173
+ ```bash
174
+ $ vitest run
175
+
176
+ ✓ login.test.js (2) 18.4s
177
+ ✓ user can login 12.3s
178
+ ✓ shows error for invalid credentials 6.1s
179
+
180
+ 📹 View reports at: https://console.testdriver.ai
181
+ ```
182
+
183
+ <Tip>
184
+ Bookmark your team's dashboard at [console.testdriver.ai](https://console.testdriver.ai) for quick access to test history and analytics.
185
+ </Tip>
@@ -0,0 +1,248 @@
1
+ ---
2
+ name: testdriver:screenshot
3
+ description: Capture and save screenshots during test execution
4
+ ---
5
+ <!-- Generated from screenshot.mdx. DO NOT EDIT. -->
6
+
7
+ ## Overview
8
+
9
+ Capture a screenshot of the current screen and automatically save it to a local file. Screenshots are organized by test file for easy debugging and review.
10
+
11
+ <Note>
12
+ **Automatic Screenshots**: TestDriver can automatically capture screenshots before and after every command (click, type, find, etc.). These are saved with descriptive filenames like `001-click-before-L42-submit-button.png` that include the line number from your test file. Enable this with `autoScreenshots: true` in your TestDriver options.
13
+ </Note>
14
+
15
+ ## Syntax
16
+
17
+ ```javascript
18
+ const filePath = await testdriver.screenshot(filename)
19
+ ```
20
+
21
+ ## Parameters
22
+
23
+ <ParamField path="filename" type="string" optional>
24
+ Custom filename for the screenshot (without .png extension). If not provided, a timestamp-based filename is generated automatically.
25
+ </ParamField>
26
+
27
+ ## Returns
28
+
29
+ `Promise<string>` - The absolute file path where the screenshot was saved
30
+
31
+ ## File Organization
32
+
33
+ Screenshots are automatically saved to `.testdriver/screenshots/<test-file-name>/` in your project root:
34
+
35
+ ```
36
+ .testdriver/
37
+ screenshots/
38
+ login.test/
39
+ 001-find-before-L15-email-input.png # Auto: before find()
40
+ 002-find-after-L15-email-input.png # Auto: after find()
41
+ 003-click-before-L16-email-input.png # Auto: before click()
42
+ 004-click-after-L16-email-input.png # Auto: after click()
43
+ 005-type-before-L17-userexamplecom.png # Auto: before type()
44
+ 006-type-after-L17-userexamplecom.png # Auto: after type()
45
+ custom-screenshot.png # Manual: screenshot("custom-screenshot")
46
+ checkout.test/
47
+ 001-find-before-L12-checkout-button.png
48
+ ...
49
+ ```
50
+
51
+ ### Automatic Screenshot Naming
52
+
53
+ When `autoScreenshots` is enabled, filenames follow this format:
54
+
55
+ `<seq>-<action>-<phase>-L<line>-<description>.png`
56
+
57
+ | Component | Description | Example |
58
+ |-----------|-------------|---------|
59
+ | `seq` | Sequential number (001, 002, ...) | `001` |
60
+ | `action` | Command name | `click`, `type`, `find` |
61
+ | `phase` | Before, after, or error | `before`, `after` |
62
+ | `L<line>` | Line number from test file | `L42` |
63
+ | `description` | Element description or action target | `submit-button` |
64
+
65
+ <Note>
66
+ The screenshot folder for each test file is automatically cleared when the test starts. This ensures you only see screenshots from the most recent test run.
67
+ </Note>
68
+
69
+ ## Examples
70
+
71
+ ### Basic Screenshot
72
+
73
+ ```javascript
74
+ // Capture a screenshot with auto-generated filename
75
+ const screenshotPath = await testdriver.screenshot();
76
+ console.log('Screenshot saved to:', screenshotPath);
77
+ ```
78
+
79
+ ### Custom Filename
80
+
81
+ ```javascript
82
+ // Save with a descriptive filename
83
+ await testdriver.screenshot("login-page");
84
+ // Saves to: .testdriver/screenshots/<test>/login-page.png
85
+
86
+ await testdriver.screenshot("after-click");
87
+ // Saves to: .testdriver/screenshots/<test>/after-click.png
88
+ ```
89
+
90
+ ### Debugging with Screenshots
91
+
92
+ ```javascript
93
+ import { describe, expect, it } from "vitest";
94
+ import { TestDriver } from "testdriverai/vitest/hooks";
95
+
96
+ describe("Login Flow", () => {
97
+ it("should log in successfully", async (context) => {
98
+ const testdriver = TestDriver(context);
99
+
100
+ await testdriver.provision.chrome({
101
+ url: 'https://myapp.com/login',
102
+ });
103
+
104
+ // Capture initial state
105
+ await testdriver.screenshot();
106
+
107
+ // Fill in login form
108
+ const emailInput = await testdriver.find("email input");
109
+ await emailInput.click();
110
+ await testdriver.type("user@example.com");
111
+
112
+ // Capture state after typing
113
+ await testdriver.screenshot();
114
+
115
+ const passwordInput = await testdriver.find("password input");
116
+ await passwordInput.click();
117
+ await testdriver.type("password123");
118
+
119
+ // Capture before clicking login
120
+ await testdriver.screenshot();
121
+
122
+ const loginButton = await testdriver.find("Login button");
123
+ await loginButton.click();
124
+
125
+ // Capture after login attempt
126
+ await testdriver.screenshot();
127
+
128
+ const result = await testdriver.assert("dashboard is visible");
129
+ expect(result).toBeTruthy();
130
+ });
131
+ });
132
+ ```
133
+
134
+ ## Automatic Screenshots
135
+
136
+ By default, TestDriver captures screenshots **automatically** before and after every command. This creates a complete visual timeline of your test execution without any additional code.
137
+
138
+ ### Enabling/Disabling
139
+
140
+ ```javascript
141
+ // Auto-screenshots enabled by default
142
+ const testdriver = TestDriver(context);
143
+
144
+ // Explicitly disable if needed (not recommended)
145
+ const testdriver = TestDriver(context, {
146
+ autoScreenshots: false
147
+ });
148
+ ```
149
+
150
+ ### What Gets Captured
151
+
152
+ Automatic screenshots are taken around these commands:
153
+ - `find()` / `findAll()`
154
+ - `click()` / `hover()` / `doubleClick()` / `rightClick()`
155
+ - `type()` / `pressKeys()`
156
+ - `scroll()`
157
+ - `waitForText()` / `waitForImage()`
158
+ - `focusApplication()`
159
+ - `assert()` / `extract()` / `exec()`
160
+
161
+ ### Example Output
162
+
163
+ For this test code:
164
+
165
+ ```javascript
166
+ // Line 15: Find email input
167
+ const emailInput = await testdriver.find("email input");
168
+ // Line 16: Click it
169
+ await emailInput.click();
170
+ // Line 17: Type email
171
+ await testdriver.type("user@example.com");
172
+ ```
173
+
174
+ TestDriver automatically saves:
175
+
176
+ ```
177
+ 001-find-before-L15-email-input.png
178
+ 002-find-after-L15-email-input.png
179
+ 003-click-before-L16-email-input.png
180
+ 004-click-after-L16-email-input.png
181
+ 005-type-before-L17-userexamplecom.png
182
+ 006-type-after-L17-userexamplecom.png
183
+ ```
184
+
185
+ If an error occurs, the phase will be `error` instead of `after`.
186
+
187
+ ## Best Practices
188
+
189
+ <AccordionGroup>
190
+ <Accordion title="Let automatic screenshots do the work">
191
+ With `autoScreenshots: true`, you get comprehensive coverage without adding manual `screenshot()` calls. Only add manual screenshots for specific named checkpoints.
192
+ </Accordion>
193
+
194
+ <Accordion title="Use screenshots for debugging flaky tests">
195
+ When a test fails intermittently, add screenshots at key steps to capture the actual screen state. This helps identify timing issues or unexpected UI states.
196
+ </Accordion>
197
+
198
+ <Accordion title="Capture before assertions">
199
+ Take a screenshot before making assertions. If the assertion fails, you'll have a visual record of what the screen looked like.
200
+
201
+ ```javascript
202
+ await testdriver.screenshot();
203
+ const result = await testdriver.assert("checkout button is visible");
204
+ ```
205
+ </Accordion>
206
+
207
+ <Accordion title="Add to .gitignore">
208
+ Add `.testdriver/screenshots/` to your `.gitignore` to avoid committing screenshots to version control:
209
+
210
+ ```
211
+ # .gitignore
212
+ .testdriver/screenshots/
213
+ ```
214
+ </Accordion>
215
+ </AccordionGroup>
216
+
217
+ ## Viewing Saved Screenshots
218
+
219
+ After saving screenshots during test execution, you can view them using TestDriver MCP commands. This is especially useful for debugging failed tests or verifying test behavior.
220
+
221
+ ### MCP Commands for Screenshot Viewing
222
+
223
+ **List all saved screenshots:**
224
+
225
+ ```
226
+ list_local_screenshots()
227
+ ```
228
+
229
+ **View a specific screenshot:**
230
+
231
+ ```
232
+ view_local_screenshot({ path: "/full/path/to/screenshot.png" })
233
+ ```
234
+
235
+ These commands allow you to:
236
+ - View screenshots from failed tests to understand what went wrong
237
+ - Review test execution flow by examining screenshots in chronological order
238
+ - Compare screenshots across test runs to identify flaky behavior
239
+
240
+ <Note>
241
+ For detailed workflows and examples of using these MCP commands for debugging, see the [Debugging with Screenshots](/v7/debugging-with-screenshots) guide.
242
+ </Note>
243
+
244
+ ## Related
245
+
246
+ - [Debugging with Screenshots](/v7/debugging-with-screenshots) - View and analyze saved screenshots using MCP
247
+ - [assert()](/v7/assert) - Make AI-powered assertions
248
+ - [find()](/v7/find) - Locate elements on screen
@@ -0,0 +1,184 @@
1
+ ---
2
+ name: testdriver:screenshots
3
+ description: Capture and manage screenshots during test execution
4
+ ---
5
+ <!-- Generated from screenshots.mdx. DO NOT EDIT. -->
6
+
7
+ ## Overview
8
+
9
+ TestDriver can capture screenshots manually at any point during a test, or automatically before and after every command. Screenshots are saved to a structured directory for easy debugging.
10
+
11
+ ## Manual Screenshots
12
+
13
+ Use `testdriver.screenshot()` to capture the current screen:
14
+
15
+ ```javascript
16
+ const path = await testdriver.screenshot();
17
+ console.log('Saved to:', path);
18
+ // .testdriver/screenshots/my-test/screenshot-1719849312345.png
19
+ ```
20
+
21
+ ### Options
22
+
23
+ ```javascript
24
+ await testdriver.screenshot(filename?)
25
+ ```
26
+
27
+ <ParamField path="filename" type="string">
28
+ Custom filename for the screenshot. `.png` is appended automatically if missing. If omitted, defaults to `screenshot-<timestamp>.png`.
29
+ </ParamField>
30
+
31
+ **Returns:** `Promise<string>` — the absolute file path of the saved screenshot.
32
+
33
+ ```javascript
34
+ // Default filename
35
+ await testdriver.screenshot();
36
+ // → .testdriver/screenshots/my-test/screenshot-1719849312345.png
37
+
38
+ // Custom filename
39
+ await testdriver.screenshot('login-page');
40
+ // → .testdriver/screenshots/my-test/login-page.png
41
+
42
+ // With .png extension
43
+ await testdriver.screenshot('dashboard-loaded.png');
44
+ // → .testdriver/screenshots/my-test/dashboard-loaded.png
45
+ ```
46
+
47
+ ## Auto Screenshots
48
+
49
+ Enable automatic screenshots before and after every command:
50
+
51
+ ```javascript
52
+ const testdriver = new TestDriver({
53
+ autoScreenshots: true,
54
+ });
55
+ ```
56
+
57
+ <ParamField path="autoScreenshots" type="boolean" default={false}>
58
+ When `true`, captures a screenshot before and after every SDK command (`click`, `type`, `find`, `scroll`, `hover`, `pressKeys`, `assert`, `exec`, etc.). On error, an error-phase screenshot replaces the after-phase screenshot.
59
+ </ParamField>
60
+
61
+ ### Filename Format
62
+
63
+ Auto-screenshots follow this naming convention:
64
+
65
+ ```
66
+ <seq>-<action>-<phase>-L<line>-<description>.png
67
+ ```
68
+
69
+ | Part | Description | Example |
70
+ |---|---|---|
71
+ | `seq` | 3-digit zero-padded sequence number | `001` |
72
+ | `action` | Command name | `click`, `type`, `find` |
73
+ | `phase` | `before`, `after`, or `error` | `before` |
74
+ | `L<line>` | Source line number from your test file | `L42` |
75
+ | `description` | Sanitized from command arguments (max 30 chars) | `submit-button` |
76
+
77
+ **Examples:**
78
+ ```
79
+ 001-find-before-L15-login-button.png
80
+ 002-find-after-L15-login-button.png
81
+ 003-click-before-L16-login-button.png
82
+ 004-click-after-L16-login-button.png
83
+ 005-type-before-L18-username-field.png
84
+ 006-type-error-L18-username-field.png
85
+ ```
86
+
87
+ ### Phases
88
+
89
+ | Phase | When | Description |
90
+ |---|---|---|
91
+ | `before` | Before command executes | Captures the screen state before the action |
92
+ | `after` | After successful command | Captures the result of the action |
93
+ | `error` | After failed command | Captures the screen at the point of failure (replaces `after`) |
94
+
95
+ ## Screenshot Directory
96
+
97
+ Screenshots are saved to:
98
+
99
+ ```
100
+ <cwd>/.testdriver/screenshots/<testFileName>/
101
+ ```
102
+
103
+ Where `<testFileName>` is the test file name without its extension. For example, a test at `tests/login.test.mjs` saves screenshots to `.testdriver/screenshots/login.test/`.
104
+
105
+ ### Directory Cleanup
106
+
107
+ The screenshot directory for each test file is **automatically cleaned** at the start of a test run. This happens once per process per test file to prevent concurrent tests from the same file from interfering with each other.
108
+
109
+ ## Debug Screenshots
110
+
111
+ Elements have a `saveDebugScreenshot()` method for debugging element detection:
112
+
113
+ ```javascript
114
+ const el = await testdriver.find('submit button');
115
+
116
+ // Save the screenshot that was used to detect this element
117
+ const debugPath = await el.saveDebugScreenshot();
118
+ console.log('Debug screenshot:', debugPath);
119
+ // → ./debug-screenshot-1719849312345.png
120
+
121
+ // Custom path
122
+ await el.saveDebugScreenshot('./my-debug.png');
123
+ ```
124
+
125
+ This saves the screenshot that was captured during the `find()` call, which can be useful for understanding what the AI "saw" when locating the element.
126
+
127
+ ## Complete Example
128
+
129
+ ```javascript
130
+ import { describe, it, beforeAll, afterAll } from 'vitest';
131
+ import TestDriver from 'testdriverai';
132
+
133
+ describe('Screenshot Example', () => {
134
+ let testdriver;
135
+
136
+ beforeAll(async () => {
137
+ testdriver = new TestDriver({
138
+ autoScreenshots: true, // capture every step
139
+ });
140
+ await testdriver.ready();
141
+ await testdriver.provision.chrome({ url: 'https://example.com' });
142
+ });
143
+
144
+ afterAll(async () => {
145
+ await testdriver.disconnect();
146
+ });
147
+
148
+ it('captures the login flow', async () => {
149
+ // Auto-screenshots capture before/after each command
150
+
151
+ // Manual screenshot for a specific moment
152
+ await testdriver.screenshot('initial-page-load');
153
+
154
+ const username = await testdriver.find('username input');
155
+ await username.click();
156
+ await testdriver.type('testuser@example.com');
157
+
158
+ await testdriver.screenshot('after-username-entry');
159
+
160
+ const password = await testdriver.find('password input');
161
+ await password.click();
162
+ await testdriver.type('password123');
163
+
164
+ await testdriver.find('login button').click();
165
+
166
+ await testdriver.screenshot('after-login-click');
167
+ });
168
+ });
169
+ ```
170
+
171
+ After running, your screenshot directory will contain:
172
+ ```
173
+ .testdriver/screenshots/login-flow.test/
174
+ ├── initial-page-load.png
175
+ ├── 001-find-before-L18-username-input.png
176
+ ├── 002-find-after-L18-username-input.png
177
+ ├── 003-click-before-L19-username-input.png
178
+ ├── 004-click-after-L19-username-input.png
179
+ ├── 005-type-before-L20-testuser-example-com.png
180
+ ├── 006-type-after-L20-testuser-example-com.png
181
+ ├── after-username-entry.png
182
+ ├── 007-find-before-L24-password-input.png
183
+ ├── ...
184
+ ```