testdriverai 7.2.9 → 7.2.11
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/workflows/testdriver.yml +127 -0
- package/.testdriver/last-sandbox +7 -0
- package/agent/events.js +1 -0
- package/agent/index.js +71 -54
- package/agent/lib/sandbox.js +11 -1
- package/agents.md +393 -0
- package/debug/01-table-initial.png +0 -0
- package/debug/02-after-ai-explore.png +0 -0
- package/debug/02-after-scroll.png +0 -0
- package/docs/docs.json +87 -126
- package/docs/v7/_drafts/caching.mdx +2 -2
- package/docs/v7/{getting-started → _drafts}/installation.mdx +0 -66
- package/docs/v7/{features/coverage.mdx → _drafts/powerful.mdx} +1 -90
- package/docs/v7/{features → _drafts}/scalable.mdx +126 -4
- package/docs/v7/_drafts/screenshot.mdx +155 -0
- package/docs/v7/_drafts/writing-tests.mdx +25 -0
- package/docs/v7/{api/act.mdx → ai.mdx} +27 -27
- package/docs/v7/{api/assert.mdx → assert.mdx} +3 -3
- package/docs/v7/aws-setup.mdx +338 -0
- package/docs/v7/caching.mdx +128 -0
- package/docs/v7/ci-cd.mdx +605 -0
- package/docs/v7/{api/click.mdx → click.mdx} +4 -4
- package/docs/v7/cloud.mdx +120 -0
- package/docs/v7/customizing-devices.mdx +129 -0
- package/docs/v7/{api/dashcam.mdx → dashcam.mdx} +0 -78
- package/docs/v7/{api/doubleClick.mdx → double-click.mdx} +5 -5
- package/docs/v7/{api/elements.mdx → elements.mdx} +1 -54
- package/docs/v7/enterprise.mdx +116 -0
- package/docs/v7/examples.mdx +5 -0
- package/docs/v7/{api/exec.mdx → exec.mdx} +3 -3
- package/docs/v7/{api/find.mdx → find.mdx} +17 -21
- package/docs/v7/{api/focusApplication.mdx → focus-application.mdx} +3 -3
- package/docs/v7/generating-tests.mdx +36 -0
- package/docs/v7/{api/hover.mdx → hover.mdx} +3 -3
- package/docs/v7/locating-elements.mdx +71 -0
- package/docs/v7/making-assertions.mdx +32 -0
- package/docs/v7/{api/mouseDown.mdx → mouse-down.mdx} +7 -7
- package/docs/v7/{api/mouseUp.mdx → mouse-up.mdx} +8 -8
- package/docs/v7/performing-actions.mdx +51 -0
- package/docs/v7/{api/pressKeys.mdx → press-keys.mdx} +3 -3
- package/docs/v7/quickstart.mdx +162 -0
- package/docs/v7/reusable-code.mdx +240 -0
- package/docs/v7/{api/rightClick.mdx → right-click.mdx} +5 -5
- package/docs/v7/running-tests.mdx +181 -0
- package/docs/v7/{api/scroll.mdx → scroll.mdx} +3 -3
- package/docs/v7/secrets.mdx +115 -0
- package/docs/v7/self-hosted.mdx +66 -0
- package/docs/v7/{api/type.mdx → type.mdx} +3 -3
- package/docs/v7/variables.mdx +111 -0
- package/docs/v7/waiting-for-elements.mdx +66 -0
- package/docs/v7/what-is-testdriver.mdx +54 -0
- package/lib/vitest/hooks.mjs +80 -68
- package/package.json +1 -1
- package/sdk.d.ts +22 -9
- package/sdk.js +177 -44
- package/test/manual/reconnect-provision.test.mjs +49 -0
- package/test/manual/reconnect-signin.test.mjs +41 -0
- package/test/testdriver/ai.test.mjs +30 -0
- package/test/testdriver/setup/testHelpers.mjs +0 -1
- package/test/testdriver/windows-installer.test.mjs +61 -0
- package/tests/table-sort-enrollments.test.mjs +72 -0
- package/tests/table-sort-experiment.test.mjs +42 -0
- package/tests/table-sort-setup.test.mjs +59 -0
- package/vitest.config.mjs +1 -0
- package/docs/v7/api/assertions.mdx +0 -403
- package/docs/v7/api/sandbox.mdx +0 -404
- package/docs/v7/features/ai-native.mdx +0 -413
- package/docs/v7/features/application-logs.mdx +0 -353
- package/docs/v7/features/browser-logs.mdx +0 -414
- package/docs/v7/features/cache-management.mdx +0 -402
- package/docs/v7/features/continuous-testing.mdx +0 -346
- package/docs/v7/features/data-driven-testing.mdx +0 -441
- package/docs/v7/features/easy-to-write.mdx +0 -280
- package/docs/v7/features/enterprise.mdx +0 -656
- package/docs/v7/features/fast.mdx +0 -406
- package/docs/v7/features/managed-sandboxes.mdx +0 -384
- package/docs/v7/features/network-monitoring.mdx +0 -568
- package/docs/v7/features/parallel-execution.mdx +0 -381
- package/docs/v7/features/powerful.mdx +0 -531
- package/docs/v7/features/sandbox-customization.mdx +0 -229
- package/docs/v7/features/stable.mdx +0 -473
- package/docs/v7/features/system-performance.mdx +0 -616
- package/docs/v7/features/test-analytics.mdx +0 -373
- package/docs/v7/features/test-cases.mdx +0 -393
- package/docs/v7/features/test-replays.mdx +0 -408
- package/docs/v7/features/test-reports.mdx +0 -308
- package/docs/v7/getting-started/debugging-tests.mdx +0 -382
- package/docs/v7/getting-started/quickstart.mdx +0 -90
- package/docs/v7/getting-started/running-tests.mdx +0 -173
- package/docs/v7/getting-started/setting-up-in-ci.mdx +0 -612
- package/docs/v7/getting-started/writing-tests.mdx +0 -534
- package/docs/v7/overview/what-is-testdriver.mdx +0 -386
- package/docs/v7/presets/chrome-extension.mdx +0 -248
- package/docs/v7/presets/chrome.mdx +0 -300
- package/docs/v7/presets/electron.mdx +0 -460
- package/docs/v7/presets/vscode.mdx +0 -417
- package/docs/v7/presets/webapp.mdx +0 -393
- package/vitest.config.js +0 -18
- /package/docs/v7/{commands → _drafts/commands}/assert.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/exec.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/focus-application.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/hover-image.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/hover-text.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/if.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/match-image.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/press-keys.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/remember.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/run.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/scroll-until-image.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/scroll-until-text.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/scroll.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/type.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/wait-for-image.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/wait-for-text.mdx +0 -0
- /package/docs/v7/{commands → _drafts/commands}/wait.mdx +0 -0
- /package/docs/v7/{getting-started → _drafts}/configuration.mdx +0 -0
- /package/docs/v7/{features → _drafts}/observable.mdx +0 -0
- /package/docs/v7/{platforms → _drafts/platforms}/linux.mdx +0 -0
- /package/docs/v7/{platforms → _drafts/platforms}/macos.mdx +0 -0
- /package/docs/v7/{platforms → _drafts/platforms}/windows.mdx +0 -0
- /package/docs/v7/{playwright.mdx → _drafts/playwright.mdx} +0 -0
- /package/docs/v7/{overview → _drafts}/readme.mdx +0 -0
- /package/docs/v7/{features → _drafts}/reports.mdx +0 -0
- /package/docs/v7/{api/client.mdx → client.mdx} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Locating Elements"
|
|
3
|
+
description: "Find UI elements using natural language descriptions"
|
|
4
|
+
icon: "crosshairs"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Locating Single Elements
|
|
8
|
+
|
|
9
|
+
Use natural language to describe elements. Descriptions should be specific enough to locate the element, but not too-specific that they break with minor UI changes. For example:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
await testdriver.find('email input field');
|
|
13
|
+
await testdriver.find('first product card in the grid');
|
|
14
|
+
await testdriver.find('dropdown menu labeled "Country"');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
<Info>TestDriver will cache found elements for improved performance on subsequent calls. Learn more about [element caching here](/v7/caching).</Info>
|
|
18
|
+
|
|
19
|
+
## Debugging Found Elements
|
|
20
|
+
|
|
21
|
+
After finding an element, you can inspect its properties for debugging:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
const button = await testdriver.find('submit button');
|
|
25
|
+
console.log(button);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This outputs all element properties:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
{
|
|
32
|
+
description: 'submit button',
|
|
33
|
+
found: true,
|
|
34
|
+
x: 150,
|
|
35
|
+
y: 300,
|
|
36
|
+
coordinates: { x: 150, y: 300, centerX: 200, centerY: 320 },
|
|
37
|
+
threshold: 0.8,
|
|
38
|
+
confidence: 0.95,
|
|
39
|
+
similarity: 0.92,
|
|
40
|
+
selector: 'button[type="submit"]',
|
|
41
|
+
cache: {
|
|
42
|
+
hit: true,
|
|
43
|
+
strategy: 'pixel-diff',
|
|
44
|
+
createdAt: '2025-01-15T10:30:00Z',
|
|
45
|
+
diffPercent: 0.02,
|
|
46
|
+
imageUrl: 'https://...'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Working with Multiple Elements
|
|
52
|
+
|
|
53
|
+
Find and interact with multiple elements:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// Find all matching elements
|
|
57
|
+
const products = await testdriver.findAll('product card');
|
|
58
|
+
console.log(`Found ${products.length} products`);
|
|
59
|
+
|
|
60
|
+
// Interact with each
|
|
61
|
+
for (const product of products) {
|
|
62
|
+
const title = await product.find('title text');
|
|
63
|
+
console.log('Product:', title.text);
|
|
64
|
+
|
|
65
|
+
await product.find('add to cart button').click();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Or find specific element
|
|
69
|
+
const firstProduct = products[0];
|
|
70
|
+
await firstProduct.click();
|
|
71
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Making Assertions"
|
|
3
|
+
description: "Verify application state with AI-powered assertions"
|
|
4
|
+
icon: "check-double"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Making Assertions
|
|
8
|
+
|
|
9
|
+
Use AI-powered assertions to verify application state:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// Verify visibility
|
|
13
|
+
await testdriver.assert('login page is displayed');
|
|
14
|
+
await testdriver.assert('submit button is visible');
|
|
15
|
+
await testdriver.assert('loading spinner is not visible');
|
|
16
|
+
|
|
17
|
+
// Verify content
|
|
18
|
+
await testdriver.assert('page title is "Welcome"');
|
|
19
|
+
await testdriver.assert('success message says "Account created"');
|
|
20
|
+
await testdriver.assert('error message contains "Invalid email"');
|
|
21
|
+
|
|
22
|
+
// Verify state
|
|
23
|
+
await testdriver.assert('checkbox is checked');
|
|
24
|
+
await testdriver.assert('dropdown shows "United States"');
|
|
25
|
+
await testdriver.assert('button is disabled');
|
|
26
|
+
|
|
27
|
+
// Verify visual appearance
|
|
28
|
+
await testdriver.assert('submit button is blue');
|
|
29
|
+
await testdriver.assert('form has red border');
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
<Info>Assertions are not cached and always re-evaluated to ensure accuracy.</Info>
|
|
@@ -147,15 +147,15 @@ test('resizes panel', async () => {
|
|
|
147
147
|
|
|
148
148
|
## Important Notes
|
|
149
149
|
|
|
150
|
-
- Always pair `mouseDown()` with [`mouseUp()`](/v7/
|
|
150
|
+
- Always pair `mouseDown()` with [`mouseUp()`](/v7/mouse-up) to complete the gesture
|
|
151
151
|
- The mouse button remains pressed until `mouseUp()` is called
|
|
152
|
-
- Use [`hover()`](/v7/
|
|
152
|
+
- Use [`hover()`](/v7/hover) to move the mouse while the button is pressed
|
|
153
153
|
- For simple drag operations, consider using `ai()` with a natural language description like `"drag file to folder"`
|
|
154
154
|
|
|
155
155
|
## Related Methods
|
|
156
156
|
|
|
157
|
-
- [`mouseUp()`](/v7/
|
|
158
|
-
- [`hover()`](/v7/
|
|
159
|
-
- [`click()`](/v7/
|
|
160
|
-
- [`doubleClick()`](/v7/
|
|
161
|
-
- [`rightClick()`](/v7/
|
|
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
|
|
@@ -6,7 +6,7 @@ icon: "arrow-pointer"
|
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
9
|
-
The `mouseUp()` method releases the mouse button, completing a drag operation or custom mouse gesture that was started with [`mouseDown()`](/v7/
|
|
9
|
+
The `mouseUp()` method releases the mouse button, completing a drag operation or custom mouse gesture that was started with [`mouseDown()`](/v7/mouse-down). You can call it without parameters to release at the current mouse position.
|
|
10
10
|
|
|
11
11
|
## Syntax
|
|
12
12
|
|
|
@@ -150,15 +150,15 @@ test('selects text with mouse drag', async () => {
|
|
|
150
150
|
|
|
151
151
|
## Important Notes
|
|
152
152
|
|
|
153
|
-
- `mouseUp()` must be preceded by [`mouseDown()`](/v7/
|
|
153
|
+
- `mouseUp()` must be preceded by [`mouseDown()`](/v7/mouse-down) to have an effect
|
|
154
154
|
- Releases the button at the current cursor position
|
|
155
155
|
- Completes any drag or selection operation that was in progress
|
|
156
|
-
- For simple clicks, use [`click()`](/v7/
|
|
156
|
+
- For simple clicks, use [`click()`](/v7/click) instead of mouseDown/mouseUp pair
|
|
157
157
|
|
|
158
158
|
## Related Methods
|
|
159
159
|
|
|
160
|
-
- [`mouseDown()`](/v7/
|
|
161
|
-
- [`hover()`](/v7/
|
|
162
|
-
- [`click()`](/v7/
|
|
163
|
-
- [`doubleClick()`](/v7/
|
|
164
|
-
- [`rightClick()`](/v7/
|
|
160
|
+
- [`mouseDown()`](/v7/mouse-down) - Press mouse button without releasing
|
|
161
|
+
- [`hover()`](/v7/hover) - Move mouse to element
|
|
162
|
+
- [`click()`](/v7/click) - Complete click (mouseDown + mouseUp)
|
|
163
|
+
- [`doubleClick()`](/v7/double-click) - Double-click on element
|
|
164
|
+
- [`rightClick()`](/v7/right-click) - Right-click for context menu
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Performing Actions"
|
|
3
|
+
description: "Click, type, hover, scroll and more with TestDriver"
|
|
4
|
+
icon: "computer-mouse"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Performing Actions
|
|
8
|
+
|
|
9
|
+
TestDriver provides a variety of actions you can perform, like [clicking](/v7/click), [typing](/v7/type), [hovering](/v7/hover), and [scrolling](/v7/scroll). For a full list, see the [API Reference](/v7/click).
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// Clicking
|
|
13
|
+
await testdriver.find('submit button').click();
|
|
14
|
+
await testdriver.find('file item').doubleClick();
|
|
15
|
+
await testdriver.find('text area').rightClick();
|
|
16
|
+
|
|
17
|
+
// Typing
|
|
18
|
+
await testdriver.find('email input').type('user@example.com');
|
|
19
|
+
await testdriver.find('password input').type('secret', { secret: true });
|
|
20
|
+
|
|
21
|
+
// Keyboard shortcuts
|
|
22
|
+
await testdriver.pressKeys(['enter']);
|
|
23
|
+
await testdriver.pressKeys(['ctrl', 'c']);
|
|
24
|
+
|
|
25
|
+
// Hovering
|
|
26
|
+
await testdriver.find('dropdown menu').hover();
|
|
27
|
+
|
|
28
|
+
// Scrolling
|
|
29
|
+
await testdriver.scroll('down', 500);
|
|
30
|
+
await testdriver.scrollUntilText('Footer content');
|
|
31
|
+
|
|
32
|
+
// Extracting information from screen
|
|
33
|
+
const price = await testdriver.extract('the total price');
|
|
34
|
+
const orderNumber = await testdriver.extract('the order confirmation number');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Chaining Actions
|
|
38
|
+
|
|
39
|
+
TestDriver supports method chaining for cleaner code:
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
// Chain find() with actions
|
|
43
|
+
const button = await testdriver.find('submit button').click();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or save element reference for later use:
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const button = await testdriver.find('submit button');
|
|
50
|
+
await button.click();
|
|
51
|
+
```
|
|
@@ -344,6 +344,6 @@ describe('Keyboard Navigation', () => {
|
|
|
344
344
|
|
|
345
345
|
## Related Methods
|
|
346
346
|
|
|
347
|
-
- [`type()`](/v7/
|
|
348
|
-
- [`click()`](/v7/
|
|
349
|
-
- [`scroll()`](/v7/
|
|
347
|
+
- [`type()`](/v7/type) - Type text
|
|
348
|
+
- [`click()`](/v7/click) - Click elements
|
|
349
|
+
- [`scroll()`](/v7/scroll) - Scroll pages
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Quick Start"
|
|
3
|
+
sidebarTitle: "Quickstart"
|
|
4
|
+
description: "Run your first computer-use test in minutes."
|
|
5
|
+
icon: "rocket"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
TestDriver makes it easy to write automated computer-use tests for web browsers, desktop apps, and more. Follow the directions below to run your first TestDriver test.
|
|
9
|
+
|
|
10
|
+
<Tip><a href="https://discord.com/invite/cWDFW8DzPm" target="_blank" rel="noreferrer">Join our Discord</a> if you have any questions or need help getting started!</Tip>
|
|
11
|
+
|
|
12
|
+
<Tabs>
|
|
13
|
+
<Tab title="Automatic Setup">
|
|
14
|
+
|
|
15
|
+
Get started quickly with the TestDriver CLI.
|
|
16
|
+
|
|
17
|
+
<Steps>
|
|
18
|
+
<Step title="Create a TestDriver Account">
|
|
19
|
+
|
|
20
|
+
You will need a TestDriver account to get an API key.
|
|
21
|
+
|
|
22
|
+
<Card
|
|
23
|
+
title="Sign Up for TestDriver"
|
|
24
|
+
icon="user-plus"
|
|
25
|
+
href="https://app.testdriver.ai/team"
|
|
26
|
+
arrow
|
|
27
|
+
horizontal
|
|
28
|
+
>
|
|
29
|
+
No credit-card required!
|
|
30
|
+
</Card>
|
|
31
|
+
|
|
32
|
+
</Step>
|
|
33
|
+
<Step title="Install TestDriver">
|
|
34
|
+
|
|
35
|
+
Use `npx` to quickly set up an example project:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx testdriverai@beta init
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This will walk you through creating a new project folder, installing dependencies, and setting up your API key.
|
|
42
|
+
|
|
43
|
+
</Step>
|
|
44
|
+
|
|
45
|
+
<Step title="Run Your Test">
|
|
46
|
+
|
|
47
|
+
TestDriver uses Vitest as the test runner. To run your test, use:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
vitest run
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This will spawn a sandbox, launch Chrome, and run the example test!
|
|
54
|
+
|
|
55
|
+
</Step>
|
|
56
|
+
</Steps>
|
|
57
|
+
</Tab>
|
|
58
|
+
<Tab title="Manual Setup">
|
|
59
|
+
|
|
60
|
+
Install TestDriver and manually create the files yourself.
|
|
61
|
+
|
|
62
|
+
<Steps>
|
|
63
|
+
<Step title="Create a TestDriver Account">
|
|
64
|
+
|
|
65
|
+
You will need a TestDriver account to get an API key.
|
|
66
|
+
|
|
67
|
+
<Card
|
|
68
|
+
title="Sign Up for TestDriver"
|
|
69
|
+
icon="user-plus"
|
|
70
|
+
href="https://app.testdriver.ai/team"
|
|
71
|
+
arrow
|
|
72
|
+
horizontal
|
|
73
|
+
>
|
|
74
|
+
No credit-card required!
|
|
75
|
+
</Card>
|
|
76
|
+
|
|
77
|
+
</Step>
|
|
78
|
+
<Step title="Install Dependencies">
|
|
79
|
+
|
|
80
|
+
Install Vitest and TestDriver as dev dependencies:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install --save-dev vitest testdriverai@beta
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
</Step>
|
|
87
|
+
<Step title="Create a vitest.config.js File">
|
|
88
|
+
|
|
89
|
+
In your project root, create a `vitest.config.js` file with the following content:
|
|
90
|
+
|
|
91
|
+
```js vitest.config.js
|
|
92
|
+
import TestDriver from 'testdriverai/vitest';
|
|
93
|
+
import { defineConfig } from 'vitest/config';
|
|
94
|
+
|
|
95
|
+
export default defineConfig({
|
|
96
|
+
test: {
|
|
97
|
+
testTimeout: 900000,
|
|
98
|
+
hookTimeout: 900000,
|
|
99
|
+
disableConsoleIntercept: true,
|
|
100
|
+
maxConcurrency: 1, // this should match your plan's concurrency limit
|
|
101
|
+
reporters: [
|
|
102
|
+
'default',
|
|
103
|
+
TestDriver()
|
|
104
|
+
],
|
|
105
|
+
setupFiles: ['testdriverai/vitest/setup'],
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
</Step>
|
|
111
|
+
<Step title="Create an Example Test File">
|
|
112
|
+
|
|
113
|
+
Add your API key to the example test file below and save it as `test.mjs` in your project root.
|
|
114
|
+
|
|
115
|
+
```js test.mjs highlight={9}
|
|
116
|
+
import { describe, expect, it } from "vitest";
|
|
117
|
+
// Import TestDriver from the vitest hooks
|
|
118
|
+
import { TestDriver } from "testdriverai/vitest/hooks";
|
|
119
|
+
|
|
120
|
+
describe("Google Search Example", () => {
|
|
121
|
+
it("should search for TestDriver", async (context) => {
|
|
122
|
+
// Create TestDriver instance - automatically connects to sandbox
|
|
123
|
+
const testdriver = TestDriver(context, {
|
|
124
|
+
apiKey: 'YOUR_API_KEY_HERE' // supply your API key here
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Provision Chrome browser with a URL
|
|
128
|
+
// This also starts dashcam recording automatically
|
|
129
|
+
await testdriver.provision.chrome({ url: "https://duckduckgo.com" });
|
|
130
|
+
|
|
131
|
+
// Find and interact with elements using natural language
|
|
132
|
+
const searchBox = await testdriver.find("DuckDuckGo search input field");
|
|
133
|
+
await searchBox.click();
|
|
134
|
+
|
|
135
|
+
// Type into the focused element
|
|
136
|
+
await testdriver.type("testdriver.ai");
|
|
137
|
+
|
|
138
|
+
// Press Enter to search
|
|
139
|
+
await testdriver.pressKeys(["enter"]);
|
|
140
|
+
|
|
141
|
+
// Assert something is visible on the page
|
|
142
|
+
const result = await testdriver.assert("search results are displayed");
|
|
143
|
+
expect(result).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
</Step>
|
|
149
|
+
<Step title="Run Your Test">
|
|
150
|
+
|
|
151
|
+
TestDriver uses Vitest as the test runner. To run your test, use:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
vitest run
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
This will spawn a sandbox, launch Chrome, and run the example test!
|
|
158
|
+
|
|
159
|
+
</Step>
|
|
160
|
+
</Steps>
|
|
161
|
+
</Tab>
|
|
162
|
+
</Tabs>
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reusable Code Snippets"
|
|
3
|
+
description: "Build maintainable test suites with reusable code patterns"
|
|
4
|
+
icon: "recycle"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
As your test suite grows, you'll want to extract common patterns into reusable code. This keeps tests DRY, readable, and easy to maintain.
|
|
8
|
+
|
|
9
|
+
## Helper Functions
|
|
10
|
+
|
|
11
|
+
The simplest approach is extracting common actions into helper functions. Create a `helpers/` directory for shared utilities:
|
|
12
|
+
|
|
13
|
+
```javascript test/helpers/auth.js
|
|
14
|
+
export async function login(testdriver, { email, password }) {
|
|
15
|
+
const emailInput = await testdriver.find('email input');
|
|
16
|
+
await emailInput.click();
|
|
17
|
+
await testdriver.type(email);
|
|
18
|
+
|
|
19
|
+
const passwordInput = await testdriver.find('password input');
|
|
20
|
+
await passwordInput.click();
|
|
21
|
+
await testdriver.type(password);
|
|
22
|
+
|
|
23
|
+
const loginButton = await testdriver.find('login button');
|
|
24
|
+
await loginButton.click();
|
|
25
|
+
|
|
26
|
+
const result = await testdriver.assert('user is logged in');
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function logout(testdriver) {
|
|
31
|
+
const userMenu = await testdriver.find('user menu');
|
|
32
|
+
await userMenu.click();
|
|
33
|
+
|
|
34
|
+
const logoutButton = await testdriver.find('logout button');
|
|
35
|
+
await logoutButton.click();
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Now import and use these helpers in any test:
|
|
40
|
+
|
|
41
|
+
```javascript test/checkout.test.mjs
|
|
42
|
+
import { describe, expect, it } from "vitest";
|
|
43
|
+
import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
|
|
44
|
+
import { login } from './helpers/auth.js';
|
|
45
|
+
|
|
46
|
+
describe("Checkout", () => {
|
|
47
|
+
it("should complete checkout as logged in user", async (context) => {
|
|
48
|
+
const testdriver = TestDriver(context, { newSandbox: true });
|
|
49
|
+
|
|
50
|
+
await testdriver.provision.chrome({
|
|
51
|
+
url: 'https://shop.example.com',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Use the helper
|
|
55
|
+
await login(testdriver, {
|
|
56
|
+
email: 'user@example.com',
|
|
57
|
+
password: 'password123'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Continue with checkout steps...
|
|
61
|
+
const cartButton = await testdriver.find('cart button');
|
|
62
|
+
await cartButton.click();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Page Objects
|
|
68
|
+
|
|
69
|
+
For larger test suites, the Page Object pattern encapsulates all interactions with a specific page or component:
|
|
70
|
+
|
|
71
|
+
```javascript test/pages/LoginPage.js
|
|
72
|
+
export class LoginPage {
|
|
73
|
+
constructor(testdriver) {
|
|
74
|
+
this.td = testdriver;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async enterEmail(email) {
|
|
78
|
+
const input = await this.td.find('email input');
|
|
79
|
+
await input.click();
|
|
80
|
+
await this.td.type(email);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async enterPassword(password) {
|
|
84
|
+
const input = await this.td.find('password input');
|
|
85
|
+
await input.click();
|
|
86
|
+
await this.td.type(password);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async submit() {
|
|
90
|
+
const button = await this.td.find('submit button');
|
|
91
|
+
await button.click();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async login(email, password) {
|
|
95
|
+
await this.enterEmail(email);
|
|
96
|
+
await this.enterPassword(password);
|
|
97
|
+
await this.submit();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async assertError(message) {
|
|
101
|
+
return await this.td.assert(`error message shows "${message}"`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async assertLoggedIn() {
|
|
105
|
+
return await this.td.assert('user dashboard is visible');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use the page object in your tests:
|
|
111
|
+
|
|
112
|
+
```javascript test/auth.test.mjs
|
|
113
|
+
import { describe, expect, it } from "vitest";
|
|
114
|
+
import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
|
|
115
|
+
import { LoginPage } from './pages/LoginPage.js';
|
|
116
|
+
|
|
117
|
+
describe("Authentication", () => {
|
|
118
|
+
it("should show error for invalid credentials", async (context) => {
|
|
119
|
+
const testdriver = TestDriver(context, { newSandbox: true });
|
|
120
|
+
|
|
121
|
+
await testdriver.provision.chrome({
|
|
122
|
+
url: 'https://app.example.com/login',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const loginPage = new LoginPage(testdriver);
|
|
126
|
+
|
|
127
|
+
await loginPage.login('invalid@test.com', 'wrongpassword');
|
|
128
|
+
|
|
129
|
+
const hasError = await loginPage.assertError('Invalid credentials');
|
|
130
|
+
expect(hasError).toBeTruthy();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should redirect to dashboard on success", async (context) => {
|
|
134
|
+
const testdriver = TestDriver(context, { newSandbox: true });
|
|
135
|
+
|
|
136
|
+
await testdriver.provision.chrome({
|
|
137
|
+
url: 'https://app.example.com/login',
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const loginPage = new LoginPage(testdriver);
|
|
141
|
+
|
|
142
|
+
await loginPage.login('valid@test.com', 'correctpassword');
|
|
143
|
+
|
|
144
|
+
const isLoggedIn = await loginPage.assertLoggedIn();
|
|
145
|
+
expect(isLoggedIn).toBeTruthy();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Shared Test Fixtures
|
|
151
|
+
|
|
152
|
+
Create reusable fixtures for common test setup scenarios:
|
|
153
|
+
|
|
154
|
+
```javascript test/fixtures/index.js
|
|
155
|
+
export const testUsers = {
|
|
156
|
+
admin: { email: 'admin@example.com', password: 'admin123' },
|
|
157
|
+
regular: { email: 'user@example.com', password: 'user123' },
|
|
158
|
+
guest: { email: 'guest@example.com', password: 'guest123' },
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const testUrls = {
|
|
162
|
+
staging: 'https://staging.example.com',
|
|
163
|
+
production: 'https://example.com',
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export async function setupAuthenticatedSession(testdriver, user = testUsers.regular) {
|
|
167
|
+
const emailInput = await testdriver.find('email input');
|
|
168
|
+
await emailInput.click();
|
|
169
|
+
await testdriver.type(user.email);
|
|
170
|
+
|
|
171
|
+
const passwordInput = await testdriver.find('password input');
|
|
172
|
+
await passwordInput.click();
|
|
173
|
+
await testdriver.type(user.password);
|
|
174
|
+
|
|
175
|
+
const loginButton = await testdriver.find('login button');
|
|
176
|
+
await loginButton.click();
|
|
177
|
+
|
|
178
|
+
await testdriver.assert('user is logged in');
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```javascript test/admin.test.mjs
|
|
183
|
+
import { describe, expect, it } from "vitest";
|
|
184
|
+
import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
|
|
185
|
+
import { testUsers, testUrls, setupAuthenticatedSession } from './fixtures/index.js';
|
|
186
|
+
|
|
187
|
+
describe("Admin Panel", () => {
|
|
188
|
+
it("should access admin settings", async (context) => {
|
|
189
|
+
const testdriver = TestDriver(context, { newSandbox: true });
|
|
190
|
+
|
|
191
|
+
await testdriver.provision.chrome({
|
|
192
|
+
url: `${testUrls.staging}/login`,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await setupAuthenticatedSession(testdriver, testUsers.admin);
|
|
196
|
+
|
|
197
|
+
const settingsLink = await testdriver.find('admin settings link');
|
|
198
|
+
await settingsLink.click();
|
|
199
|
+
|
|
200
|
+
const result = await testdriver.assert('admin settings panel is visible');
|
|
201
|
+
expect(result).toBeTruthy();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Suggested Project Structure
|
|
207
|
+
|
|
208
|
+
<FileTree>
|
|
209
|
+
<Folder name="test" defaultOpen>
|
|
210
|
+
<Folder name="fixtures" defaultOpen>
|
|
211
|
+
<File name="index.js" />
|
|
212
|
+
</Folder>
|
|
213
|
+
<Folder name="helpers" defaultOpen>
|
|
214
|
+
<File name="auth.js" />
|
|
215
|
+
<File name="navigation.js" />
|
|
216
|
+
<File name="forms.js" />
|
|
217
|
+
</Folder>
|
|
218
|
+
<Folder name="pages" defaultOpen>
|
|
219
|
+
<File name="LoginPage.js" />
|
|
220
|
+
<File name="DashboardPage.js" />
|
|
221
|
+
<File name="CheckoutPage.js" />
|
|
222
|
+
</Folder>
|
|
223
|
+
<Folder name="specs" defaultOpen>
|
|
224
|
+
<File name="auth.test.mjs" />
|
|
225
|
+
<File name="checkout.test.mjs" />
|
|
226
|
+
<File name="search.test.mjs" />
|
|
227
|
+
</Folder>
|
|
228
|
+
</Folder>
|
|
229
|
+
</FileTree>
|
|
230
|
+
|
|
231
|
+
| Folder | Purpose |
|
|
232
|
+
|--------|---------|
|
|
233
|
+
| `fixtures/` | Test data and setup utilities |
|
|
234
|
+
| `helpers/` | Reusable helper functions |
|
|
235
|
+
| `pages/` | Page object classes |
|
|
236
|
+
| `specs/` | Test files |
|
|
237
|
+
|
|
238
|
+
<Tip>
|
|
239
|
+
Start simple with helper functions. Only introduce page objects when you find yourself duplicating the same element interactions across multiple tests.
|
|
240
|
+
</Tip>
|
|
@@ -116,8 +116,8 @@ test('uses custom context menu', async () => {
|
|
|
116
116
|
|
|
117
117
|
## Related Methods
|
|
118
118
|
|
|
119
|
-
- [`click()`](/v7/
|
|
120
|
-
- [`doubleClick()`](/v7/
|
|
121
|
-
- [`mouseDown()`](/v7/
|
|
122
|
-
- [`mouseUp()`](/v7/
|
|
123
|
-
- [`hover()`](/v7/
|
|
119
|
+
- [`click()`](/v7/click) - Single click on an element
|
|
120
|
+
- [`doubleClick()`](/v7/double-click) - Double-click on an element
|
|
121
|
+
- [`mouseDown()`](/v7/mouse-down) - Press mouse button without releasing
|
|
122
|
+
- [`mouseUp()`](/v7/mouse-up) - Release mouse button
|
|
123
|
+
- [`hover()`](/v7/hover) - Move mouse over element without clicking
|