testdriverai 7.3.12 → 7.3.13

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 (133) hide show
  1. package/.github/skills/testdriver:ai/SKILL.md +204 -0
  2. package/.github/skills/testdriver:assert/SKILL.md +284 -0
  3. package/.github/skills/testdriver:aws-setup/SKILL.md +515 -0
  4. package/.github/skills/testdriver:caching/SKILL.md +124 -0
  5. package/.github/skills/testdriver:captcha/SKILL.md +159 -0
  6. package/.github/skills/testdriver:ci-cd/SKILL.md +602 -0
  7. package/.github/skills/testdriver:click/SKILL.md +286 -0
  8. package/.github/skills/testdriver:client/SKILL.md +339 -0
  9. package/.github/skills/testdriver:cloud/SKILL.md +119 -0
  10. package/.github/skills/testdriver:customizing-devices/SKILL.md +153 -0
  11. package/.github/skills/testdriver:dashcam/SKILL.md +418 -0
  12. package/.github/skills/testdriver:debugging-with-screenshots/SKILL.md +271 -0
  13. package/.github/skills/testdriver:device-config/SKILL.md +317 -0
  14. package/.github/skills/testdriver:double-click/SKILL.md +102 -0
  15. package/.github/skills/testdriver:elements/SKILL.md +605 -0
  16. package/.github/skills/testdriver:enterprise/SKILL.md +114 -0
  17. package/.github/skills/testdriver:examples/SKILL.md +7 -0
  18. package/.github/skills/testdriver:exec/SKILL.md +345 -0
  19. package/.github/skills/testdriver:find/SKILL.md +721 -0
  20. package/.github/skills/testdriver:focus-application/SKILL.md +293 -0
  21. package/.github/skills/testdriver:generating-tests/SKILL.md +36 -0
  22. package/.github/skills/testdriver:hover/SKILL.md +278 -0
  23. package/.github/skills/testdriver:locating-elements/SKILL.md +71 -0
  24. package/.github/skills/testdriver:making-assertions/SKILL.md +32 -0
  25. package/.github/skills/testdriver:mcp-workflow/SKILL.md +410 -0
  26. package/.github/skills/testdriver:mouse-down/SKILL.md +161 -0
  27. package/.github/skills/testdriver:mouse-up/SKILL.md +164 -0
  28. package/.github/skills/testdriver:performing-actions/SKILL.md +51 -0
  29. package/.github/skills/testdriver:press-keys/SKILL.md +348 -0
  30. package/.github/skills/testdriver:quickstart/SKILL.md +161 -0
  31. package/.github/skills/testdriver:reusable-code/SKILL.md +240 -0
  32. package/.github/skills/testdriver:right-click/SKILL.md +123 -0
  33. package/.github/skills/testdriver:running-tests/SKILL.md +181 -0
  34. package/.github/skills/testdriver:screenshot/SKILL.md +167 -0
  35. package/.github/skills/testdriver:scroll/SKILL.md +299 -0
  36. package/.github/skills/testdriver:secrets/SKILL.md +115 -0
  37. package/.github/skills/testdriver:self-hosted/SKILL.md +65 -0
  38. package/.github/skills/testdriver:test-writer/SKILL.md +451 -0
  39. package/.github/skills/testdriver:testdriver/SKILL.md +523 -0
  40. package/.github/skills/testdriver:testdriver-mechanic/SKILL.md +165 -0
  41. package/.github/skills/testdriver:type/SKILL.md +357 -0
  42. package/.github/skills/testdriver:variables/SKILL.md +111 -0
  43. package/.github/skills/testdriver:waiting-for-elements/SKILL.md +66 -0
  44. package/.github/skills/testdriver:what-is-testdriver/SKILL.md +54 -0
  45. package/.github/workflows/acceptance-windows-scheduled.yaml +6 -1
  46. package/.github/workflows/acceptance.yaml +0 -36
  47. package/.github/workflows/update-examples.yaml +53 -0
  48. package/CHANGELOG.md +4 -0
  49. package/agent/events.js +1 -0
  50. package/agent/index.js +8 -0
  51. package/agent/lib/commands.js +48 -29
  52. package/agent/lib/redraw.js +3 -1
  53. package/agent/lib/sandbox.js +166 -14
  54. package/agent/lib/sdk.js +142 -3
  55. package/agent/lib/system.js +4 -6
  56. package/ai/skills/testdriver:ai/SKILL.md +204 -0
  57. package/ai/skills/testdriver:assert/SKILL.md +315 -0
  58. package/ai/skills/testdriver:aws-setup/SKILL.md +448 -0
  59. package/ai/skills/testdriver:caching/SKILL.md +124 -0
  60. package/ai/skills/testdriver:captcha/SKILL.md +159 -0
  61. package/ai/skills/testdriver:ci-cd/SKILL.md +602 -0
  62. package/ai/skills/testdriver:click/SKILL.md +286 -0
  63. package/ai/skills/testdriver:client/SKILL.md +372 -0
  64. package/ai/skills/testdriver:cloud/SKILL.md +119 -0
  65. package/ai/skills/testdriver:customizing-devices/SKILL.md +153 -0
  66. package/ai/skills/testdriver:dashcam/SKILL.md +418 -0
  67. package/ai/skills/testdriver:debugging-with-screenshots/SKILL.md +401 -0
  68. package/ai/skills/testdriver:device-config/SKILL.md +317 -0
  69. package/ai/skills/testdriver:double-click/SKILL.md +102 -0
  70. package/ai/skills/testdriver:elements/SKILL.md +605 -0
  71. package/ai/skills/testdriver:enterprise/SKILL.md +114 -0
  72. package/ai/skills/testdriver:examples/SKILL.md +7 -0
  73. package/ai/skills/testdriver:exec/SKILL.md +345 -0
  74. package/ai/skills/testdriver:find/SKILL.md +745 -0
  75. package/ai/skills/testdriver:focus-application/SKILL.md +293 -0
  76. package/ai/skills/testdriver:generating-tests/SKILL.md +36 -0
  77. package/ai/skills/testdriver:hover/SKILL.md +278 -0
  78. package/ai/skills/testdriver:locating-elements/SKILL.md +71 -0
  79. package/ai/skills/testdriver:making-assertions/SKILL.md +32 -0
  80. package/ai/skills/testdriver:mcp-workflow/SKILL.md +410 -0
  81. package/ai/skills/testdriver:mouse-down/SKILL.md +161 -0
  82. package/ai/skills/testdriver:mouse-up/SKILL.md +164 -0
  83. package/ai/skills/testdriver:ocr/SKILL.md +235 -0
  84. package/ai/skills/testdriver:performing-actions/SKILL.md +51 -0
  85. package/ai/skills/testdriver:press-keys/SKILL.md +348 -0
  86. package/ai/skills/testdriver:quickstart/SKILL.md +146 -0
  87. package/ai/skills/testdriver:reusable-code/SKILL.md +240 -0
  88. package/ai/skills/testdriver:right-click/SKILL.md +123 -0
  89. package/ai/skills/testdriver:running-tests/SKILL.md +185 -0
  90. package/ai/skills/testdriver:screenshot/SKILL.md +248 -0
  91. package/ai/skills/testdriver:scroll/SKILL.md +335 -0
  92. package/ai/skills/testdriver:secrets/SKILL.md +115 -0
  93. package/ai/skills/testdriver:self-hosted/SKILL.md +65 -0
  94. package/ai/skills/testdriver:test-writer/SKILL.md +451 -0
  95. package/ai/skills/testdriver:testdriver/SKILL.md +631 -0
  96. package/ai/skills/testdriver:testdriver-mechanic/SKILL.md +165 -0
  97. package/ai/skills/testdriver:type/SKILL.md +357 -0
  98. package/ai/skills/testdriver:variables/SKILL.md +111 -0
  99. package/ai/skills/testdriver:waiting-for-elements/SKILL.md +66 -0
  100. package/ai/skills/testdriver:what-is-testdriver/SKILL.md +54 -0
  101. package/debugger/index.html +12 -2
  102. package/docs/v7/examples/scroll-keyboard.mdx +1 -1
  103. package/docs/v7/find.mdx +1 -0
  104. package/examples/config.mjs +1 -1
  105. package/examples/findall-coffee-icons.test.mjs +42 -0
  106. package/examples/flake-diffthreshold-001.test.mjs +9 -0
  107. package/examples/flake-diffthreshold-01.test.mjs +9 -0
  108. package/examples/flake-diffthreshold-05.test.mjs +9 -0
  109. package/examples/{z_flake-noredraw-cache.test.mjs → flake-noredraw-cache.test.mjs} +2 -2
  110. package/examples/{z_flake-noredraw-nocache.test.mjs → flake-noredraw-nocache.test.mjs} +2 -2
  111. package/examples/{z_flake-redraw-cache.test.mjs → flake-redraw-cache.test.mjs} +2 -2
  112. package/examples/{z_flake-redraw-nocache.test.mjs → flake-redraw-nocache.test.mjs} +2 -2
  113. package/examples/flake-rocket-match.test.mjs +30 -0
  114. package/examples/{z_flake-shared.mjs → flake-shared.mjs} +2 -2
  115. package/examples/parse.test.mjs +19 -0
  116. package/examples/scroll-keyboard.test.mjs +1 -1
  117. package/interfaces/cli/lib/base.js +6 -0
  118. package/interfaces/logger.js +51 -13
  119. package/interfaces/vitest-plugin.mjs +137 -0
  120. package/lib/core/index.d.ts +22 -0
  121. package/lib/init-project.js +105 -6
  122. package/lib/vitest/hooks.mjs +2 -5
  123. package/lib/vitest/setup-disable-defender.mjs +52 -0
  124. package/package.json +2 -1
  125. package/sdk-log-formatter.js +90 -0
  126. package/sdk.d.ts +88 -51
  127. package/sdk.js +126 -18
  128. package/setup/aws/disable-defender.sh +42 -0
  129. package/vitest.config.mjs +1 -3
  130. package/examples/z_flake-diffthreshold-001.test.mjs +0 -9
  131. package/examples/z_flake-diffthreshold-01.test.mjs +0 -9
  132. package/examples/z_flake-diffthreshold-05.test.mjs +0 -9
  133. /package/{examples → manual}/captcha-api.test.mjs +0 -0
@@ -0,0 +1,410 @@
1
+ ---
2
+ name: testdriver:mcp-workflow
3
+ description: Build TestDriver tests iteratively using MCP tools with visual feedback
4
+ ---
5
+
6
+ # TestDriver MCP Workflow
7
+
8
+ Build automated tests by directly controlling a sandbox through MCP tools. Every action returns a screenshot AND the generated code to add to your test file.
9
+
10
+ ## When to Use This Skill
11
+
12
+ Use this skill when:
13
+ - You have access to TestDriver MCP tools (`session_start`, `find`, `click`, etc.)
14
+ - User asks to "write a test", "automate this workflow", "check if X works"
15
+ - You need to build tests iteratively with visual feedback
16
+
17
+ ## Overview
18
+
19
+ Use MCP tools to:
20
+
21
+ 1. **Control the sandbox directly** - Click, type, scroll in real-time
22
+ 2. **See visual feedback** - Every action shows a screenshot with overlays
23
+ 3. **Get generated code** - Each successful action returns the code to add to your test file
24
+ 4. **Build tests incrementally** - Append code to test files as you go
25
+
26
+ ## Quick Start
27
+
28
+ ### 1. Start a Session
29
+
30
+ ```
31
+ session_start({ type: "chrome", url: "https://your-app.com" })
32
+ ```
33
+
34
+ This provisions a sandbox with Chrome and navigates to your URL. You'll see a screenshot and the provision code:
35
+
36
+ ```
37
+ Add to test file:
38
+ await testdriver.provision.chrome({ url: "https://your-app.com" });
39
+ ```
40
+
41
+ **For local development** (pointing to a custom API endpoint):
42
+
43
+ ```
44
+ session_start({
45
+ type: "chrome",
46
+ url: "https://your-app.com",
47
+ apiRoot: "https://your-ngrok-url.ngrok.io"
48
+ })
49
+ ```
50
+
51
+ **For self-hosted AWS instances** (your own Windows EC2):
52
+
53
+ ```
54
+ session_start({
55
+ type: "chrome",
56
+ url: "https://your-app.com",
57
+ os: "windows",
58
+ ip: "1.2.3.4" // IP from your AWS instance
59
+ })
60
+ ```
61
+
62
+ See [AWS Setup Guide](https://docs.testdriver.ai/v7/aws-setup) to deploy your own infrastructure.
63
+
64
+ ### 2. Interact with the App
65
+
66
+ Find elements and interact with them. Each action returns a screenshot AND generated code:
67
+
68
+ ```
69
+ find_and_click({ description: "Sign In button" })
70
+ → Returns: screenshot with element highlighted
71
+ → Add to test file: await testdriver.find("Sign In button").click();
72
+
73
+ type({ text: "user@example.com" })
74
+ → Returns: screenshot showing typed text
75
+ → Add to test file: await testdriver.type("user@example.com");
76
+ ```
77
+
78
+ ### 3. Check If Actions Succeeded
79
+
80
+ After performing actions, use `check` to verify they worked:
81
+
82
+ ```
83
+ check({ task: "Was the text entered into the field?" })
84
+ → Returns: AI analysis of whether the task completed, with screenshot
85
+
86
+ check({ task: "Did the button click navigate to a new page?" })
87
+ → Returns: AI compares previous screenshot to current state
88
+ ```
89
+
90
+ ### 4. Make Assertions (for Test Files)
91
+
92
+ Use `assert` for boolean pass/fail conditions that get recorded in test files:
93
+
94
+ ```
95
+ assert({ assertion: "the login form is visible" })
96
+ → Returns: pass/fail with screenshot
97
+ → Add to test file:
98
+ const assertResult = await testdriver.assert("the login form is visible");
99
+ expect(assertResult).toBeTruthy();
100
+ ```
101
+
102
+ ### 5. Write the Test File
103
+
104
+ As you perform actions, append the generated code to your test file:
105
+
106
+ ```javascript
107
+ /**
108
+ * Login Flow test
109
+ */
110
+ import { describe, expect, it } from "vitest";
111
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
112
+
113
+ describe("Login Flow", () => {
114
+ it("should complete login", async (context) => {
115
+ const testdriver = TestDriver(context);
116
+
117
+ // Append generated code here as you go:
118
+ await testdriver.provision.chrome({ url: "https://app.example.com" });
119
+ await testdriver.find("email input field").click();
120
+ await testdriver.type("user@example.com");
121
+ // ... more code as you perform actions
122
+ });
123
+ });
124
+ ```
125
+
126
+ ### 6. Verify the Test
127
+
128
+ Run the test from scratch to validate it works:
129
+
130
+ ```
131
+ verify({ testFile: "tests/login.test.mjs" })
132
+ ```
133
+
134
+ ## Tools Reference
135
+
136
+ ### Session Management
137
+
138
+ | Tool | Description |
139
+ |------|-------------|
140
+ | `session_start` | Start sandbox with browser/app, returns screenshot + provision code |
141
+ | `session_status` | Check session health and time remaining |
142
+ | `session_extend` | Add more time before session expires |
143
+
144
+ ### Element Interaction
145
+
146
+ Each tool returns a screenshot AND the generated code to add to your test file.
147
+
148
+ | Tool | Description |
149
+ |------|-------------|
150
+ | `find` | Locate element by description, returns ref for later use |
151
+ | `click` | Click on element ref |
152
+ | `find_and_click` | Find and click in one action |
153
+ | `type` | Type text into focused field |
154
+ | `press_keys` | Press keyboard shortcuts (e.g., `["ctrl", "a"]`) |
155
+ | `scroll` | Scroll page (up/down/left/right) |
156
+
157
+ ### Verification & Display
158
+
159
+ | Tool | Description |
160
+ |------|-------------|
161
+ | `check` | **For AI to understand screen state.** Analyzes current screen and tells you (the AI) whether a task/condition is met. Use this after actions to verify they worked. |
162
+ | `assert` | AI-powered boolean assertion for test files (pass/fail for CI). Returns generated code. |
163
+ | `screenshot` | **For showing the user the screen.** Captures and displays a screenshot. Does NOT return analysis to you (the AI). |
164
+ | `exec` | Execute JavaScript, shell, or PowerShell in sandbox. Returns generated code. |
165
+
166
+ ### Test Validation
167
+
168
+ | Tool | Description |
169
+ |------|-------------|
170
+ | `verify` | Run test file from scratch to validate it works |
171
+
172
+ ## Visual Feedback
173
+
174
+ Every tool returns a screenshot showing:
175
+
176
+ - **Element highlights** - Blue box around found elements
177
+ - **Click markers** - Red dot with ripple effect at click location
178
+ - **Scroll indicators** - Arrow showing scroll direction
179
+ - **Action status** - Success/failure with duration
180
+ - **Session info** - Time remaining before expiry
181
+
182
+ ## Workflow Best Practices
183
+
184
+ ### 1. Work Incrementally
185
+
186
+ Don't try to build the entire test at once:
187
+
188
+ ```
189
+ # Step 1: Get to login page
190
+ session_start({ url: "https://app.com" })
191
+ → Add to test: await testdriver.provision.chrome({ url: "https://app.com" });
192
+
193
+ # Step 2: Verify you're on the right page
194
+ check({ task: "Is this the login page?" })
195
+
196
+ # Step 3: Fill in email
197
+ find_and_click({ description: "email input field" })
198
+ → Add to test: await testdriver.find("email input field").click();
199
+
200
+ type({ text: "user@example.com" })
201
+ → Add to test: await testdriver.type("user@example.com");
202
+
203
+ # Step 4: Check if email was entered
204
+ check({ task: "Was the email entered correctly?" })
205
+
206
+ # Step 5: Continue with password...
207
+ ```
208
+
209
+ ### 2. Use Check After Actions
210
+
211
+ After each action, use `check` to verify it worked:
212
+
213
+ ```
214
+ find_and_click({ description: "Submit button" })
215
+ check({ task: "Was the form submitted?" })
216
+ ```
217
+
218
+ The `check` tool compares the previous screenshot (from before your action) with the current state, giving you AI analysis of what changed and whether the action succeeded.
219
+
220
+ ### 3. Understanding Screen State
221
+
222
+ **For AI understanding:** Use `check` to analyze the screen:
223
+ ```
224
+ check({ task: "Did the form submit successfully?" })
225
+ → Returns AI analysis you can read and understand
226
+ ```
227
+
228
+ **For user visibility:** Use `screenshot` to show the user:
229
+ ```
230
+ screenshot()
231
+ → Displays to user, no analysis returned to you
232
+ ```
233
+
234
+ Action tools (`find`, `click`, `find_and_click`) return screenshots automatically, which the user can see. But if you need to understand the state, use `check`.
235
+
236
+ ### 4. Handle Timing Issues
237
+
238
+ If elements take time to appear, use `find` with timeout:
239
+
240
+ ```
241
+ find({ description: "Loading complete indicator", timeout: 30000 })
242
+ ```
243
+
244
+ ### 5. Check Session Time
245
+
246
+ Sessions expire after 5 minutes by default. Use `session_status` to check time remaining and `session_extend` to add more time:
247
+
248
+ ```
249
+ session_status()
250
+ → "Time remaining: 45s"
251
+
252
+ session_extend({ additionalMs: 60000 })
253
+ → "New expiry: 105s"
254
+ ```
255
+
256
+ ### 6. Write Code as You Go
257
+
258
+ After each successful action, append the generated code to your test file. This ensures you don't lose progress and makes the test easier to debug.
259
+
260
+ ## Error Recovery
261
+
262
+ ### Element Not Found
263
+
264
+ If `find` fails:
265
+
266
+ 1. Check the screenshot to see what's actually on screen
267
+ 2. Adjust the element description to be more specific
268
+ 3. Wait for page load with timeout: `find({ description: "...", timeout: 10000 })`
269
+ 4. Scroll to find off-screen elements: `scroll({ direction: "down" })`
270
+
271
+ ### Session Expired
272
+
273
+ If the session expires:
274
+
275
+ 1. `session_start` again with the same URL
276
+ 2. Run the test with `verify` to get back to last state
277
+ 3. Continue from where you left off
278
+
279
+ ### Test Verification Fails
280
+
281
+ If `verify` fails:
282
+
283
+ 1. Check the error message and screenshot
284
+ 2. Review the test file to see the generated code
285
+ 3. Start a new session and manually test the failing step
286
+ 4. Adjust element descriptions or add waits as needed
287
+
288
+ ## Dependencies
289
+
290
+ When creating a new test project, use these exact dependencies:
291
+
292
+ **package.json:**
293
+ ```json
294
+ {
295
+ "type": "module",
296
+ "devDependencies": {
297
+ "testdriverai": "beta",
298
+ "vitest": "^4.0.0"
299
+ },
300
+ "scripts": {
301
+ "test": "vitest"
302
+ }
303
+ }
304
+ ```
305
+
306
+ **Important:** The package is `testdriverai` (NOT `@testdriverai/sdk`). Always install from the `beta` tag.
307
+
308
+ ## Test File Format
309
+
310
+ Create test files using this standard format. Append generated code inside the test function:
311
+
312
+ ```javascript
313
+ /**
314
+ * Login Flow test
315
+ */
316
+ import { describe, expect, it } from "vitest";
317
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
318
+
319
+ describe("Login Flow", () => {
320
+ it("should complete Login Flow", async (context) => {
321
+ const testdriver = TestDriver(context);
322
+
323
+ // Append generated code from each action here:
324
+ await testdriver.provision.chrome({ url: "https://app.example.com" });
325
+
326
+ await testdriver.find("email input field").click();
327
+ await testdriver.type("user@example.com");
328
+
329
+ await testdriver.find("password field").click();
330
+ await testdriver.type("secret123");
331
+
332
+ await testdriver.find("Sign In button").click();
333
+
334
+ const assertResult = await testdriver.assert("dashboard is visible");
335
+ expect(assertResult).toBeTruthy();
336
+ });
337
+ });
338
+ ```
339
+
340
+ ## Self-Hosted AWS Instances
341
+
342
+ You can use your own AWS-hosted Windows instances instead of TestDriver cloud. This gives you:
343
+
344
+ - **Flat license fee** - No device-second metering
345
+ - **Your own AI keys** - Use your OpenAI/Anthropic keys
346
+ - **Custom configuration** - Install custom software, configure networking
347
+ - **Full debugging access** - RDP into instances
348
+
349
+ ### Quick Setup
350
+
351
+ 1. **Deploy AWS infrastructure** using [CloudFormation](https://docs.testdriver.ai/v7/aws-setup)
352
+
353
+ 2. **Spawn an instance**:
354
+ ```bash
355
+ AWS_REGION=us-east-2 \
356
+ AMI_ID=ami-0504bf50fad62f312 \
357
+ AWS_LAUNCH_TEMPLATE_ID=lt-xxx \
358
+ bash setup/aws/spawn-runner.sh
359
+ ```
360
+ Output: `PUBLIC_IP=1.2.3.4`
361
+
362
+ 3. **Connect via session_start**:
363
+ ```
364
+ session_start({
365
+ type: "chrome",
366
+ url: "https://example.com",
367
+ os: "windows",
368
+ ip: "1.2.3.4"
369
+ })
370
+ ```
371
+
372
+ 4. **Terminate when done**:
373
+ ```bash
374
+ aws ec2 terminate-instances --instance-ids i-xxx --region us-east-2
375
+ ```
376
+
377
+ ### Environment Variable
378
+
379
+ You can also set `TD_IP` environment variable in your MCP config instead of passing `ip` to each session:
380
+
381
+ ```json
382
+ {
383
+ "mcpServers": {
384
+ "testdriver": {
385
+ "env": {
386
+ "TD_API_KEY": "your-key",
387
+ "TD_IP": "1.2.3.4"
388
+ }
389
+ }
390
+ }
391
+ }
392
+ ```
393
+
394
+ ## Tips
395
+
396
+ 1. **Every action returns generated code** - Look for "Add to test file:" in responses and append that code
397
+
398
+ 2. **Use `check` to understand the screen** - This is how you (the AI) see and analyze the current state
399
+
400
+ 3. **Use `screenshot` to show the user** - This displays the screen to the user, but does NOT return analysis to you
401
+
402
+ 4. **Use `check` after every action** - Verify your actions succeeded before moving on
403
+
404
+ 5. **Be specific with element descriptions** - "the blue Sign In button in the header" is better than "button"
405
+
406
+ 6. **Use `check` for verification, `assert` for test files** - `check` gives detailed AI analysis, `assert` gives boolean pass/fail for CI
407
+
408
+ 7. **Write code incrementally** - Append generated code to your test file after each successful action
409
+
410
+ 8. **Extend session proactively** - If you have complex workflows, extend before you run out of time
@@ -0,0 +1,161 @@
1
+ ---
2
+ name: testdriver:mouse-down
3
+ description: Press the mouse button without releasing it
4
+ ---
5
+ <!-- Generated from mouse-down.mdx. DO NOT EDIT. -->
6
+
7
+ ## Overview
8
+
9
+ The `mouseDown()` method presses the mouse button at an element's location without releasing it. This is useful for drag operations, custom gestures, or when you need precise control over mouse events. You can either call it on an [`Element`](/v7/core-concepts/elements) instance or use it directly with a selector.
10
+
11
+ ## Syntax
12
+
13
+ ```javascript
14
+ // Mouse down on an element
15
+ await element.mouseDown();
16
+
17
+ // Mouse down using a selector
18
+ await ai.mouseDown('selector');
19
+ ```
20
+
21
+ ## Parameters
22
+
23
+ When called on an `Element`, no parameters are required.
24
+
25
+ When called directly on the AI client:
26
+
27
+ | Parameter | Type | Description |
28
+ |-----------|------|-------------|
29
+ | `selector` | `string` | The selector describing the element where the mouse button should be pressed |
30
+
31
+ ## Returns
32
+
33
+ Returns a `Promise<void>` that resolves when the mouse button is pressed.
34
+
35
+ ## Examples
36
+
37
+ ### Basic Drag Operation
38
+
39
+ ```javascript
40
+ // Start dragging an item
41
+ const dragItem = await ai.find('file to drag');
42
+ await dragItem.mouseDown();
43
+
44
+ // Move to drop target
45
+ const dropTarget = await ai.find('folder to drop into');
46
+ await dropTarget.hover();
47
+
48
+ // Release
49
+ await ai.mouseUp();
50
+ ```
51
+
52
+ ### Drag and Drop with Direct Selectors
53
+
54
+ ```javascript
55
+ await ai.mouseDown('draggable card');
56
+ await ai.hover('drop zone');
57
+ await ai.mouseUp();
58
+ ```
59
+
60
+ ### Selecting Multiple Items
61
+
62
+ ```javascript
63
+ import { test } from 'vitest';
64
+ import { chrome } from '@testdriver/sdk';
65
+
66
+ test('selects multiple items with click and drag', async () => {
67
+ const { ai } = await chrome('https://app.example.com');
68
+
69
+ // Start selection at first item
70
+ await ai.mouseDown('first item in grid');
71
+
72
+ // Drag to last item
73
+ await ai.hover('last item in grid');
74
+
75
+ // Release to complete selection
76
+ await ai.mouseUp();
77
+
78
+ // Verify multiple items selected
79
+ const selectedItems = await ai.find('selected items count');
80
+ expect(selectedItems.text).toContain('5 items selected');
81
+ });
82
+ ```
83
+
84
+ ### Custom Drawing Application
85
+
86
+ ```javascript
87
+ test('draws on canvas', async () => {
88
+ const { ai } = await chrome('https://drawing-app.example.com');
89
+
90
+ // Start drawing
91
+ await ai.mouseDown('canvas at top-left corner');
92
+
93
+ // Draw a line by moving mouse
94
+ await ai.hover('canvas at center');
95
+ await ai.hover('canvas at bottom-right corner');
96
+
97
+ // Stop drawing
98
+ await ai.mouseUp();
99
+
100
+ // Verify something was drawn
101
+ const canvas = await ai.exec('document.querySelector("canvas").toDataURL()');
102
+ expect(canvas).toBeTruthy();
103
+ });
104
+ ```
105
+
106
+ ### Long Press Gesture
107
+
108
+ ```javascript
109
+ test('triggers long press menu', async () => {
110
+ const { ai } = await chrome('https://mobile-app.example.com');
111
+
112
+ // Press and hold
113
+ await ai.mouseDown('message in chat');
114
+
115
+ // Wait for long-press menu
116
+ await new Promise(resolve => setTimeout(resolve, 500));
117
+
118
+ // Verify menu appeared before releasing
119
+ const menu = await ai.find('message options menu');
120
+ expect(menu).toBeTruthy();
121
+
122
+ // Release
123
+ await ai.mouseUp();
124
+ });
125
+ ```
126
+
127
+ ### Resizing UI Elements
128
+
129
+ ```javascript
130
+ test('resizes panel', async () => {
131
+ const { ai } = await vscode();
132
+
133
+ // Grab resize handle
134
+ await ai.mouseDown('sidebar resize handle');
135
+
136
+ // Drag to new position
137
+ await ai.hover('position 300 pixels from left edge');
138
+
139
+ // Release
140
+ await ai.mouseUp();
141
+
142
+ // Verify new size
143
+ const sidebar = await ai.find('sidebar');
144
+ expect(sidebar.width).toBeGreaterThan(250);
145
+ });
146
+ ```
147
+
148
+ ## Important Notes
149
+
150
+ - Always pair `mouseDown()` with [`mouseUp()`](/v7/mouse-up) to complete the gesture
151
+ - The mouse button remains pressed until `mouseUp()` is called
152
+ - Use [`hover()`](/v7/hover) to move the mouse while the button is pressed
153
+ - For simple drag operations, consider using `ai()` with a natural language description like `"drag file to folder"`
154
+
155
+ ## Related Methods
156
+
157
+ - [`mouseUp()`](/v7/mouse-up) - Release the mouse button
158
+ - [`hover()`](/v7/hover) - Move mouse to element
159
+ - [`click()`](/v7/click) - Full click (mouseDown + mouseUp)
160
+ - [`doubleClick()`](/v7/double-click) - Double-click on element
161
+ - [`rightClick()`](/v7/right-click) - Right-click for context menu