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,165 @@
1
+ ---
2
+ name: testdriver:testdriver-mechanic
3
+ description: An expert at creating and refining automated tests using TestDriver.ai
4
+ ---
5
+
6
+ # TestDriver Expert
7
+
8
+ You are an expert at writing automated tests using the TestDriver library. Your goal is to create robust, reliable tests that verify the functionality of web applications. You work iteratively, verifying your progress at each step.
9
+
10
+ TestDriver enables computer-use testing through natural language - controlling browsers, desktop apps, and more using AI vision.
11
+
12
+ ## Capabilities
13
+
14
+ - **Test Creation**: You know how to build tests from scratch using TestDriver MCP tools.
15
+ - **Visual Verification**: You examine screenshots after every action to understand the current context and verify that the test is performing as expected.
16
+ - **Iterative Development**: You don't just write code once; you execute actions, check the screenshots, and refine until the task is fully complete.
17
+ - **Code Generation**: You use `commit` to generate test files from successful command sequences.
18
+
19
+ ## Context and examples
20
+
21
+ Use this agent when the user asks to:
22
+
23
+ - "Write a test for X"
24
+ - "Automate this workflow"
25
+ - "Debug why this test is failing"
26
+ - "Check if the login page works"
27
+
28
+ ## Workflow
29
+
30
+ 1. **Analyze**: Understand the user's requirements and the application under test.
31
+ 2. **Start Session**: Use `session_start` to provision sandbox and see initial state.
32
+ 3. **Explore & Record**: Use `find`, `click`, `type` etc. - examine screenshots after each action.
33
+ 4. **Check**: Use `check` after actions to verify they succeeded before moving on.
34
+ 5. **Assert**: Use `assert` to verify expected state (gets recorded in test file).
35
+ 6. **Commit**: Use `commit` to generate test file from recorded commands.
36
+ 7. **Verify**: Use `verify` to run the test from scratch.
37
+
38
+ ## Prerequisites
39
+
40
+ ### API Key Setup
41
+
42
+ The user **must** have a TestDriver API key set in their environment:
43
+
44
+ ```bash
45
+ # .env file
46
+ TD_API_KEY=your_api_key_here
47
+ ```
48
+
49
+ Get your API key at: **https://console.testdriver.ai/team**
50
+
51
+ ## MCP Tools Reference
52
+
53
+ ### Session Management
54
+
55
+ | Tool | Description |
56
+ |------|-------------|
57
+ | `session_start` | Start sandbox with browser/app, returns initial screenshot |
58
+ | `session_status` | Check session health, time remaining |
59
+ | `session_extend` | Add more time before expiry |
60
+
61
+ ### Element Interaction
62
+
63
+ | Tool | Description |
64
+ |------|-------------|
65
+ | `find` | Locate element by description, returns ref |
66
+ | `click` | Click on element ref or coordinates |
67
+ | `find_and_click` | Find and click in one action |
68
+ | `type` | Type text into focused field |
69
+ | `press_keys` | Press keyboard shortcuts |
70
+ | `scroll` | Scroll page |
71
+
72
+ ### Verification
73
+
74
+ | Tool | Description |
75
+ |------|-------------|
76
+ | `check` | AI analysis of whether action succeeded - use after every action |
77
+ | `assert` | AI-powered boolean assertion (pass/fail for test files) |
78
+ | `exec` | Execute code in sandbox |
79
+ | `screenshot` | Capture screenshot |
80
+
81
+ ### Test Generation
82
+
83
+ | Tool | Description |
84
+ |------|-------------|
85
+ | `commit` | Write commands to test file |
86
+ | `verify` | Run test file |
87
+ | `get_command_log` | View recorded commands |
88
+
89
+ ## Example Workflow
90
+
91
+ ```
92
+ # 1. Start session
93
+ session_start({ type: "chrome", url: "https://app.example.com/login" })
94
+ → Screenshot shows login page
95
+
96
+ # 2. Fill in email
97
+ find_and_click({ description: "email input field" })
98
+ type({ text: "user@example.com" })
99
+
100
+ # 3. Check if email was entered
101
+ check({ task: "Was the email entered correctly?" })
102
+ → AI confirms email is in the field
103
+
104
+ # 4. Fill in password
105
+ find_and_click({ description: "password field" })
106
+ type({ text: "secret123" })
107
+
108
+ # 5. Submit login
109
+ find_and_click({ description: "Sign In button" })
110
+
111
+ # 6. Check if login succeeded
112
+ check({ task: "Did the login complete successfully?" })
113
+ → AI analyzes screen and confirms dashboard is visible
114
+
115
+ # 7. Assert success (for test file)
116
+ assert({ assertion: "dashboard is visible" })
117
+
118
+ # 8. Commit to file
119
+ commit({ testFile: "tests/login.test.mjs", testName: "Login Flow" })
120
+
121
+ # 9. Verify test runs
122
+ verify({ testFile: "tests/login.test.mjs" })
123
+ ```
124
+
125
+ ## Visual Feedback
126
+
127
+ Every tool returns a screenshot showing:
128
+
129
+ - **Element highlights** - Blue box around found elements
130
+ - **Click markers** - Red dot at click location
131
+ - **Action status** - Success/failure
132
+ - **Session info** - Time remaining
133
+
134
+ ## Best Practices
135
+
136
+ 1. **Use `check` after every action** - Verify actions succeeded before moving on
137
+ 2. **Work incrementally** - One action at a time, check the result
138
+ 3. **Be specific** - "blue Sign In button in header" > "button"
139
+ 4. **Use `check` for verification, `assert` for test files** - `check` gives AI analysis, `assert` gives boolean pass/fail
140
+ 5. **Watch session time** - Use `session_extend` if needed
141
+ 6. **Commit working sequences** - Don't lose progress
142
+
143
+ ## Error Recovery
144
+
145
+ ### Element Not Found
146
+
147
+ 1. Check screenshot to see actual screen state
148
+ 2. Adjust element description
149
+ 3. Add timeout: `find({ description: "...", timeout: 10000 })`
150
+ 4. Scroll if element is off-screen
151
+
152
+ ### Session Expired
153
+
154
+ 1. `session_start` again
155
+ 2. `verify` to replay committed test
156
+ 3. Continue from there
157
+
158
+ ## Tips for Agents
159
+
160
+ 1. **Use `check` after every action** - Verify actions succeeded before moving on
161
+ 2. **Examine every screenshot** - They show exactly what the sandbox sees
162
+ 3. **Be specific with descriptions** - More context = better element finding
163
+ 4. **Assert after major actions** - Catches issues early and gets recorded in test files
164
+ 5. **Commit often** - Preserve progress
165
+ 6. **Use `verify` to validate** - Ensures test works from scratch
@@ -0,0 +1,357 @@
1
+ ---
2
+ name: testdriver:type
3
+ description: Type text into focused input fields
4
+ ---
5
+ <!-- Generated from type.mdx. DO NOT EDIT. -->
6
+
7
+ ## Overview
8
+
9
+ Type text or numbers into the currently focused input field with optional delay between keystrokes.
10
+
11
+ ## Syntax
12
+
13
+ ```javascript
14
+ await testdriver.type(text, options)
15
+ ```
16
+
17
+ ## Parameters
18
+
19
+ <ParamField path="text" type="string | number" required>
20
+ Text to type (can be a string or number)
21
+ </ParamField>
22
+
23
+ <ParamField path="options" type="object | number">
24
+ Typing options (or legacy delay number)
25
+
26
+ <Expandable title="properties">
27
+ <ParamField path="delay" type="number" default={250}>
28
+ Delay between keystrokes in milliseconds
29
+ </ParamField>
30
+
31
+ <ParamField path="secret" type="boolean" default={false}>
32
+ If `true`, treats text as sensitive data (won't be logged or stored in debug info/dashcam)
33
+ </ParamField>
34
+ </Expandable>
35
+ </ParamField>
36
+
37
+ ## Returns
38
+
39
+ `Promise<void>`
40
+
41
+ ## Examples
42
+
43
+ ### Basic Typing
44
+
45
+ ```javascript
46
+ // Type text
47
+ await testdriver.type('hello@example.com');
48
+
49
+ // Type numbers
50
+ await testdriver.type(12345);
51
+
52
+ // Type with custom delay (legacy syntax)
53
+ await testdriver.type('slow typing', 500); // 500ms between each character
54
+
55
+ // Type with options object
56
+ await testdriver.type('text', { delay: 500 });
57
+ ```
58
+
59
+ ### Password/Secret Handling
60
+
61
+ ```javascript
62
+ // ✅ SECURE - Mark as secret to prevent logging
63
+ const passwordField = await testdriver.find('password input');
64
+ await passwordField.click();
65
+ await testdriver.type('MySecureP@ssw0rd', { secret: true });
66
+ // Password NOT logged in dashcam or debug output
67
+
68
+ // ❌ INSECURE - Password will be logged
69
+ await testdriver.type('MySecureP@ssw0rd');
70
+ // Password appears in logs, dashcam replay, and debug info
71
+
72
+ // Use secret for any sensitive data
73
+ await testdriver.find('api key input').click();
74
+ await testdriver.type('sk-1234567890abcdef', { secret: true });
75
+
76
+ await testdriver.find('credit card input').click();
77
+ await testdriver.type('4111111111111111', { secret: true });
78
+ ```
79
+
80
+ <Warning>
81
+ **Always use `secret: true` for passwords and sensitive data!**
82
+
83
+ Without this option, typed text appears in:
84
+ - Dashcam video replays
85
+ - TestDriver logs
86
+ - Debug screenshots
87
+ - Error messages
88
+ </Warning>
89
+
90
+ ### Form Filling
91
+
92
+ ```javascript
93
+ // Focus field and type
94
+ const emailField = await testdriver.find('email input');
95
+ await emailField.click();
96
+ await testdriver.type('user@example.com');
97
+
98
+ // Tab to next field and type
99
+ await testdriver.pressKeys(['tab']);
100
+ await testdriver.type('John Doe');
101
+
102
+ // Type password securely
103
+ await testdriver.pressKeys(['tab']);
104
+ await testdriver.type('MySecureP@ssw0rd', { secret: true });
105
+ ```
106
+
107
+ ### Clearing and Replacing Text
108
+
109
+ ```javascript
110
+ const searchBox = await testdriver.find('search input');
111
+ await searchBox.click();
112
+
113
+ // Clear existing text
114
+ await testdriver.pressKeys(['ctrl', 'a']); // Select all
115
+ await testdriver.type('new search query');
116
+ ```
117
+
118
+ ## Best Practices
119
+
120
+ <Check>
121
+ **Focus the field first**
122
+
123
+ Always click the input field or navigate to it before typing:
124
+
125
+ ```javascript
126
+ const input = await testdriver.find('username input');
127
+ await input.click();
128
+ await testdriver.type('testuser');
129
+ ```
130
+ </Check>
131
+
132
+ <Check>
133
+ **Use Tab for navigation**
134
+
135
+ Navigate between fields using Tab instead of clicking each one:
136
+
137
+ ```javascript
138
+ const firstField = await testdriver.find('first name');
139
+ await firstField.click();
140
+ await testdriver.type('John');
141
+
142
+ await testdriver.pressKeys(['tab']);
143
+ await testdriver.type('Doe');
144
+
145
+ await testdriver.pressKeys(['tab']);
146
+ await testdriver.type('john@example.com');
147
+ ```
148
+ </Check>
149
+
150
+ <Check>
151
+ **Clear fields before typing**
152
+
153
+ Clear existing content to avoid appending:
154
+
155
+ ```javascript
156
+ const input = await testdriver.find('search field');
157
+ await input.click();
158
+ await testdriver.pressKeys(['ctrl', 'a']); // Select all
159
+ await testdriver.type('new search');
160
+ ```
161
+ </Check>
162
+
163
+ <Warning>
164
+ **Field must be focused**
165
+
166
+ Typing will only work if an input field is currently focused. If no field is focused, the text may be lost or trigger unexpected keyboard shortcuts.
167
+ </Warning>
168
+
169
+ ## Use Cases
170
+
171
+ <AccordionGroup>
172
+ <Accordion title="Login Forms">
173
+ ```javascript
174
+ await testdriver.focusApplication('Google Chrome');
175
+
176
+ const usernameField = await testdriver.find('username input');
177
+ await usernameField.click();
178
+ await testdriver.type('testuser@example.com');
179
+
180
+ await testdriver.pressKeys(['tab']);
181
+ await testdriver.type('MyP@ssword123', { secret: true });
182
+
183
+ await testdriver.pressKeys(['enter']);
184
+ ```
185
+ </Accordion>
186
+
187
+ <Accordion title="Search Fields">
188
+ ```javascript
189
+ const searchBox = await testdriver.find('search input');
190
+ await searchBox.click();
191
+ await testdriver.type('laptop computers');
192
+ await testdriver.pressKeys(['enter']);
193
+
194
+ // Wait for results
195
+ await new Promise(r => setTimeout(r, 2000));
196
+ ```
197
+ </Accordion>
198
+
199
+ <Accordion title="Multi-Field Forms">
200
+ ```javascript
201
+ // First field
202
+ const nameField = await testdriver.find('full name input');
203
+ await nameField.click();
204
+ await testdriver.type('Jane Smith');
205
+
206
+ // Navigate with Tab
207
+ await testdriver.pressKeys(['tab']);
208
+ await testdriver.type('jane.smith@example.com');
209
+
210
+ await testdriver.pressKeys(['tab']);
211
+ await testdriver.type('+1-555-0123');
212
+
213
+ await testdriver.pressKeys(['tab']);
214
+ await testdriver.type('123 Main Street');
215
+ ```
216
+ </Accordion>
217
+
218
+ <Accordion title="Text Editors">
219
+ ```javascript
220
+ const editor = await testdriver.find('text editor area');
221
+ await editor.click();
222
+
223
+ await testdriver.type('# My Document', 100);
224
+ await testdriver.pressKeys(['enter', 'enter']);
225
+ await testdriver.type('This is the first paragraph.', 50);
226
+ ```
227
+ </Accordion>
228
+
229
+ <Accordion title="Numeric Input">
230
+ ```javascript
231
+ const quantityField = await testdriver.find('quantity input');
232
+ await quantityField.click();
233
+
234
+ // Clear field
235
+ await testdriver.pressKeys(['ctrl', 'a']);
236
+
237
+ // Type number
238
+ await testdriver.type(5);
239
+ ```
240
+ </Accordion>
241
+ </AccordionGroup>
242
+
243
+ ## Typing Speed
244
+
245
+ Adjust the delay parameter based on your needs:
246
+
247
+ ```javascript
248
+ // Fast typing (100ms delay)
249
+ await testdriver.type('quick entry', 100);
250
+
251
+ // Normal typing (250ms - default)
252
+ await testdriver.type('standard speed');
253
+
254
+ // Slow typing (500ms delay) - useful for fields with live validation
255
+ await testdriver.type('slow and steady', 500);
256
+
257
+ // Very slow (1000ms delay) - for problematic fields
258
+ await testdriver.type('one by one', 1000);
259
+ ```
260
+
261
+ <Note>
262
+ Some applications with live validation or autocomplete may require slower typing speeds to avoid race conditions.
263
+ </Note>
264
+
265
+ ## Special Characters
266
+
267
+ ```javascript
268
+ // Email addresses
269
+ await testdriver.type('user@example.com');
270
+
271
+ // URLs
272
+ await testdriver.type('https://example.com/path?query=value');
273
+
274
+ // Passwords with special characters
275
+ await testdriver.type('P@ssw0rd!#$%');
276
+
277
+ // Paths
278
+ await testdriver.type('C:\\Users\\Documents\\file.txt');
279
+
280
+ // Multi-line text (use pressKeys for Enter)
281
+ await testdriver.type('Line 1');
282
+ await testdriver.pressKeys(['enter']);
283
+ await testdriver.type('Line 2');
284
+ ```
285
+
286
+ ## Complete Example
287
+
288
+ ```javascript
289
+ import { beforeAll, afterAll, describe, it, expect } from 'vitest';
290
+ import TestDriver from 'testdriverai';
291
+
292
+ describe('Form Filling with Type', () => {
293
+ let testdriver;
294
+
295
+ beforeAll(async () => {
296
+ client = new TestDriver(process.env.TD_API_KEY);
297
+ await testdriver.auth();
298
+ await testdriver.connect();
299
+ });
300
+
301
+ afterAll(async () => {
302
+ await testdriver.disconnect();
303
+ });
304
+
305
+ it('should fill out registration form', async () => {
306
+ await testdriver.focusApplication('Google Chrome');
307
+
308
+ // Email field
309
+ const emailField = await testdriver.find('email input field');
310
+ await emailField.click();
311
+ await testdriver.type('john.doe@example.com');
312
+
313
+ // Tab through form fields
314
+ await testdriver.pressKeys(['tab']);
315
+ await testdriver.type('John');
316
+
317
+ await testdriver.pressKeys(['tab']);
318
+ await testdriver.type('Doe');
319
+
320
+ await testdriver.pressKeys(['tab']);
321
+ await testdriver.type('MySecureP@ssword123');
322
+
323
+ await testdriver.pressKeys(['tab']);
324
+ await testdriver.type('MySecureP@ssword123'); // Confirm password
325
+
326
+ // Verify fields were filled
327
+ const result = await testdriver.assert('all form fields are filled');
328
+ expect(result).toBeTruthy();
329
+ });
330
+
331
+ it('should update search query', async () => {
332
+ const searchBox = await testdriver.find('search input');
333
+ await searchBox.click();
334
+
335
+ // Type initial search
336
+ await testdriver.type('laptops');
337
+ await testdriver.pressKeys(['enter']);
338
+
339
+ await new Promise(r => setTimeout(r, 2000));
340
+
341
+ // Update search
342
+ await searchBox.click();
343
+ await testdriver.pressKeys(['ctrl', 'a']); // Select all
344
+ await testdriver.type('gaming laptops');
345
+ await testdriver.pressKeys(['enter']);
346
+
347
+ // Verify new search
348
+ await testdriver.assert('search results for "gaming laptops" are shown');
349
+ });
350
+ });
351
+ ```
352
+
353
+ ## Related Methods
354
+
355
+ - [`pressKeys()`](/v7/press-keys) - Press keyboard keys and shortcuts
356
+ - [`find()`](/v7/find) - Locate input fields
357
+ - [`click()`](/v7/click) - Focus input fields
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: testdriver:variables
3
+ description: Use dynamic data and secure secrets in your tests
4
+ ---
5
+ <!-- Generated from variables.mdx. DO NOT EDIT. -->
6
+
7
+ Scale your testing with dynamic data and secure secrets management. Choose the right approach based on your testing needs.
8
+
9
+ ## Environment Variables
10
+
11
+ Environment variables are ideal for **configuration that changes between environments** (dev, staging, production) or for **secrets that shouldn't be committed to code**. Use this approach when you need to run the same tests against different servers or with different credentials.
12
+
13
+ ```javascript
14
+ import { test } from 'vitest';
15
+ import { chrome } from 'testdriverai/presets';
16
+
17
+ test('multi-environment testing', async (context) => {
18
+ const env = process.env.TEST_ENV || 'staging';
19
+ const urls = {
20
+ dev: 'https://dev.myapp.com',
21
+ staging: 'https://staging.myapp.com',
22
+ production: 'https://myapp.com'
23
+ };
24
+
25
+ const { testdriver } = await chrome(context, {
26
+ url: urls[env]
27
+ });
28
+
29
+ await testdriver.assert('app is running');
30
+ });
31
+ ```
32
+
33
+ ```bash
34
+ # Run against different environments
35
+ TEST_ENV=dev vitest run
36
+ TEST_ENV=staging vitest run
37
+ TEST_ENV=production vitest run
38
+ ```
39
+
40
+ ## Test Fixtures
41
+
42
+ Test fixtures work best when you have **structured, reusable test data** that needs to be shared across multiple tests. Use fixtures when testing different user roles, product catalogs, or any scenario where you want to parameterize tests with a known set of data.
43
+
44
+ ```javascript test/fixtures/users.js
45
+ export const testUsers = [
46
+ { email: 'admin@test.com', role: 'admin' },
47
+ { email: 'user@test.com', role: 'user' },
48
+ { email: 'guest@test.com', role: 'guest' }
49
+ ];
50
+
51
+ export const products = [
52
+ { name: 'Laptop', price: 999 },
53
+ { name: 'Mouse', price: 29 },
54
+ { name: 'Keyboard', price: 89 }
55
+ ];
56
+ ```
57
+
58
+ ```javascript test/permissions.test.js
59
+ import { test } from 'vitest';
60
+ import { chrome } from 'testdriverai/presets';
61
+ import { testUsers } from './fixtures/users.js';
62
+
63
+ test.each(testUsers)('$role can access dashboard', async ({ email, role }, context) => {
64
+ const { testdriver } = await chrome(context, { url });
65
+
66
+ await testdriver.find('email input').type(email);
67
+ await testdriver.find('password input').type('password123');
68
+ await testdriver.find('login button').click();
69
+
70
+ if (role === 'admin') {
71
+ await testdriver.assert('admin panel is visible');
72
+ } else {
73
+ await testdriver.assert('user dashboard is visible');
74
+ }
75
+ });
76
+ ```
77
+
78
+ ## Dynamic Data Generation
79
+
80
+ Dynamic data generation is perfect for **creating unique test data on each run**, avoiding conflicts with existing records, and **testing edge cases with realistic data**. Use libraries like Faker when you need fresh emails, names, or other data that won't collide with previous test runs.
81
+
82
+ ```javascript
83
+ import { test } from 'vitest';
84
+ import { chrome } from 'testdriverai/presets';
85
+ import { faker } from '@faker-js/faker';
86
+
87
+ test('user registration with dynamic data', async (context) => {
88
+ const { testdriver } = await chrome(context, { url });
89
+
90
+ // Generate unique test data for each run
91
+ const userData = {
92
+ firstName: faker.person.firstName(),
93
+ lastName: faker.person.lastName(),
94
+ email: faker.internet.email(),
95
+ password: faker.internet.password({ length: 12 })
96
+ };
97
+
98
+ await testdriver.find('first name input').type(userData.firstName);
99
+ await testdriver.find('last name input').type(userData.lastName);
100
+ await testdriver.find('email input').type(userData.email);
101
+ await testdriver.find('password input').type(userData.password);
102
+ await testdriver.find('register button').click();
103
+
104
+ await testdriver.assert('registration successful');
105
+ console.log('Registered user:', userData.email);
106
+ });
107
+ ```
108
+
109
+ ```bash
110
+ npm install --save-dev @faker-js/faker
111
+ ```
@@ -0,0 +1,66 @@
1
+ ---
2
+ name: testdriver:waiting-for-elements
3
+ description: Handle async operations and prevent flaky tests
4
+ ---
5
+ <!-- Generated from waiting-for-elements.mdx. DO NOT EDIT. -->
6
+
7
+ ## Waiting for Elements
8
+
9
+ Use the `timeout` option with `find()` to wait for elements that appear after async operations:
10
+
11
+ ```javascript
12
+ // Wait up to 30 seconds for element to appear (polls every 5 seconds)
13
+ const element = await testdriver.find('Loading complete indicator', { timeout: 30000 });
14
+ await element.click();
15
+
16
+ // Useful after actions that trigger loading states
17
+ await testdriver.find('submit button').click();
18
+ await testdriver.find('success message', { timeout: 15000 });
19
+
20
+ // Short timeout for quick checks
21
+ const toast = await testdriver.find('notification toast', { timeout: 5000 });
22
+ ```
23
+
24
+ ## Flake Prevention
25
+
26
+ TestDriver automatically waits for the screen and network to stabilize after each action using **redraw detection**. This prevents flaky tests caused by animations, loading states, or dynamic content updates.
27
+
28
+ <Note>
29
+ Redraw detection adds a small delay after each action but significantly reduces test flakiness.
30
+ </Note>
31
+
32
+ For example, when clicking a submit button that navigates to a new page:
33
+
34
+ ```javascript
35
+ // Click submit - TestDriver automatically waits for the new page to load
36
+ await testdriver.find('submit button').click();
37
+
38
+ // By the time this runs, the page has fully loaded and stabilized
39
+ await testdriver.assert('dashboard is displayed');
40
+ await testdriver.find('welcome message');
41
+ ```
42
+
43
+ Without redraw detection, you'd need manual waits or retries to handle the page transition. TestDriver handles this automatically by detecting when the screen stops changing and network requests complete.
44
+
45
+ You can disable redraw detection or customize its behavior:
46
+
47
+ ```javascript
48
+ // Disable redraw detection for faster tests (less reliable)
49
+ const testdriver = TestDriver(context, {
50
+ redraw: false
51
+ });
52
+ ```
53
+
54
+ Here is an example of customizing redraw detection:
55
+
56
+ ```javascript
57
+ // Fine-tune redraw detection
58
+ const testdriver = TestDriver(context, {
59
+ redraw: {
60
+ enabled: true,
61
+ diffThreshold: 0.1, // Pixel difference threshold (0-1)
62
+ screenRedraw: true, // Monitor screen changes
63
+ networkMonitor: true, // Wait for network idle
64
+ }
65
+ });
66
+ ```