@testdriverai/mcp 7.10.0-canary.0 → 7.10.1-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 (196) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/agent/index.js +116 -71
  3. package/agent/interface.js +13 -1
  4. package/agent/lib/commands.js +35 -15
  5. package/agent/lib/provision-commands.js +92 -11
  6. package/agent/lib/sandbox.js +263 -30
  7. package/agent/lib/sdk.js +16 -12
  8. package/agent/lib/system.js +107 -31
  9. package/ai/.claude-plugin/plugin.json +89 -4
  10. package/ai/agents/testdriver.md +4 -8
  11. package/ai/skills/testdriver-assert/SKILL.md +0 -1
  12. package/ai/skills/testdriver-aws-setup/SKILL.md +1 -1
  13. package/ai/skills/testdriver-caching/SKILL.md +13 -6
  14. package/ai/skills/testdriver-ci-cd/SKILL.md +57 -14
  15. package/ai/skills/testdriver-client/SKILL.md +10 -6
  16. package/ai/skills/testdriver-customizing-devices/SKILL.md +7 -5
  17. package/ai/skills/testdriver-dashcam/SKILL.md +36 -3
  18. package/ai/skills/testdriver-debugging-with-screenshots/SKILL.md +28 -4
  19. package/ai/skills/testdriver-device-config/SKILL.md +5 -5
  20. package/ai/skills/testdriver-find/SKILL.md +50 -11
  21. package/ai/skills/testdriver-generating-tests/SKILL.md +163 -8
  22. package/ai/skills/testdriver-hosted/SKILL.md +1 -1
  23. package/ai/skills/testdriver-machine-setup/SKILL.md +331 -0
  24. package/ai/skills/testdriver-making-assertions/SKILL.md +78 -2
  25. package/ai/skills/testdriver-mcp-workflow/SKILL.md +2 -2
  26. package/ai/skills/testdriver-parse/SKILL.md +1 -1
  27. package/ai/skills/testdriver-performing-actions/SKILL.md +97 -3
  28. package/ai/skills/testdriver-provision/SKILL.md +0 -20
  29. package/ai/skills/testdriver-quickstart/SKILL.md +299 -21
  30. package/ai/skills/testdriver-reusable-code/SKILL.md +3 -3
  31. package/ai/skills/testdriver-running-tests/SKILL.md +1 -1
  32. package/ai/skills/testdriver-screenshot/SKILL.md +5 -5
  33. package/ai/skills/testdriver-scroll/SKILL.md +30 -160
  34. package/ai/skills/testdriver-test-writer/SKILL.md +3 -5
  35. package/ai/skills/testdriver-testdriver/SKILL.md +3 -7
  36. package/ai/skills/testdriver-wait/SKILL.md +1 -1
  37. package/{docs/v7/ai.mdx → ai/skills/testdriver:ai/SKILL.md} +3 -4
  38. package/ai/skills/testdriver:assert/SKILL.md +315 -0
  39. package/ai/skills/testdriver:aws-setup/SKILL.md +448 -0
  40. package/ai/skills/testdriver:cache/SKILL.md +221 -0
  41. package/ai/skills/testdriver:caching/SKILL.md +124 -0
  42. package/ai/skills/testdriver:captcha/SKILL.md +158 -0
  43. package/ai/skills/testdriver:ci-cd/SKILL.md +659 -0
  44. package/ai/skills/testdriver:click/SKILL.md +286 -0
  45. package/ai/skills/testdriver:client/SKILL.md +477 -0
  46. package/ai/skills/testdriver:customizing-devices/SKILL.md +319 -0
  47. package/ai/skills/testdriver:dashcam/SKILL.md +451 -0
  48. package/ai/skills/testdriver:debugging-with-screenshots/SKILL.md +415 -0
  49. package/{docs/v7/device-config.mdx → ai/skills/testdriver:device-config/SKILL.md} +8 -8
  50. package/ai/skills/testdriver:double-click/SKILL.md +102 -0
  51. package/ai/skills/testdriver:elements/SKILL.md +605 -0
  52. package/ai/skills/testdriver:enterprise/SKILL.md +7 -0
  53. package/ai/skills/testdriver:errors/SKILL.md +246 -0
  54. package/ai/skills/testdriver:events/SKILL.md +356 -0
  55. package/ai/skills/testdriver:exec/SKILL.md +317 -0
  56. package/ai/skills/testdriver:find/SKILL.md +860 -0
  57. package/ai/skills/testdriver:focus-application/SKILL.md +293 -0
  58. package/ai/skills/testdriver:generating-tests/SKILL.md +25 -0
  59. package/ai/skills/testdriver:hosted/SKILL.md +156 -0
  60. package/ai/skills/testdriver:hover/SKILL.md +278 -0
  61. package/{docs/v7/locating-elements.mdx → ai/skills/testdriver:locating-elements/SKILL.md} +3 -3
  62. package/ai/skills/testdriver:making-assertions/SKILL.md +32 -0
  63. package/ai/skills/testdriver:mcp/SKILL.md +7 -0
  64. package/ai/skills/testdriver:mouse-down/SKILL.md +161 -0
  65. package/ai/skills/testdriver:mouse-up/SKILL.md +164 -0
  66. package/ai/skills/testdriver:parse/SKILL.md +236 -0
  67. package/ai/skills/testdriver:performing-actions/SKILL.md +53 -0
  68. package/ai/skills/testdriver:press-keys/SKILL.md +348 -0
  69. package/ai/skills/testdriver:provision/SKILL.md +331 -0
  70. package/ai/skills/testdriver:quickstart/SKILL.md +172 -0
  71. package/ai/skills/testdriver:redraw/SKILL.md +214 -0
  72. package/ai/skills/testdriver:reusable-code/SKILL.md +249 -0
  73. package/ai/skills/testdriver:right-click/SKILL.md +123 -0
  74. package/{docs/v7/running-tests.mdx → ai/skills/testdriver:running-tests/SKILL.md} +4 -4
  75. package/ai/skills/testdriver:screenshot/SKILL.md +248 -0
  76. package/ai/skills/testdriver:screenshots/SKILL.md +184 -0
  77. package/ai/skills/testdriver:scroll/SKILL.md +205 -0
  78. package/ai/skills/testdriver:secrets/SKILL.md +115 -0
  79. package/ai/skills/testdriver:self-hosted/SKILL.md +147 -0
  80. package/ai/skills/testdriver:test-results-json/SKILL.md +257 -0
  81. package/ai/skills/testdriver:testdriver/SKILL.md +624 -0
  82. package/ai/skills/testdriver:type/SKILL.md +357 -0
  83. package/ai/skills/testdriver:variables/SKILL.md +111 -0
  84. package/ai/skills/testdriver:wait/SKILL.md +50 -0
  85. package/{docs/v7/waiting-for-elements.mdx → ai/skills/testdriver:waiting-for-elements/SKILL.md} +3 -3
  86. package/ai/skills/testdriver:what-is-testdriver/SKILL.md +54 -0
  87. package/debugger/index.html +12 -0
  88. package/docs/_data/examples-manifest.json +54 -46
  89. package/docs/_data/examples-manifest.schema.json +12 -2
  90. package/docs/_scripts/extract-example-urls.js +21 -3
  91. package/docs/_scripts/generate-examples.js +64 -16
  92. package/docs/changelog.mdx +29 -2
  93. package/docs/claude-mcp-plugin.mdx +65 -18
  94. package/docs/docs.json +16 -33
  95. package/docs/snippets/tests/scroll-yaml.mdx +2 -2
  96. package/docs/v6/commands/scroll-until-image.mdx +1 -1
  97. package/docs/v6/commands/scroll-until-text.mdx +2 -2
  98. package/docs/v6/commands/scroll.mdx +2 -2
  99. package/docs/v7/_drafts/agents.mdx +0 -4
  100. package/docs/v7/_drafts/best-practices.mdx +0 -12
  101. package/docs/v7/_drafts/commands/scroll-until-image.mdx +1 -1
  102. package/docs/v7/_drafts/commands/scroll-until-text.mdx +2 -2
  103. package/docs/v7/_drafts/commands/scroll.mdx +1 -1
  104. package/docs/v7/_drafts/configuration.mdx +0 -12
  105. package/docs/v7/_drafts/faq.mdx +2 -10
  106. package/docs/v7/_drafts/readme.mdx +0 -1
  107. package/docs/v7/_drafts/troubleshooting.mdx +1 -4
  108. package/docs/v7/assert.mdx +0 -1
  109. package/docs/v7/aws-setup.mdx +1 -1
  110. package/docs/v7/caching.mdx +14 -10
  111. package/docs/v7/ci-cd.mdx +98 -14
  112. package/docs/v7/client.mdx +10 -6
  113. package/docs/v7/copilot/auto-healing.mdx +167 -18
  114. package/docs/v7/copilot/running-tests.mdx +915 -54
  115. package/docs/v7/customizing-devices.mdx +7 -5
  116. package/docs/v7/dashcam.mdx +36 -3
  117. package/docs/v7/debugging-with-screenshots.mdx +31 -7
  118. package/docs/v7/examples/ai.mdx +13 -8
  119. package/docs/v7/examples/assert.mdx +1 -1
  120. package/docs/v7/examples/chrome-extension.mdx +30 -13
  121. package/docs/v7/examples/element-not-found.mdx +1 -1
  122. package/docs/v7/examples/findall-coffee-icons.mdx +3 -2
  123. package/docs/v7/examples/formatted-logging.mdx +74 -0
  124. package/docs/v7/examples/hover-image.mdx +1 -1
  125. package/docs/v7/examples/hover-text-with-description.mdx +2 -2
  126. package/docs/v7/examples/hover-text.mdx +1 -1
  127. package/docs/v7/examples/installer.mdx +1 -1
  128. package/docs/v7/examples/launch-vscode-linux.mdx +27 -27
  129. package/docs/v7/examples/match-image.mdx +1 -1
  130. package/docs/v7/examples/parse.mdx +3 -2
  131. package/docs/v7/examples/press-keys.mdx +2 -2
  132. package/docs/v7/examples/scroll-keyboard.mdx +2 -2
  133. package/docs/v7/examples/scroll-until-text.mdx +1 -1
  134. package/docs/v7/examples/scroll.mdx +1 -1
  135. package/docs/v7/examples/type.mdx +1 -1
  136. package/docs/v7/find.mdx +50 -11
  137. package/docs/v7/generating-tests.mdx +166 -10
  138. package/docs/v7/hosted.mdx +1 -1
  139. package/docs/v7/making-assertions.mdx +81 -4
  140. package/docs/v7/parse.mdx +1 -1
  141. package/docs/v7/performing-actions.mdx +100 -5
  142. package/docs/v7/provision.mdx +0 -20
  143. package/docs/v7/quickstart.mdx +299 -21
  144. package/docs/v7/reusable-code.mdx +3 -3
  145. package/docs/v7/screenshot.mdx +5 -5
  146. package/docs/v7/scroll.mdx +30 -160
  147. package/docs/v7/wait.mdx +1 -1
  148. package/examples/chrome-extension.test.mjs +29 -12
  149. package/examples/config.mjs +1 -1
  150. package/examples/launch-vscode-linux.test.mjs +25 -25
  151. package/interfaces/cli/commands/init.js +84 -2
  152. package/interfaces/vitest-plugin.mjs +51 -61
  153. package/lib/core/Dashcam.js +43 -2
  154. package/lib/core/index.d.ts +13 -1
  155. package/lib/github-comment.mjs +11 -5
  156. package/lib/init-project.js +98 -44
  157. package/lib/install-clients.js +470 -0
  158. package/lib/provision.js +749 -0
  159. package/lib/resolve-channel.js +2 -2
  160. package/lib/sentry.js +15 -2
  161. package/lib/vitest/hooks.mjs +44 -34
  162. package/mcp-server/README.md +32 -0
  163. package/mcp-server/dist/core/actions.d.ts +176 -0
  164. package/mcp-server/dist/core/actions.js +753 -0
  165. package/mcp-server/dist/env-utils.d.ts +45 -0
  166. package/mcp-server/dist/env-utils.js +63 -0
  167. package/mcp-server/dist/provision-types.d.ts +6 -2
  168. package/mcp-server/dist/provision-types.js +3 -1
  169. package/mcp-server/dist/server.mjs +449 -751
  170. package/mcp-server/package-lock.json +384 -1
  171. package/mcp-server/package.json +5 -2
  172. package/mcp-server/src/core/actions.ts +912 -0
  173. package/mcp-server/src/env-utils.test.ts +82 -0
  174. package/mcp-server/src/env-utils.ts +77 -0
  175. package/mcp-server/src/provision-types.ts +4 -1
  176. package/mcp-server/src/server.ts +533 -954
  177. package/mcp-server/tsconfig.json +1 -1
  178. package/mcp-server/vitest.config.ts +7 -0
  179. package/package.json +15 -3
  180. package/sdk.d.ts +11 -9
  181. package/sdk.js +116 -746
  182. package/setup/aws/spawn-runner.sh +24 -3
  183. package/docs/v7/_drafts/caching-ai.mdx +0 -215
  184. package/docs/v7/_drafts/caching.mdx +0 -366
  185. package/docs/v7/_drafts/prompt-cache.mdx +0 -200
  186. package/docs/v7/copilot/creating-tests.mdx +0 -156
  187. package/docs/v7/copilot/github.mdx +0 -143
  188. package/docs/v7/copilot/setup.mdx +0 -143
  189. package/docs/v7/examples/exec-output.mdx +0 -84
  190. package/docs/v7/examples/exec-pwsh.mdx +0 -82
  191. package/docs/v7/examples/focus-window.mdx +0 -61
  192. package/docs/v7/examples/scroll-until-image.mdx +0 -82
  193. package/docs/v7/examples/windows-installer.mdx +0 -95
  194. package/examples/formatted-logging.test.mjs +0 -27
  195. package/examples/match-image.test.mjs +0 -55
  196. package/manual/exec-stream-logs.test.mjs +0 -25
@@ -49,8 +49,12 @@ const element = await testdriver.find(description, options)
49
49
  - `"any"` — No wrapping, uses the description as-is (default behavior)
50
50
  </ParamField>
51
51
 
52
- <ParamField path="zoom" type="boolean" default={true}>
53
- Two-phase zoom mode for better precision in crowded UIs with many similar elements. Enabled by default.
52
+ <ParamField path="zoom" type="boolean" default={false}>
53
+ Two-phase zoom mode for better precision in crowded UIs with many similar elements. Disabled by default.
54
+ </ParamField>
55
+
56
+ <ParamField path="verify" type="boolean" default={false}>
57
+ Enable AI verification of the located element. When `true`, a second AI call checks that the coordinates returned actually correspond to the requested element, catching hallucinated or incorrect positions. Disabled by default for lower latency.
54
58
  </ParamField>
55
59
 
56
60
  <ParamField path="ai" type="object">
@@ -334,17 +338,17 @@ The `timeout` option:
334
338
 
335
339
  ## Zoom Mode
336
340
 
337
- Zoom mode is **enabled by default**. It uses a two-phase approach for better precision when locating elements, especially in crowded UIs with many similar elements.
341
+ Zoom mode is **disabled by default**. It uses a two-phase approach for better precision when locating elements, especially in crowded UIs with many similar elements.
338
342
 
339
- To disable zoom for a specific find call, pass `zoom: false`:
343
+ To enable zoom for a specific find call, pass `zoom: true`:
340
344
 
341
345
  ```javascript
342
- // Zoom is on by default no option needed
343
- const extensionsBtn = await testdriver.find('extensions puzzle icon in Chrome toolbar');
346
+ // Enable zoom for better precision in crowded UIs
347
+ const extensionsBtn = await testdriver.find('extensions puzzle icon in Chrome toolbar', { zoom: true });
344
348
  await extensionsBtn.click();
345
349
 
346
- // Disable zoom for a specific call if needed
347
- const largeButton = await testdriver.find('big hero button', { zoom: false });
350
+ // Without zoom (default)
351
+ const largeButton = await testdriver.find('big hero button');
348
352
  ```
349
353
 
350
354
  ### How Zoom Mode Works
@@ -357,13 +361,48 @@ const largeButton = await testdriver.find('big hero button', { zoom: false });
357
361
  This two-phase approach gives the AI a higher-resolution view of the target area, improving accuracy when multiple similar elements are close together.
358
362
 
359
363
  <Tip>
360
- You may want to disable zoom with `zoom: false` when:
361
- - Targeting large, isolated elements where the extra precision isn't needed
362
- - You want to speed up find calls in simple UIs
364
+ You may want to enable zoom with `zoom: true` when:
365
+ - Targeting small elements in crowded UIs with many similar elements
366
+ - You need extra precision for closely spaced UI elements
363
367
  </Tip>
364
368
 
369
+ ## Verify Mode
370
+
371
+ Verify mode is **disabled by default**. When enabled, a second AI call checks that the coordinates returned by `find()` actually correspond to the requested element, catching hallucinated or incorrect positions.
372
+
373
+ ```javascript
374
+ // Enable verification for critical interactions
375
+ const deleteBtn = await testdriver.find('delete account button', { verify: true });
376
+ await deleteBtn.click();
377
+ ```
378
+
379
+ ### How Verify Mode Works
380
+
381
+ 1. **Phase 1**: AI locates the element and returns coordinates
382
+ 2. **Phase 2**: A second AI call examines the screenshot at those coordinates to confirm the element matches the description
383
+ 3. **Result**: If verification fails, the find is retried or marked as not found
384
+
385
+ ### Combining Zoom and Verify
386
+
387
+ For maximum accuracy, enable both `zoom` and `verify` together. This is useful for critical interactions where clicking the wrong element could cause cascading failures:
388
+
389
+ ```javascript
390
+ // Maximum accuracy: zoom for precision + verify to catch hallucinations
391
+ const element = await testdriver.find('small cancel icon next to the subscription', {
392
+ zoom: true,
393
+ verify: true,
394
+ });
395
+ await element.click();
396
+ ```
397
+
398
+ <Warning>
399
+ Both `zoom` and `verify` add extra AI calls per `find()` invocation, which increases latency and API usage. When both are enabled, each find may make up to 3 AI calls. **Rate limiting may occur** if many find calls use these options in rapid succession. Use them selectively for critical interactions rather than on every find call.
400
+ </Warning>
401
+
365
402
  ## Cache Options
366
403
 
404
+ When a test completes successfully, the result of each `find()` is cached. On later runs, TestDriver reuses the cached match instead of making a fresh AI call, which significantly speeds up locating the same element. The cache lives in your [dashboard](https://console.testdriver.ai/cache) and is shared across runs — see the [Cache](/v7/cache) page for how matching, thresholds, and invalidation work.
405
+
367
406
  Control caching behavior to optimize performance, especially when using dynamic variables in prompts.
368
407
 
369
408
  ### Custom Cache Key
@@ -1,12 +1,20 @@
1
1
  ---
2
2
  name: testdriver:generating-tests
3
- description: Use AI coding agents and exploration mode to generate TestDriver tests
3
+ description: Generate tests by exploring your app with the AI vision agent
4
4
  ---
5
5
  <!-- Generated from generating-tests.mdx. DO NOT EDIT. -->
6
6
 
7
+ Start by exploring your app. This is where tests begin: you describe a flow in plain English, and the TestDriver vision agent clicks, types, and reads the screen to figure it out — then writes the test for you. No selectors, no DOM, no brittle locators. Just describe what you want to test and let the agent discover the rest.
8
+
9
+ There are two ways to explore: chatting interactively with your AI assistant through the TestDriver MCP server, or handing a coding agent our instructions file and prompting it to generate a test.
10
+
11
+ <Info>
12
+ Both paths need an MCP-capable AI coding assistant. If you don't have one yet, start with **GitHub Copilot** — there's a [free tier](https://github.com/features/copilot/plans), no credit card required. See [Run → Setup](/v7/copilot/running-tests#setup) for the full install and sign-in walkthrough.
13
+ </Info>
14
+
7
15
  ## Instructions for Coding Agents
8
16
 
9
- We recommend starting with [our quickstart](./quickstart) then supplying your coding agent with our agent instructions file.
17
+ We recommend starting with [our quickstart](./quickstart), then supplying your coding agent with our agent instructions file.
10
18
 
11
19
  <Card title="TestDriver Agent Instructions" icon="link" arrow="true" horizontal href="https://github.com/testdriverai/testdriverai/blob/main/ai/agents/testdriver.md?plain=1">
12
20
  Copy the current version of our agent instructions to provide your coding agent with up-to-date instructions on how to generate TestDriver tests.
@@ -24,13 +32,160 @@ Push Submit button
24
32
  Verify new page contains expected text 'logged in'
25
33
  ```
26
34
 
27
- ## AI Exploration Mode
35
+ <Info>Explicit commands are preferred for production tests, as they are cheaper, faster, and more reliable.</Info>
36
+
37
+ ## Start a Conversation
38
+
39
+ With TestDriver's MCP server and your AI assistant (GitHub Copilot, Cursor, or Claude Desktop), you can create tests by chatting with an AI agent. The agent spawns a virtual machine, executes actions, and writes test code for you.
40
+
41
+ Open your AI assistant's chat. If your project has no other agents configured, the TestDriver agent is used by default. Otherwise, select **testdriver** from the agent dropdown in the chat panel.
28
42
 
29
- Within a test, the `ai()` method lets TestDriver autonomously figure out how to accomplish a task. It's useful for dynamic or unpredictable UIs where explicit actions may be difficult to define.
43
+ Describe what you want to test:
30
44
 
31
- ```javascript
32
- // Handle dynamic or unpredictable UI
33
- await testdriver.ai('dismiss any popups or modals that appear');
45
+ ```
46
+ Create a test that logs into my app at https://myapp.com
34
47
  ```
35
48
 
36
- <Info>Explicit commands are preferred for production tests, as they are cheaper, faster, and more reliable.</Info>
49
+ The agent will:
50
+ 1. Start a new session and spawn a Linux virtual machine
51
+ 2. Launch Chrome and navigate to your URL
52
+ 3. Execute actions based on your instructions
53
+ 4. Write the test code to a `.test.mjs` file
54
+
55
+ <Note>
56
+ The TestDriver agent appears in the agent selection dropdown if you have other agents configured (like `copilot-instructions.md` or other `.agent.md` files). Make sure to select **testdriver** to use TestDriver's MCP tools.
57
+ </Note>
58
+
59
+ ## Live Preview Panel
60
+
61
+ When the agent starts a session, a **live preview panel** opens in your editor. This lets you:
62
+
63
+ - **Watch tests execute** in real-time
64
+ - **Interact with the VM** — click, type, and navigate manually
65
+ - **Debug issues** — see exactly what the AI sees
66
+
67
+ <Note>
68
+ The live preview panel requires the TestDriver VS Code extension. Set `TD_PREVIEW=ide` in your MCP configuration to enable it. See the [Run page](/v7/copilot/running-tests) for all device and preview options.
69
+ </Note>
70
+
71
+ ## Interactive Workflow
72
+
73
+ The recommended workflow for exploring and creating tests:
74
+
75
+ <Steps>
76
+ <Step title="Describe Your Test">
77
+ Tell the agent what you want to test:
78
+
79
+ ```
80
+ Test the checkout flow on https://shop.example.com
81
+ ```
82
+ </Step>
83
+
84
+ <Step title="Watch and Guide">
85
+ The agent will start executing. Watch the preview panel and provide guidance if needed:
86
+
87
+ ```
88
+ The login modal appeared. Use test@example.com and password123
89
+ ```
90
+ </Step>
91
+
92
+ <Step title="Add Assertions">
93
+ Ask the agent to verify specific conditions:
94
+
95
+ ```
96
+ Assert that the order confirmation page is shown with the order number
97
+ ```
98
+ </Step>
99
+
100
+ <Step title="Review the Code">
101
+ The agent writes test code as it works. Review the generated `.test.mjs` file and make any adjustments.
102
+ </Step>
103
+ </Steps>
104
+
105
+ ## Example Conversation
106
+
107
+ Here's a complete example of exploring and creating a login test:
108
+
109
+ ```
110
+ You: Create a test for the login flow at https://console.testdriver.ai
111
+
112
+ Agent: I'll create a test for the login flow. Starting a session...
113
+ [Screenshot: Login page loaded]
114
+
115
+ I can see the login page. Let me find the email input.
116
+ [Screenshot: Email input highlighted]
117
+
118
+ Now I'll type the email and find the password field...
119
+
120
+ You: Use test@example.com for the email
121
+
122
+ Agent: Got it. Typing test@example.com...
123
+ [Screenshot: Email entered]
124
+
125
+ Now entering the password and clicking Sign In...
126
+ [Screenshot: Dashboard loaded]
127
+
128
+ ✅ Login successful! I've written the test to tests/login.test.mjs
129
+ ```
130
+
131
+ ## Generated Test Code
132
+
133
+ The agent generates standard Vitest test files:
134
+
135
+ ```javascript tests/login.test.mjs
136
+ import { describe, expect, it } from "vitest";
137
+ import { TestDriver } from "testdriverai/vitest/hooks";
138
+
139
+ describe("Login Flow", () => {
140
+ it("should log in successfully", async (context) => {
141
+ const testdriver = TestDriver(context);
142
+
143
+ await testdriver.provision.chrome({
144
+ url: "https://console.testdriver.ai"
145
+ });
146
+
147
+ const emailInput = await testdriver.find("email input field");
148
+ await emailInput.click();
149
+ await testdriver.type("test@example.com");
150
+
151
+ const passwordInput = await testdriver.find("password input field");
152
+ await passwordInput.click();
153
+ await testdriver.type("password123");
154
+
155
+ const signInButton = await testdriver.find("Sign In button");
156
+ await signInButton.click();
157
+
158
+ const result = await testdriver.assert("dashboard is visible");
159
+ expect(result).toBeTruthy();
160
+ });
161
+ });
162
+ ```
163
+
164
+ ## Tips for Better Tests
165
+
166
+ <AccordionGroup>
167
+ <Accordion title="Be specific with element descriptions">
168
+ Instead of "click the button", say "click the blue Sign In button in the header". More context helps the AI find the right element.
169
+ </Accordion>
170
+ <Accordion title="Add waits for dynamic content">
171
+ If your app has animations or loading states, tell the agent to wait:
172
+ ```
173
+ Wait for the loading spinner to disappear before continuing
174
+ ```
175
+ </Accordion>
176
+ <Accordion title="Use assertions liberally">
177
+ Add assertions after each major action to catch regressions early:
178
+ ```
179
+ Assert that the product was added to the cart
180
+ ```
181
+ </Accordion>
182
+ <Accordion title="Break complex flows into steps">
183
+ For long workflows, create the test incrementally and verify each step works before moving on.
184
+ </Accordion>
185
+ </AccordionGroup>
186
+
187
+ ## Next
188
+
189
+ <Card title="Learn" icon="brain" arrow="true" horizontal href="/v7/caching">
190
+ Once the agent has explored your app, TestDriver caches what it discovers so your tests replay instantly without re-reasoning over the screen every time.
191
+ </Card>
@@ -75,7 +75,7 @@ To prevent tests from failing due to exceeding your license slot limit, we recom
75
75
 
76
76
  ```javascript vitest.config.mjs
77
77
  import { defineConfig } from 'vitest/config';
78
- import { TestDriver } from 'testdriverai/vitest';
78
+ import TestDriver from 'testdriverai/vitest';
79
79
 
80
80
  export default defineConfig({
81
81
  test: {
@@ -0,0 +1,331 @@
1
+ ---
2
+ name: testdriver:machine-setup
3
+ description: Configure Linux and Windows sandboxes, persist machines between runs, and install custom software
4
+ ---
5
+ <!-- Generated from machine-setup.mdx. DO NOT EDIT. -->
6
+
7
+ TestDriver provisions a fresh cloud VM for every test by default. This guide covers how to configure Linux and Windows machines, reduce startup time by keeping machines alive between runs, use provision scripts for repeatable setup, and install custom software on the fly.
8
+
9
+ ---
10
+
11
+ ## Linux Machines
12
+
13
+ Linux is the default operating system. No extra configuration is required.
14
+
15
+ ```javascript
16
+ import { describe, expect, it } from "vitest";
17
+ import { TestDriver } from "testdriverai/vitest/hooks";
18
+
19
+ describe("My Test", () => {
20
+ it("runs on Linux", async (context) => {
21
+ const testdriver = TestDriver(context);
22
+
23
+ await testdriver.provision.chrome({ url: "https://example.com" });
24
+
25
+ const result = await testdriver.assert("the page loaded successfully");
26
+ expect(result).toBeTruthy();
27
+ });
28
+ });
29
+ ```
30
+
31
+ ### Common Linux Options
32
+
33
+ | Option | Type | Default | Description |
34
+ |--------|------|---------|-------------|
35
+ | `os` | string | `"linux"` | Operating system |
36
+ | `resolution` | string | `"1366x768"` | Screen resolution (Enterprise only) |
37
+ | `e2bTemplateId` | string | — | Custom E2B template ID (see [Self-Hosted](/v7/self-hosted)) |
38
+ | `keepAlive` | number | `60000` | Ms to keep VM alive after disconnect |
39
+ | `reconnect` | boolean | `false` | Reconnect to last used sandbox |
40
+
41
+ ```javascript
42
+ const testdriver = TestDriver(context, {
43
+ os: "linux",
44
+ resolution: "1920x1080",
45
+ keepAlive: 5 * 60 * 1000, // keep alive 5 minutes
46
+ });
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Windows Machines
52
+
53
+ Set `os: "windows"` to provision a Windows VM instead. Everything else works the same way.
54
+
55
+ ```javascript
56
+ const testdriver = TestDriver(context, {
57
+ os: "windows",
58
+ });
59
+
60
+ await testdriver.provision.chrome({ url: "https://example.com" });
61
+ ```
62
+
63
+ Windows sandboxes use EC2 instances and take longer to boot than Linux (E2B) sandboxes — typically 1–3 minutes for a cold start. See [Keeping Machines Alive](#keeping-machines-alive-between-runs) below to avoid this cost on repeated runs.
64
+
65
+ ### Common Windows Options
66
+
67
+ | Option | Type | Default | Description |
68
+ |--------|------|---------|-------------|
69
+ | `os` | string | — | Set to `"windows"` |
70
+ | `resolution` | string | `"1366x768"` | Screen resolution (Enterprise only) |
71
+ | `sandboxAmi` | string | — | Custom AMI ID (self-hosted) |
72
+ | `sandboxInstance` | string | — | EC2 instance type (self-hosted) |
73
+ | `keepAlive` | number | `60000` | Ms to keep VM alive after disconnect |
74
+ | `reconnect` | boolean | `false` | Reconnect to last used sandbox |
75
+
76
+ ```javascript
77
+ const testdriver = TestDriver(context, {
78
+ os: "windows",
79
+ resolution: "1920x1080",
80
+ keepAlive: 10 * 60 * 1000, // keep alive 10 minutes
81
+ });
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Keeping Machines Alive Between Runs
87
+
88
+ Windows (and Linux) cold starts can be expensive if you're iterating quickly. Use `keepAlive` + `reconnect` to reuse the same VM across multiple test runs.
89
+
90
+ ### How it works
91
+
92
+ Every time the SDK successfully connects to a sandbox, it records the sandbox id in `.testdriver/last-sandbox` inside your project directory. The next test that opts in with `reconnect: true` reads that file and reattaches automatically — no manual id tracking required.
93
+
94
+ Provision calls (`testdriver.provision.chrome(...)`, `vscode(...)`, etc.) are **skipped** when reconnecting, because the application is already running inside the sandbox from the previous run.
95
+
96
+ <Note>
97
+ `.testdriver/last-sandbox` is already covered by the default TestDriver `.gitignore`. Don't commit it.
98
+ </Note>
99
+
100
+ ### Step 1 — Start the machine with a long `keepAlive`
101
+
102
+ ```javascript
103
+ // first.test.mjs
104
+ const testdriver = TestDriver(context, {
105
+ os: "windows",
106
+ keepAlive: 30 * 60 * 1000, // keep alive 30 minutes after this test ends
107
+ });
108
+
109
+ await testdriver.provision.chrome({ url: "https://example.com" });
110
+ // ... your test steps
111
+ ```
112
+
113
+ When this test finishes, the sandbox stays running for 30 minutes instead of being terminated immediately.
114
+
115
+ ### Step 2 — Reattach automatically with `reconnect: true`
116
+
117
+ ```javascript
118
+ // second.test.mjs
119
+ const testdriver = TestDriver(context, {
120
+ os: "windows",
121
+ reconnect: true, // ← reads .testdriver/last-sandbox
122
+ keepAlive: 30 * 60 * 1000,
123
+ });
124
+
125
+ // No provision call — Chrome is already open from the previous run.
126
+ await testdriver.find("Sign In button").click();
127
+ ```
128
+
129
+ ### Step 2 (alternative) — Reattach to an explicit id
130
+
131
+ If you need to pin to a specific sandbox (CI matrix, multiple chains in parallel, etc.) pass the id directly:
132
+
133
+ ```javascript
134
+ await testdriver.connect({ sandboxId: "sandbox-abc123" });
135
+ ```
136
+
137
+ When reattaching to a sandbox:
138
+ - You reuse a specific running machine directly
139
+ - You continue from the app state created in the earlier run
140
+ - You must run within the previous test's `keepAlive` window
141
+
142
+ <Tip>
143
+ Use `testdriver.getLastSandboxId()` to read the recorded sandbox id (and optional metadata) for scripting purposes.
144
+ </Tip>
145
+
146
+ ### Chaining describe blocks within one test file
147
+
148
+ A common pattern is to break a long flow into focused `describe` blocks that share one sandbox — the first block provisions and signs in, later blocks reconnect and continue:
149
+
150
+ ```javascript
151
+ import { describe, expect, it } from "vitest";
152
+ import { TestDriver } from "testdriverai/vitest/hooks";
153
+
154
+ const KEEP_ALIVE_MS = 5 * 60 * 1000;
155
+
156
+ describe("step 1 — log in", () => {
157
+ it("signs in and lands on the dashboard", async (context) => {
158
+ const testdriver = TestDriver(context, { keepAlive: KEEP_ALIVE_MS });
159
+ await testdriver.provision.chrome({ url: "https://example.com/login" });
160
+ await testdriver.find("username input").click();
161
+ await testdriver.type("standard_user");
162
+ await testdriver.pressKeys(["tab"]);
163
+ await testdriver.type("secret_sauce", { secret: true });
164
+ await testdriver.pressKeys(["enter"]);
165
+ expect(await testdriver.assert("the dashboard is visible")).toBeTruthy();
166
+ });
167
+ });
168
+
169
+ describe("step 2 — add to cart", () => {
170
+ it("reuses the logged-in sandbox", async (context) => {
171
+ const testdriver = TestDriver(context, {
172
+ reconnect: true, // ← skip provisioning, reattach
173
+ keepAlive: KEEP_ALIVE_MS,
174
+ });
175
+ await testdriver.find("Add to cart").click();
176
+ await testdriver.find("cart icon").click();
177
+ expect(await testdriver.assert("the cart has an item")).toBeTruthy();
178
+ });
179
+ });
180
+
181
+ describe("step 3 — check out", () => {
182
+ it("continues from the cart state", async (context) => {
183
+ const testdriver = TestDriver(context, { reconnect: true, keepAlive: 30_000 });
184
+ await testdriver.find("Checkout").click();
185
+ expect(await testdriver.assert("the checkout form is visible")).toBeTruthy();
186
+ });
187
+ });
188
+ ```
189
+
190
+ A runnable copy of this pattern lives at [`examples/reconnect-sequential.test.mjs`](https://github.com/testdriverai/mono/blob/main/sdk/examples/reconnect-sequential.test.mjs).
191
+
192
+ <Warning>
193
+ Vitest runs **test files** in parallel by default. Within a single file, `describe`/`it` blocks run in source order, so reconnect chaining works as written. To chain across multiple files, run them sequentially (e.g. `vitest run --sequence.concurrent=false` or place them in a single project pool with workers set to 1).
194
+ </Warning>
195
+
196
+ ### How `keepAlive` works
197
+
198
+ `keepAlive` is a duration in milliseconds. After the SDK disconnects, the server keeps the VM running for that long before terminating it. The default is `60000` (1 minute). Note: `keepAlive: 0` currently falls back to the default disconnect grace period rather than terminating immediately, so use a positive duration when you want to control the grace window explicitly.
199
+
200
+ ```javascript
201
+ const testdriver = TestDriver(context, {
202
+ keepAlive: 0, // currently uses the default 1 minute grace period
203
+ // keepAlive: 60000, // default — 1 minute
204
+ // keepAlive: 600000, // 10 minutes
205
+ // keepAlive: 3600000, // 1 hour
206
+ });
207
+ ```
208
+
209
+ <Warning>
210
+ Machines kept alive beyond your test session continue to consume credits. Always set a `keepAlive` value appropriate for your workflow.
211
+ </Warning>
212
+
213
+ ---
214
+
215
+ ## Using Provision Scripts
216
+
217
+ Provision scripts let you run arbitrary setup steps before your test starts — downloading fixtures, seeding a database, configuring environment variables, and more. Use `testdriver.exec()` to run shell or PowerShell commands directly in the sandbox.
218
+
219
+ <Card
220
+ title="exec() Reference"
221
+ icon="terminal"
222
+ href="/v7/exec"
223
+ >
224
+ Full reference for running shell and PowerShell commands in the sandbox.
225
+ </Card>
226
+
227
+ ### Linux setup script
228
+
229
+ ```javascript
230
+ await testdriver.provision.chrome({ url: "https://myapp.com" });
231
+
232
+ // Run a setup script from your repo
233
+ await testdriver.exec("sh", `
234
+ curl -s https://myapp.com/api/reset-test-db -X POST
235
+ echo "Test DB reset"
236
+ `, 30000);
237
+ ```
238
+
239
+ ### Windows setup script (PowerShell)
240
+
241
+ ```javascript
242
+ await testdriver.provision.chrome({ url: "https://myapp.com" });
243
+
244
+ await testdriver.exec("pwsh", `
245
+ $env:API_URL = "https://staging.myapp.com"
246
+ Write-Host "Environment configured"
247
+ `, 15000);
248
+ ```
249
+
250
+ ### Clone a repo and run a script
251
+
252
+ ```javascript
253
+ await testdriver.exec("sh", `
254
+ git clone https://github.com/myorg/test-fixtures.git /tmp/fixtures
255
+ bash /tmp/fixtures/seed.sh
256
+ `, 120000);
257
+ ```
258
+
259
+ ---
260
+
261
+ ## Installing Custom Software
262
+
263
+ You can install software at the start of a test using `exec()`. This works for any package available via `apt`, `brew`, `choco`, `winget`, npm, pip, or direct download.
264
+
265
+ ### Linux — apt packages
266
+
267
+ ```javascript
268
+ await testdriver.exec("sh", `
269
+ sudo apt-get update -qq
270
+ sudo apt-get install -y ffmpeg imagemagick
271
+ `, 120000);
272
+ ```
273
+
274
+ ### Linux — Node.js tools
275
+
276
+ ```javascript
277
+ await testdriver.exec("sh", "npm install -g @playwright/test", 60000);
278
+ ```
279
+
280
+ ### Windows — winget
281
+
282
+ ```javascript
283
+ await testdriver.exec("pwsh", `
284
+ winget install --id=7zip.7zip -e --silent
285
+ `, 120000);
286
+ ```
287
+
288
+ ### Windows — Chocolatey
289
+
290
+ ```javascript
291
+ await testdriver.exec("pwsh", `
292
+ choco install googlechrome --yes --no-progress
293
+ `, 180000);
294
+ ```
295
+
296
+ ### Download and run an installer
297
+
298
+ ```javascript
299
+ // Linux
300
+ await testdriver.exec("sh", `
301
+ curl -L https://example.com/installer.sh -o /tmp/installer.sh
302
+ chmod +x /tmp/installer.sh
303
+ /tmp/installer.sh --silent
304
+ `, 300000);
305
+
306
+ // Windows
307
+ await testdriver.exec("pwsh", `
308
+ Invoke-WebRequest -Uri "https://example.com/installer.exe" -OutFile "$env:TEMP\\installer.exe"
309
+ Start-Process "$env:TEMP\\installer.exe" -ArgumentList "/S" -Wait
310
+ `, 300000);
311
+ ```
312
+
313
+ <Note>
314
+ Installing software at test start adds to your test duration. For software you use in every test, consider preloading it into a custom VM image via the Enterprise self-hosted plan.
315
+ </Note>
316
+
317
+ ---
318
+
319
+ ## Want Software Pre-Installed on Every Machine?
320
+
321
+ Installing packages at runtime works well for occasional or lightweight dependencies. But if you're installing the same 5-minute setup on every test run, you're wasting time and credits.
322
+
323
+ With the **Self-Hosted Enterprise plan** you get access to our golden VM base image and Packer scripts, so you can bake your applications, dependencies, and configuration directly into a custom AMI. Tests spin up with everything already installed — zero setup time.
324
+
325
+ <Card
326
+ title="Self-Hosted Enterprise"
327
+ icon="server"
328
+ href="/v7/self-hosted"
329
+ >
330
+ Preload software, configure custom hardware, and run unlimited tests with a flat license fee. Our team assists with deployment and setup.
331
+ </Card>