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.
- package/.github/skills/testdriver:ai/SKILL.md +204 -0
- package/.github/skills/testdriver:assert/SKILL.md +284 -0
- package/.github/skills/testdriver:aws-setup/SKILL.md +515 -0
- package/.github/skills/testdriver:caching/SKILL.md +124 -0
- package/.github/skills/testdriver:captcha/SKILL.md +159 -0
- package/.github/skills/testdriver:ci-cd/SKILL.md +602 -0
- package/.github/skills/testdriver:click/SKILL.md +286 -0
- package/.github/skills/testdriver:client/SKILL.md +339 -0
- package/.github/skills/testdriver:cloud/SKILL.md +119 -0
- package/.github/skills/testdriver:customizing-devices/SKILL.md +153 -0
- package/.github/skills/testdriver:dashcam/SKILL.md +418 -0
- package/.github/skills/testdriver:debugging-with-screenshots/SKILL.md +271 -0
- package/.github/skills/testdriver:device-config/SKILL.md +317 -0
- package/.github/skills/testdriver:double-click/SKILL.md +102 -0
- package/.github/skills/testdriver:elements/SKILL.md +605 -0
- package/.github/skills/testdriver:enterprise/SKILL.md +114 -0
- package/.github/skills/testdriver:examples/SKILL.md +7 -0
- package/.github/skills/testdriver:exec/SKILL.md +345 -0
- package/.github/skills/testdriver:find/SKILL.md +721 -0
- package/.github/skills/testdriver:focus-application/SKILL.md +293 -0
- package/.github/skills/testdriver:generating-tests/SKILL.md +36 -0
- package/.github/skills/testdriver:hover/SKILL.md +278 -0
- package/.github/skills/testdriver:locating-elements/SKILL.md +71 -0
- package/.github/skills/testdriver:making-assertions/SKILL.md +32 -0
- package/.github/skills/testdriver:mcp-workflow/SKILL.md +410 -0
- package/.github/skills/testdriver:mouse-down/SKILL.md +161 -0
- package/.github/skills/testdriver:mouse-up/SKILL.md +164 -0
- package/.github/skills/testdriver:performing-actions/SKILL.md +51 -0
- package/.github/skills/testdriver:press-keys/SKILL.md +348 -0
- package/.github/skills/testdriver:quickstart/SKILL.md +161 -0
- package/.github/skills/testdriver:reusable-code/SKILL.md +240 -0
- package/.github/skills/testdriver:right-click/SKILL.md +123 -0
- package/.github/skills/testdriver:running-tests/SKILL.md +181 -0
- package/.github/skills/testdriver:screenshot/SKILL.md +167 -0
- package/.github/skills/testdriver:scroll/SKILL.md +299 -0
- package/.github/skills/testdriver:secrets/SKILL.md +115 -0
- package/.github/skills/testdriver:self-hosted/SKILL.md +65 -0
- package/.github/skills/testdriver:test-writer/SKILL.md +451 -0
- package/.github/skills/testdriver:testdriver/SKILL.md +523 -0
- package/.github/skills/testdriver:testdriver-mechanic/SKILL.md +165 -0
- package/.github/skills/testdriver:type/SKILL.md +357 -0
- package/.github/skills/testdriver:variables/SKILL.md +111 -0
- package/.github/skills/testdriver:waiting-for-elements/SKILL.md +66 -0
- package/.github/skills/testdriver:what-is-testdriver/SKILL.md +54 -0
- package/.github/workflows/acceptance-windows-scheduled.yaml +6 -1
- package/.github/workflows/acceptance.yaml +0 -36
- package/.github/workflows/update-examples.yaml +53 -0
- package/CHANGELOG.md +4 -0
- package/agent/events.js +1 -0
- package/agent/index.js +8 -0
- package/agent/lib/commands.js +48 -29
- package/agent/lib/redraw.js +3 -1
- package/agent/lib/sandbox.js +166 -14
- package/agent/lib/sdk.js +142 -3
- package/agent/lib/system.js +4 -6
- package/ai/skills/testdriver:ai/SKILL.md +204 -0
- package/ai/skills/testdriver:assert/SKILL.md +315 -0
- package/ai/skills/testdriver:aws-setup/SKILL.md +448 -0
- package/ai/skills/testdriver:caching/SKILL.md +124 -0
- package/ai/skills/testdriver:captcha/SKILL.md +159 -0
- package/ai/skills/testdriver:ci-cd/SKILL.md +602 -0
- package/ai/skills/testdriver:click/SKILL.md +286 -0
- package/ai/skills/testdriver:client/SKILL.md +372 -0
- package/ai/skills/testdriver:cloud/SKILL.md +119 -0
- package/ai/skills/testdriver:customizing-devices/SKILL.md +153 -0
- package/ai/skills/testdriver:dashcam/SKILL.md +418 -0
- package/ai/skills/testdriver:debugging-with-screenshots/SKILL.md +401 -0
- package/ai/skills/testdriver:device-config/SKILL.md +317 -0
- package/ai/skills/testdriver:double-click/SKILL.md +102 -0
- package/ai/skills/testdriver:elements/SKILL.md +605 -0
- package/ai/skills/testdriver:enterprise/SKILL.md +114 -0
- package/ai/skills/testdriver:examples/SKILL.md +7 -0
- package/ai/skills/testdriver:exec/SKILL.md +345 -0
- package/ai/skills/testdriver:find/SKILL.md +745 -0
- package/ai/skills/testdriver:focus-application/SKILL.md +293 -0
- package/ai/skills/testdriver:generating-tests/SKILL.md +36 -0
- package/ai/skills/testdriver:hover/SKILL.md +278 -0
- package/ai/skills/testdriver:locating-elements/SKILL.md +71 -0
- package/ai/skills/testdriver:making-assertions/SKILL.md +32 -0
- package/ai/skills/testdriver:mcp-workflow/SKILL.md +410 -0
- package/ai/skills/testdriver:mouse-down/SKILL.md +161 -0
- package/ai/skills/testdriver:mouse-up/SKILL.md +164 -0
- package/ai/skills/testdriver:ocr/SKILL.md +235 -0
- package/ai/skills/testdriver:performing-actions/SKILL.md +51 -0
- package/ai/skills/testdriver:press-keys/SKILL.md +348 -0
- package/ai/skills/testdriver:quickstart/SKILL.md +146 -0
- package/ai/skills/testdriver:reusable-code/SKILL.md +240 -0
- package/ai/skills/testdriver:right-click/SKILL.md +123 -0
- package/ai/skills/testdriver:running-tests/SKILL.md +185 -0
- package/ai/skills/testdriver:screenshot/SKILL.md +248 -0
- package/ai/skills/testdriver:scroll/SKILL.md +335 -0
- package/ai/skills/testdriver:secrets/SKILL.md +115 -0
- package/ai/skills/testdriver:self-hosted/SKILL.md +65 -0
- package/ai/skills/testdriver:test-writer/SKILL.md +451 -0
- package/ai/skills/testdriver:testdriver/SKILL.md +631 -0
- package/ai/skills/testdriver:testdriver-mechanic/SKILL.md +165 -0
- package/ai/skills/testdriver:type/SKILL.md +357 -0
- package/ai/skills/testdriver:variables/SKILL.md +111 -0
- package/ai/skills/testdriver:waiting-for-elements/SKILL.md +66 -0
- package/ai/skills/testdriver:what-is-testdriver/SKILL.md +54 -0
- package/debugger/index.html +12 -2
- package/docs/v7/examples/scroll-keyboard.mdx +1 -1
- package/docs/v7/find.mdx +1 -0
- package/examples/config.mjs +1 -1
- package/examples/findall-coffee-icons.test.mjs +42 -0
- package/examples/flake-diffthreshold-001.test.mjs +9 -0
- package/examples/flake-diffthreshold-01.test.mjs +9 -0
- package/examples/flake-diffthreshold-05.test.mjs +9 -0
- package/examples/{z_flake-noredraw-cache.test.mjs → flake-noredraw-cache.test.mjs} +2 -2
- package/examples/{z_flake-noredraw-nocache.test.mjs → flake-noredraw-nocache.test.mjs} +2 -2
- package/examples/{z_flake-redraw-cache.test.mjs → flake-redraw-cache.test.mjs} +2 -2
- package/examples/{z_flake-redraw-nocache.test.mjs → flake-redraw-nocache.test.mjs} +2 -2
- package/examples/flake-rocket-match.test.mjs +30 -0
- package/examples/{z_flake-shared.mjs → flake-shared.mjs} +2 -2
- package/examples/parse.test.mjs +19 -0
- package/examples/scroll-keyboard.test.mjs +1 -1
- package/interfaces/cli/lib/base.js +6 -0
- package/interfaces/logger.js +51 -13
- package/interfaces/vitest-plugin.mjs +137 -0
- package/lib/core/index.d.ts +22 -0
- package/lib/init-project.js +105 -6
- package/lib/vitest/hooks.mjs +2 -5
- package/lib/vitest/setup-disable-defender.mjs +52 -0
- package/package.json +2 -1
- package/sdk-log-formatter.js +90 -0
- package/sdk.d.ts +88 -51
- package/sdk.js +126 -18
- package/setup/aws/disable-defender.sh +42 -0
- package/vitest.config.mjs +1 -3
- package/examples/z_flake-diffthreshold-001.test.mjs +0 -9
- package/examples/z_flake-diffthreshold-01.test.mjs +0 -9
- package/examples/z_flake-diffthreshold-05.test.mjs +0 -9
- /package/{examples → manual}/captcha-api.test.mjs +0 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testdriver:screenshot
|
|
3
|
+
description: Capture and save screenshots during test execution
|
|
4
|
+
---
|
|
5
|
+
<!-- Generated from screenshot.mdx. DO NOT EDIT. -->
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Capture a screenshot of the current screen and automatically save it to a local file. Screenshots are organized by test file for easy debugging and review.
|
|
10
|
+
|
|
11
|
+
<Note>
|
|
12
|
+
**Automatic Screenshots (Default: Enabled)**: TestDriver automatically captures screenshots before and after every command (click, type, find, etc.). These are saved with descriptive filenames like `001-click-before-L42-submit-button.png` that include the line number from your test file. You can disable this with `autoScreenshots: false` in your TestDriver options.
|
|
13
|
+
</Note>
|
|
14
|
+
|
|
15
|
+
## Syntax
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const filePath = await testdriver.screenshot(filename)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
<ParamField path="filename" type="string" optional>
|
|
24
|
+
Custom filename for the screenshot (without .png extension). If not provided, a timestamp-based filename is generated automatically.
|
|
25
|
+
</ParamField>
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`Promise<string>` - The absolute file path where the screenshot was saved
|
|
30
|
+
|
|
31
|
+
## File Organization
|
|
32
|
+
|
|
33
|
+
Screenshots are automatically saved to `.testdriver/screenshots/<test-file-name>/` in your project root:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
.testdriver/
|
|
37
|
+
screenshots/
|
|
38
|
+
login.test/
|
|
39
|
+
001-find-before-L15-email-input.png # Auto: before find()
|
|
40
|
+
002-find-after-L15-email-input.png # Auto: after find()
|
|
41
|
+
003-click-before-L16-email-input.png # Auto: before click()
|
|
42
|
+
004-click-after-L16-email-input.png # Auto: after click()
|
|
43
|
+
005-type-before-L17-userexamplecom.png # Auto: before type()
|
|
44
|
+
006-type-after-L17-userexamplecom.png # Auto: after type()
|
|
45
|
+
custom-screenshot.png # Manual: screenshot("custom-screenshot")
|
|
46
|
+
checkout.test/
|
|
47
|
+
001-find-before-L12-checkout-button.png
|
|
48
|
+
...
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Automatic Screenshot Naming
|
|
52
|
+
|
|
53
|
+
When `autoScreenshots` is enabled (default), filenames follow this format:
|
|
54
|
+
|
|
55
|
+
`<seq>-<action>-<phase>-L<line>-<description>.png`
|
|
56
|
+
|
|
57
|
+
| Component | Description | Example |
|
|
58
|
+
|-----------|-------------|---------|
|
|
59
|
+
| `seq` | Sequential number (001, 002, ...) | `001` |
|
|
60
|
+
| `action` | Command name | `click`, `type`, `find` |
|
|
61
|
+
| `phase` | Before, after, or error | `before`, `after` |
|
|
62
|
+
| `L<line>` | Line number from test file | `L42` |
|
|
63
|
+
| `description` | Element description or action target | `submit-button` |
|
|
64
|
+
|
|
65
|
+
<Note>
|
|
66
|
+
The screenshot folder for each test file is automatically cleared when the test starts. This ensures you only see screenshots from the most recent test run.
|
|
67
|
+
</Note>
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
### Basic Screenshot
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// Capture a screenshot with auto-generated filename
|
|
75
|
+
const screenshotPath = await testdriver.screenshot();
|
|
76
|
+
console.log('Screenshot saved to:', screenshotPath);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Custom Filename
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
// Save with a descriptive filename
|
|
83
|
+
await testdriver.screenshot("login-page");
|
|
84
|
+
// Saves to: .testdriver/screenshots/<test>/login-page.png
|
|
85
|
+
|
|
86
|
+
await testdriver.screenshot("after-click");
|
|
87
|
+
// Saves to: .testdriver/screenshots/<test>/after-click.png
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Debugging with Screenshots
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import { describe, expect, it } from "vitest";
|
|
94
|
+
import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
|
|
95
|
+
|
|
96
|
+
describe("Login Flow", () => {
|
|
97
|
+
it("should log in successfully", async (context) => {
|
|
98
|
+
const testdriver = TestDriver(context);
|
|
99
|
+
|
|
100
|
+
await testdriver.provision.chrome({
|
|
101
|
+
url: 'https://myapp.com/login',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Capture initial state
|
|
105
|
+
await testdriver.screenshot();
|
|
106
|
+
|
|
107
|
+
// Fill in login form
|
|
108
|
+
const emailInput = await testdriver.find("email input");
|
|
109
|
+
await emailInput.click();
|
|
110
|
+
await testdriver.type("user@example.com");
|
|
111
|
+
|
|
112
|
+
// Capture state after typing
|
|
113
|
+
await testdriver.screenshot();
|
|
114
|
+
|
|
115
|
+
const passwordInput = await testdriver.find("password input");
|
|
116
|
+
await passwordInput.click();
|
|
117
|
+
await testdriver.type("password123");
|
|
118
|
+
|
|
119
|
+
// Capture before clicking login
|
|
120
|
+
await testdriver.screenshot();
|
|
121
|
+
|
|
122
|
+
const loginButton = await testdriver.find("Login button");
|
|
123
|
+
await loginButton.click();
|
|
124
|
+
|
|
125
|
+
// Capture after login attempt
|
|
126
|
+
await testdriver.screenshot();
|
|
127
|
+
|
|
128
|
+
const result = await testdriver.assert("dashboard is visible");
|
|
129
|
+
expect(result).toBeTruthy();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Automatic Screenshots
|
|
135
|
+
|
|
136
|
+
By default, TestDriver captures screenshots **automatically** before and after every command. This creates a complete visual timeline of your test execution without any additional code.
|
|
137
|
+
|
|
138
|
+
### Enabling/Disabling
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
// Auto-screenshots enabled by default
|
|
142
|
+
const testdriver = TestDriver(context);
|
|
143
|
+
|
|
144
|
+
// Explicitly disable if needed (not recommended)
|
|
145
|
+
const testdriver = TestDriver(context, {
|
|
146
|
+
autoScreenshots: false
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### What Gets Captured
|
|
151
|
+
|
|
152
|
+
Automatic screenshots are taken around these commands:
|
|
153
|
+
- `find()` / `findAll()`
|
|
154
|
+
- `click()` / `hover()` / `doubleClick()` / `rightClick()`
|
|
155
|
+
- `type()` / `pressKeys()`
|
|
156
|
+
- `scroll()` / `scrollUntilText()` / `scrollUntilImage()`
|
|
157
|
+
- `waitForText()` / `waitForImage()`
|
|
158
|
+
- `focusApplication()`
|
|
159
|
+
- `assert()` / `extract()` / `exec()`
|
|
160
|
+
|
|
161
|
+
### Example Output
|
|
162
|
+
|
|
163
|
+
For this test code:
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
// Line 15: Find email input
|
|
167
|
+
const emailInput = await testdriver.find("email input");
|
|
168
|
+
// Line 16: Click it
|
|
169
|
+
await emailInput.click();
|
|
170
|
+
// Line 17: Type email
|
|
171
|
+
await testdriver.type("user@example.com");
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
TestDriver automatically saves:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
001-find-before-L15-email-input.png
|
|
178
|
+
002-find-after-L15-email-input.png
|
|
179
|
+
003-click-before-L16-email-input.png
|
|
180
|
+
004-click-after-L16-email-input.png
|
|
181
|
+
005-type-before-L17-userexamplecom.png
|
|
182
|
+
006-type-after-L17-userexamplecom.png
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
If an error occurs, the phase will be `error` instead of `after`.
|
|
186
|
+
|
|
187
|
+
## Best Practices
|
|
188
|
+
|
|
189
|
+
<AccordionGroup>
|
|
190
|
+
<Accordion title="Let automatic screenshots do the work">
|
|
191
|
+
With `autoScreenshots: true` (default), you get comprehensive coverage without adding manual `screenshot()` calls. Only add manual screenshots for specific named checkpoints.
|
|
192
|
+
</Accordion>
|
|
193
|
+
|
|
194
|
+
<Accordion title="Use screenshots for debugging flaky tests">
|
|
195
|
+
When a test fails intermittently, add screenshots at key steps to capture the actual screen state. This helps identify timing issues or unexpected UI states.
|
|
196
|
+
</Accordion>
|
|
197
|
+
|
|
198
|
+
<Accordion title="Capture before assertions">
|
|
199
|
+
Take a screenshot before making assertions. If the assertion fails, you'll have a visual record of what the screen looked like.
|
|
200
|
+
|
|
201
|
+
```javascript
|
|
202
|
+
await testdriver.screenshot();
|
|
203
|
+
const result = await testdriver.assert("checkout button is visible");
|
|
204
|
+
```
|
|
205
|
+
</Accordion>
|
|
206
|
+
|
|
207
|
+
<Accordion title="Add to .gitignore">
|
|
208
|
+
Add `.testdriver/screenshots/` to your `.gitignore` to avoid committing screenshots to version control:
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
# .gitignore
|
|
212
|
+
.testdriver/screenshots/
|
|
213
|
+
```
|
|
214
|
+
</Accordion>
|
|
215
|
+
</AccordionGroup>
|
|
216
|
+
|
|
217
|
+
## Viewing Saved Screenshots
|
|
218
|
+
|
|
219
|
+
After saving screenshots during test execution, you can view them using TestDriver MCP commands. This is especially useful for debugging failed tests or verifying test behavior.
|
|
220
|
+
|
|
221
|
+
### MCP Commands for Screenshot Viewing
|
|
222
|
+
|
|
223
|
+
**List all saved screenshots:**
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
list_local_screenshots()
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**View a specific screenshot:**
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
view_local_screenshot({ path: "/full/path/to/screenshot.png" })
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
These commands allow you to:
|
|
236
|
+
- View screenshots from failed tests to understand what went wrong
|
|
237
|
+
- Review test execution flow by examining screenshots in chronological order
|
|
238
|
+
- Compare screenshots across test runs to identify flaky behavior
|
|
239
|
+
|
|
240
|
+
<Note>
|
|
241
|
+
For detailed workflows and examples of using these MCP commands for debugging, see the [Debugging with Screenshots](/v7/debugging-with-screenshots) guide.
|
|
242
|
+
</Note>
|
|
243
|
+
|
|
244
|
+
## Related
|
|
245
|
+
|
|
246
|
+
- [Debugging with Screenshots](/v7/debugging-with-screenshots) - View and analyze saved screenshots using MCP
|
|
247
|
+
- [assert()](/v7/assert) - Make AI-powered assertions
|
|
248
|
+
- [find()](/v7/find) - Locate elements on screen
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testdriver:scroll
|
|
3
|
+
description: Scroll pages and elements
|
|
4
|
+
---
|
|
5
|
+
<!-- Generated from scroll.mdx. DO NOT EDIT. -->
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Scroll the page or active element in any direction using mouse wheel or keyboard.
|
|
10
|
+
|
|
11
|
+
<Warning>
|
|
12
|
+
**Focus Requirements**
|
|
13
|
+
|
|
14
|
+
Scrolling requires the page or a frame to be focused. If an input field or other interactive element has focus, scroll commands may not work as expected. Before scrolling, ensure focus is on the page by:
|
|
15
|
+
- Clicking on a non-interactive area (e.g., page background)
|
|
16
|
+
- Pressing the Escape key to unfocus interactive elements
|
|
17
|
+
- Clicking outside of input fields or text areas
|
|
18
|
+
|
|
19
|
+
**If scroll is still not working**, try using Page Down/Page Up keys directly:
|
|
20
|
+
```javascript
|
|
21
|
+
await testdriver.pressKeys(['pagedown']); // Scroll down
|
|
22
|
+
await testdriver.pressKeys(['pageup']); // Scroll up
|
|
23
|
+
```
|
|
24
|
+
</Warning>
|
|
25
|
+
|
|
26
|
+
## Syntax
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
await testdriver.scroll(direction, amount, method)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Parameters
|
|
33
|
+
|
|
34
|
+
<ParamField path="direction" type="string" default="down">
|
|
35
|
+
Direction to scroll: `'up'`, `'down'`, `'left'`, `'right'`
|
|
36
|
+
</ParamField>
|
|
37
|
+
|
|
38
|
+
<ParamField path="amount" type="number" default="300">
|
|
39
|
+
Amount to scroll in pixels
|
|
40
|
+
</ParamField>
|
|
41
|
+
|
|
42
|
+
<ParamField path="method" type="string" default="mouse">
|
|
43
|
+
Scroll method: `'mouse'` or `'keyboard'`
|
|
44
|
+
</ParamField>
|
|
45
|
+
|
|
46
|
+
## Returns
|
|
47
|
+
|
|
48
|
+
`Promise<void>`
|
|
49
|
+
|
|
50
|
+
## Examples
|
|
51
|
+
|
|
52
|
+
### Basic Scrolling
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// Scroll down (default)
|
|
56
|
+
await testdriver.scroll();
|
|
57
|
+
|
|
58
|
+
// Scroll down 500 pixels
|
|
59
|
+
await testdriver.scroll('down', 500);
|
|
60
|
+
|
|
61
|
+
// Scroll up
|
|
62
|
+
await testdriver.scroll('up');
|
|
63
|
+
|
|
64
|
+
// Scroll up 200 pixels
|
|
65
|
+
await testdriver.scroll('up', 200);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Horizontal Scrolling
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
// Scroll right
|
|
72
|
+
await testdriver.scroll('right', 300);
|
|
73
|
+
|
|
74
|
+
// Scroll left
|
|
75
|
+
await testdriver.scroll('left', 300);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Scroll Methods
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
// Mouse wheel scroll (smooth, pixel-precise)
|
|
82
|
+
await testdriver.scroll('down', 300, 'mouse');
|
|
83
|
+
|
|
84
|
+
// Keyboard scroll (uses Page Down/Up, more compatible)
|
|
85
|
+
await testdriver.scroll('down', 300, 'keyboard');
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Scroll Until Found
|
|
89
|
+
|
|
90
|
+
### scrollUntilText()
|
|
91
|
+
|
|
92
|
+
Scroll until specific text appears on screen.
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
await testdriver.scrollUntilText(text, direction, maxDistance, textMatchMethod, method, invert)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Parameters:**
|
|
99
|
+
- `text` (string) - Text to find
|
|
100
|
+
- `direction` (string) - Scroll direction (default: `'down'`)
|
|
101
|
+
- `maxDistance` (number) - Max pixels to scroll (default: 10000)
|
|
102
|
+
- `textMatchMethod` (string) - `'turbo'` or `'ai'` (default: `'turbo'`)
|
|
103
|
+
- `method` (string) - `'keyboard'` or `'mouse'` (default: `'keyboard'`)
|
|
104
|
+
- `invert` (boolean) - Scroll until text disappears (default: false)
|
|
105
|
+
|
|
106
|
+
**Examples:**
|
|
107
|
+
```javascript
|
|
108
|
+
// Scroll down until "Contact Us" appears
|
|
109
|
+
await testdriver.scrollUntilText('Contact Us');
|
|
110
|
+
|
|
111
|
+
// Scroll up to find text
|
|
112
|
+
await testdriver.scrollUntilText('Header', 'up');
|
|
113
|
+
|
|
114
|
+
// Scroll until text disappears
|
|
115
|
+
await testdriver.scrollUntilText('Loading...', 'down', 5000, 'turbo', 'keyboard', true);
|
|
116
|
+
|
|
117
|
+
// Use AI matching for fuzzy text
|
|
118
|
+
await testdriver.scrollUntilText('footer content', 'down', 10000, 'ai');
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### scrollUntilImage()
|
|
122
|
+
|
|
123
|
+
Scroll until a visual element appears.
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
await testdriver.scrollUntilImage(description, direction, maxDistance, method, path, invert)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Parameters:**
|
|
130
|
+
- `description` (string) - Description of the image/element
|
|
131
|
+
- `direction` (string) - Scroll direction (default: `'down'`)
|
|
132
|
+
- `maxDistance` (number) - Max pixels to scroll (default: 10000)
|
|
133
|
+
- `method` (string) - `'keyboard'` or `'mouse'` (default: `'keyboard'`)
|
|
134
|
+
- `path` (string | null) - Path to image template (optional)
|
|
135
|
+
- `invert` (boolean) - Scroll until image disappears (default: false)
|
|
136
|
+
|
|
137
|
+
**Examples:**
|
|
138
|
+
```javascript
|
|
139
|
+
// Scroll until visual element appears
|
|
140
|
+
await testdriver.scrollUntilImage('red subscribe button');
|
|
141
|
+
|
|
142
|
+
// Scroll using image template
|
|
143
|
+
await testdriver.scrollUntilImage('', 'down', 10000, 'keyboard', './footer-logo.png');
|
|
144
|
+
|
|
145
|
+
// Scroll until image disappears
|
|
146
|
+
await testdriver.scrollUntilImage('loading spinner', 'down', 5000, 'keyboard', null, true);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Best Practices
|
|
150
|
+
|
|
151
|
+
<Check>
|
|
152
|
+
**Ensure page has focus before scrolling**
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
// After typing in an input, unfocus it first
|
|
156
|
+
await testdriver.find('email input').click();
|
|
157
|
+
await testdriver.type('user@example.com');
|
|
158
|
+
|
|
159
|
+
// Click elsewhere or press Escape before scrolling
|
|
160
|
+
await testdriver.pressKeys(['escape']);
|
|
161
|
+
// Or click a non-interactive area
|
|
162
|
+
// await testdriver.find('page background').click();
|
|
163
|
+
|
|
164
|
+
// Now scroll will work properly
|
|
165
|
+
await testdriver.scroll('down', 300);
|
|
166
|
+
|
|
167
|
+
// If scroll still doesn't work, use Page Down directly
|
|
168
|
+
// await testdriver.pressKeys(['pagedown']);
|
|
169
|
+
```
|
|
170
|
+
</Check>
|
|
171
|
+
|
|
172
|
+
<Check>
|
|
173
|
+
**Choose the right scroll method**
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
// For web pages, mouse scroll is usually smoother
|
|
177
|
+
await testdriver.scroll('down', 300, 'mouse');
|
|
178
|
+
|
|
179
|
+
// For desktop apps or when mouse doesn't work
|
|
180
|
+
await testdriver.scroll('down', 300, 'keyboard');
|
|
181
|
+
```
|
|
182
|
+
</Check>
|
|
183
|
+
|
|
184
|
+
<Check>
|
|
185
|
+
**Use scrollUntil for dynamic content**
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
// Instead of guessing scroll amount
|
|
189
|
+
await testdriver.scrollUntilText('Load More button');
|
|
190
|
+
|
|
191
|
+
const loadMoreBtn = await testdriver.find('Load More button');
|
|
192
|
+
await loadMoreBtn.click();
|
|
193
|
+
```
|
|
194
|
+
</Check>
|
|
195
|
+
|
|
196
|
+
<Check>
|
|
197
|
+
**Set reasonable max distance**
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
// Avoid infinite scrolling
|
|
201
|
+
await testdriver.scrollUntilText('Footer', 'down', 5000); // Max 5000px
|
|
202
|
+
```
|
|
203
|
+
</Check>
|
|
204
|
+
|
|
205
|
+
<Warning>
|
|
206
|
+
**Keyboard scroll uses Page Down/Up**
|
|
207
|
+
|
|
208
|
+
Keyboard scrolling typically moves by one "page" at a time, which may be more than the specified pixel amount. It's more compatible but less precise than mouse scrolling.
|
|
209
|
+
</Warning>
|
|
210
|
+
|
|
211
|
+
## Use Cases
|
|
212
|
+
|
|
213
|
+
<AccordionGroup>
|
|
214
|
+
<Accordion title="Navigate to Footer">
|
|
215
|
+
```javascript
|
|
216
|
+
// Scroll to bottom of page
|
|
217
|
+
await testdriver.scrollUntilText('Contact Us');
|
|
218
|
+
|
|
219
|
+
const contactLink = await testdriver.find('Contact Us link');
|
|
220
|
+
await contactLink.click();
|
|
221
|
+
```
|
|
222
|
+
</Accordion>
|
|
223
|
+
|
|
224
|
+
<Accordion title="Load More Results">
|
|
225
|
+
```javascript
|
|
226
|
+
// Scroll to load more button
|
|
227
|
+
await testdriver.scrollUntilText('Load More');
|
|
228
|
+
|
|
229
|
+
const loadBtn = await testdriver.find('Load More button');
|
|
230
|
+
await loadBtn.click();
|
|
231
|
+
|
|
232
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
233
|
+
```
|
|
234
|
+
</Accordion>
|
|
235
|
+
|
|
236
|
+
<Accordion title="Find Element in Long List">
|
|
237
|
+
```javascript
|
|
238
|
+
// Scroll through list to find item
|
|
239
|
+
await testdriver.scrollUntilText('Product #42');
|
|
240
|
+
|
|
241
|
+
const product = await testdriver.find('Product #42');
|
|
242
|
+
await product.click();
|
|
243
|
+
```
|
|
244
|
+
</Accordion>
|
|
245
|
+
|
|
246
|
+
<Accordion title="Infinite Scroll">
|
|
247
|
+
```javascript
|
|
248
|
+
// Scroll multiple times for infinite scroll
|
|
249
|
+
for (let i = 0; i < 5; i++) {
|
|
250
|
+
await testdriver.scroll('down', 500);
|
|
251
|
+
await new Promise(r => setTimeout(r, 1000)); // Wait for load
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
</Accordion>
|
|
255
|
+
|
|
256
|
+
<Accordion title="Horizontal Gallery">
|
|
257
|
+
```javascript
|
|
258
|
+
// Navigate horizontal carousel
|
|
259
|
+
await testdriver.scroll('right', 300);
|
|
260
|
+
await new Promise(r => setTimeout(r, 500));
|
|
261
|
+
|
|
262
|
+
const nextImage = await testdriver.find('next image in carousel');
|
|
263
|
+
await nextImage.click();
|
|
264
|
+
```
|
|
265
|
+
</Accordion>
|
|
266
|
+
</AccordionGroup>
|
|
267
|
+
|
|
268
|
+
## Complete Example
|
|
269
|
+
|
|
270
|
+
```javascript
|
|
271
|
+
import { beforeAll, afterAll, describe, it } from 'vitest';
|
|
272
|
+
import TestDriver from 'testdriverai';
|
|
273
|
+
|
|
274
|
+
describe('Scrolling', () => {
|
|
275
|
+
let testdriver;
|
|
276
|
+
|
|
277
|
+
beforeAll(async () => {
|
|
278
|
+
client = new TestDriver(process.env.TD_API_KEY);
|
|
279
|
+
await testdriver.auth();
|
|
280
|
+
await testdriver.connect();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
afterAll(async () => {
|
|
284
|
+
await testdriver.disconnect();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('should scroll to find elements', async () => {
|
|
288
|
+
await testdriver.focusApplication('Google Chrome');
|
|
289
|
+
|
|
290
|
+
// Scroll to footer
|
|
291
|
+
await testdriver.scrollUntilText('Contact Information');
|
|
292
|
+
|
|
293
|
+
// Click footer link
|
|
294
|
+
const privacyLink = await testdriver.find('Privacy Policy link');
|
|
295
|
+
await privacyLink.click();
|
|
296
|
+
|
|
297
|
+
await testdriver.assert('privacy policy page is displayed');
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('should handle infinite scroll', async () => {
|
|
301
|
+
await testdriver.focusApplication('Google Chrome');
|
|
302
|
+
|
|
303
|
+
// Scroll multiple times to load content
|
|
304
|
+
for (let i = 0; i < 3; i++) {
|
|
305
|
+
await testdriver.scroll('down', 500);
|
|
306
|
+
await new Promise(r => setTimeout(r, 1500)); // Wait for load
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Verify content loaded
|
|
310
|
+
await testdriver.assert('more than 10 items are visible');
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('should scroll until loading completes', async () => {
|
|
314
|
+
// Scroll until loading spinner disappears
|
|
315
|
+
await testdriver.scrollUntilImage(
|
|
316
|
+
'loading spinner',
|
|
317
|
+
'down',
|
|
318
|
+
5000,
|
|
319
|
+
'keyboard',
|
|
320
|
+
null,
|
|
321
|
+
true // invert - wait for it to disappear
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
// Now interact with loaded content
|
|
325
|
+
const firstResult = await testdriver.find('first search result');
|
|
326
|
+
await firstResult.click();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Related Methods
|
|
332
|
+
|
|
333
|
+
- [`find()`](/v7/find) - Locate elements after scrolling
|
|
334
|
+
- [`pressKeys()`](/v7/press-keys) - Use Page Down/Up keys
|
|
335
|
+
- [`wait()`](/v7/wait) - Wait after scrolling
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testdriver:secrets
|
|
3
|
+
description: Securely manage passwords and sensitive data in your tests
|
|
4
|
+
---
|
|
5
|
+
<!-- Generated from secrets.mdx. DO NOT EDIT. -->
|
|
6
|
+
|
|
7
|
+
Protect sensitive information like passwords, API keys, and tokens in your TestDriver tests.
|
|
8
|
+
|
|
9
|
+
## Typing Secrets Securely
|
|
10
|
+
|
|
11
|
+
When typing sensitive information like passwords, use the `secret: true` option to prevent the value from being logged or stored:
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import { test } from 'vitest';
|
|
15
|
+
import { chrome } from 'testdriverai/presets';
|
|
16
|
+
|
|
17
|
+
test('login with secure password', async (context) => {
|
|
18
|
+
const { testdriver } = await chrome(context, {
|
|
19
|
+
url: 'https://myapp.com/login'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await testdriver.find('email input').click();
|
|
23
|
+
await testdriver.type(process.env.TD_USERNAME);
|
|
24
|
+
|
|
25
|
+
await testdriver.find('password input').click();
|
|
26
|
+
// Password is masked in logs and recordings
|
|
27
|
+
await testdriver.type(process.env.TD_PASSWORD, { secret: true });
|
|
28
|
+
|
|
29
|
+
await testdriver.find('login button').click();
|
|
30
|
+
await testdriver.assert('dashboard is visible');
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
<Note>
|
|
35
|
+
When `secret: true` is set, the typed text appears as `****` in all logs, recordings, and dashcam output.
|
|
36
|
+
</Note>
|
|
37
|
+
|
|
38
|
+
## Storing Secrets in GitHub
|
|
39
|
+
|
|
40
|
+
Store sensitive credentials as GitHub repository secrets so they're never exposed in your code:
|
|
41
|
+
|
|
42
|
+
<Steps>
|
|
43
|
+
<Step title="Navigate to Repository Settings">
|
|
44
|
+
Go to your GitHub repository → **Settings** → **Secrets and variables** → **Actions**
|
|
45
|
+
</Step>
|
|
46
|
+
<Step title="Add Repository Secrets">
|
|
47
|
+
Click **New repository secret** and add your secrets:
|
|
48
|
+
- `TD_API_KEY` - Your TestDriver API key
|
|
49
|
+
- `TD_USERNAME` - Test account username
|
|
50
|
+
- `TD_PASSWORD` - Test account password
|
|
51
|
+
</Step>
|
|
52
|
+
<Step title="Use in GitHub Actions">
|
|
53
|
+
Reference secrets in your workflow file:
|
|
54
|
+
```yaml .github/workflows/test.yml
|
|
55
|
+
- name: Run TestDriver tests
|
|
56
|
+
env:
|
|
57
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
58
|
+
TD_USERNAME: ${{ secrets.TD_USERNAME }}
|
|
59
|
+
TD_PASSWORD: ${{ secrets.TD_PASSWORD }}
|
|
60
|
+
run: vitest run
|
|
61
|
+
```
|
|
62
|
+
</Step>
|
|
63
|
+
</Steps>
|
|
64
|
+
|
|
65
|
+
## Local Development
|
|
66
|
+
|
|
67
|
+
For local development, store secrets in a `.env` file:
|
|
68
|
+
|
|
69
|
+
```bash .env
|
|
70
|
+
TD_API_KEY=your_api_key_here
|
|
71
|
+
TD_USERNAME=testuser@example.com
|
|
72
|
+
TD_PASSWORD=your_secure_password
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
<Warning>
|
|
76
|
+
Never commit `.env` files to version control. Add `.env` to your `.gitignore` file.
|
|
77
|
+
</Warning>
|
|
78
|
+
|
|
79
|
+
## Complete Example
|
|
80
|
+
|
|
81
|
+
Here's a full login test with proper secrets handling:
|
|
82
|
+
|
|
83
|
+
```javascript tests/login.test.js
|
|
84
|
+
import { test, expect } from 'vitest';
|
|
85
|
+
import { chrome } from 'testdriverai/presets';
|
|
86
|
+
|
|
87
|
+
test('secure login flow', async (context) => {
|
|
88
|
+
const { testdriver } = await chrome(context, {
|
|
89
|
+
url: process.env.TD_WEBSITE || 'https://staging.myapp.com'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Enter username (not sensitive)
|
|
93
|
+
await testdriver.find('email input').click();
|
|
94
|
+
await testdriver.type(process.env.TD_USERNAME);
|
|
95
|
+
|
|
96
|
+
// Enter password securely
|
|
97
|
+
await testdriver.find('password input').click();
|
|
98
|
+
await testdriver.type(process.env.TD_PASSWORD, { secret: true });
|
|
99
|
+
|
|
100
|
+
// Submit login
|
|
101
|
+
await testdriver.find('login button').click();
|
|
102
|
+
|
|
103
|
+
// Verify successful login
|
|
104
|
+
const loggedIn = await testdriver.assert('user is logged in');
|
|
105
|
+
expect(loggedIn).toBeTruthy();
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
<Card title="Secrets Best Practices" icon="shield-check">
|
|
110
|
+
- **Always use `secret: true`** when typing passwords, tokens, or sensitive data
|
|
111
|
+
- **Use environment variables** to keep secrets out of code
|
|
112
|
+
- **Store secrets in your CI provider** (GitHub Actions, GitLab CI, etc.)
|
|
113
|
+
- **Never commit secrets** to version control
|
|
114
|
+
- **Rotate secrets regularly** to maintain security
|
|
115
|
+
</Card>
|