testdriverai 7.2.3 → 7.2.10
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/publish.yaml +15 -7
- package/.github/workflows/testdriver.yml +163 -0
- package/.testdriver/last-sandbox +7 -0
- package/agent/events.js +1 -0
- package/agent/index.js +99 -163
- package/agent/lib/sandbox.js +11 -1
- package/agents.md +393 -0
- package/bin/testdriverai.js +8 -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/debugger/index.html +37 -0
- package/docs/docs.json +93 -125
- package/docs/v7/_drafts/architecture.mdx +1 -26
- 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/_drafts/quick-start-test-recording.mdx +0 -1
- package/docs/v7/{features → _drafts}/scalable.mdx +126 -4
- package/docs/v7/_drafts/screenshot.mdx +155 -0
- package/docs/v7/_drafts/test-recording.mdx +0 -6
- package/docs/v7/_drafts/writing-tests.mdx +25 -0
- package/docs/v7/{api/act.mdx → ai.mdx} +28 -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/doubleClick.mdx → double-click.mdx} +5 -5
- package/docs/v7/enterprise.mdx +135 -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 +32 -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/interfaces/cli/commands/init.js +33 -19
- package/interfaces/cli/lib/base.js +24 -0
- package/interfaces/cli.js +8 -1
- package/interfaces/logger.js +8 -3
- package/interfaces/vitest-plugin.mjs +16 -71
- package/lib/sentry.js +343 -0
- package/lib/vitest/hooks.mjs +81 -81
- package/package.json +4 -3
- package/sdk-log-formatter.js +41 -0
- package/sdk.d.ts +22 -9
- package/sdk.js +344 -100
- package/test/manual/reconnect-provision.test.mjs +49 -0
- package/test/manual/reconnect-signin.test.mjs +41 -0
- package/test/testdriver/act.test.mjs +30 -0
- package/test/testdriver/ai.test.mjs +30 -0
- package/test/testdriver/assert.test.mjs +1 -1
- package/test/testdriver/hover-text.test.mjs +1 -1
- package/test/testdriver/setup/testHelpers.mjs +8 -119
- package/test/testdriver/windows-installer.test.mjs +61 -0
- package/tests/example.test.js +33 -0
- package/tests/login.js +28 -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 +3 -1
- package/agent/lib/cache.js +0 -142
- package/docs/v7/api/assertions.mdx +0 -403
- 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/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
- /package/docs/v7/{api/dashcam.mdx → dashcam.mdx} +0 -0
- /package/docs/v7/{api/elements.mdx → elements.mdx} +0 -0
- /package/docs/v7/{api/sandbox.mdx → sandbox.mdx} +0 -0
|
@@ -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
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Running Tests"
|
|
3
|
+
description: "Run TestDriver tests with Vitest test runner"
|
|
4
|
+
icon: "play"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Learn how to run TestDriver tests efficiently with Vitest's powerful test runner.
|
|
8
|
+
|
|
9
|
+
## Running Tests
|
|
10
|
+
|
|
11
|
+
TestDriver works with Vitest's powerful test runner.
|
|
12
|
+
|
|
13
|
+
### Run All Tests
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx vitest run
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Executes all test files in your project once and exits. Vitest automatically discovers files matching patterns like `*.test.js`, `*.test.mjs`, or `*.spec.js`.
|
|
20
|
+
|
|
21
|
+
### Run with Coverage
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx vitest run --coverage
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Generates a code coverage report showing which lines of your source code were executed during tests. Coverage helps identify untested code paths. Results are displayed in the terminal and saved to a `coverage/` directory.
|
|
28
|
+
|
|
29
|
+
<Info>
|
|
30
|
+
Coverage requires the `@vitest/coverage-v8` package. Install it with `npm install -D @vitest/coverage-v8`.
|
|
31
|
+
</Info>
|
|
32
|
+
|
|
33
|
+
### Run Specific Tests
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx vitest run login.test.js
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Runs only the specified test file. Useful when debugging a single test or working on a specific feature.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx vitest run login.test.js checkout.test.js
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Runs multiple specific test files. List as many files as needed, separated by spaces.
|
|
46
|
+
|
|
47
|
+
### Filter Tests by Name
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx vitest run --grep "login"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The `--grep` flag filters tests by their name (the string passed to `it()` or `test()`). Only tests whose names match the pattern will run. Supports regex patterns for complex matching.
|
|
54
|
+
|
|
55
|
+
### Run Tests in a Folder
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx vitest run tests/e2e/
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Runs all test files within a specific directory. Great for organizing tests by type (unit, integration, e2e) and running them separately.
|
|
62
|
+
|
|
63
|
+
## Parallel Execution
|
|
64
|
+
|
|
65
|
+
TestDriver runs each test in its own cloud sandbox, enabling true parallel execution. Run your entire test suite in minutes instead of hours.
|
|
66
|
+
|
|
67
|
+
### Control Concurrency
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx vitest run --maxConcurrency=5
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The `--maxConcurrency` flag limits how many tests run simultaneously. This should match your TestDriver license slots to avoid failures from exhausted slots.
|
|
74
|
+
|
|
75
|
+
### Thread Configuration
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npx vitest run --pool=threads --minThreads=2 --maxThreads=8
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Fine-tune thread allocation for optimal performance:
|
|
82
|
+
- `--pool=threads` — Uses worker threads for test isolation
|
|
83
|
+
- `--minThreads` — Minimum number of threads to keep alive (reduces startup overhead)
|
|
84
|
+
- `--maxThreads` — Maximum threads to spawn (limits resource usage)
|
|
85
|
+
|
|
86
|
+
### License Slots
|
|
87
|
+
|
|
88
|
+
Your TestDriver plan includes a set number of **license slots** that determine how many tests can run simultaneously. Each running test occupies one slot—when the test completes and the sandbox is destroyed, the slot is immediately available for the next test.
|
|
89
|
+
|
|
90
|
+
<Info>
|
|
91
|
+
View your available slots at [console.testdriver.ai](https://console.testdriver.ai). Upgrade anytime to increase parallelization.
|
|
92
|
+
</Info>
|
|
93
|
+
|
|
94
|
+
### Configuring Concurrency
|
|
95
|
+
|
|
96
|
+
Set `maxConcurrency` in your Vitest config to match your license slot limit:
|
|
97
|
+
|
|
98
|
+
```javascript vitest.config.mjs
|
|
99
|
+
import { defineConfig } from 'vitest/config';
|
|
100
|
+
import { TestDriver } from 'testdriverai/vitest';
|
|
101
|
+
|
|
102
|
+
export default defineConfig({
|
|
103
|
+
test: {
|
|
104
|
+
testTimeout: 900000,
|
|
105
|
+
hookTimeout: 900000,
|
|
106
|
+
maxConcurrency: 5, // Match your license slot limit
|
|
107
|
+
reporters: ['default', TestDriver()],
|
|
108
|
+
setupFiles: ['testdriverai/vitest/setup'],
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
<Warning>
|
|
114
|
+
Setting `maxConcurrency` higher than your license slots will cause tests to fail when slots are exhausted. Always match this value to your plan's limit.
|
|
115
|
+
</Warning>
|
|
116
|
+
|
|
117
|
+
### Why Parallelization Matters
|
|
118
|
+
|
|
119
|
+
| Test Suite | Sequential (1 slot) | Parallel (5 slots) | Parallel (10 slots) |
|
|
120
|
+
|------------|--------------------|--------------------|---------------------|
|
|
121
|
+
| 10 tests @ 2min each | 20 min | 4 min | 2 min |
|
|
122
|
+
| 50 tests @ 2min each | 100 min | 20 min | 10 min |
|
|
123
|
+
| 100 tests @ 2min each | 200 min | 40 min | 20 min |
|
|
124
|
+
|
|
125
|
+
<Tip>
|
|
126
|
+
**Pro tip:** Upgrading your plan doesn't just increase speed—it enables faster CI/CD feedback loops, letting your team ship with confidence.
|
|
127
|
+
</Tip>
|
|
128
|
+
|
|
129
|
+
<Card
|
|
130
|
+
title="View Plans & Pricing"
|
|
131
|
+
icon="credit-card"
|
|
132
|
+
href="/v7/cloud"
|
|
133
|
+
>
|
|
134
|
+
Compare plans and find the right level of parallelization for your team.
|
|
135
|
+
</Card>
|
|
136
|
+
|
|
137
|
+
## Vitest UI
|
|
138
|
+
|
|
139
|
+
Use Vitest UI for interactive debugging:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npx vitest --ui
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The `--ui` flag launches a web-based interface for managing your test suite. Unlike `vitest run`, this starts in watch mode by default.
|
|
146
|
+
|
|
147
|
+
Open http://localhost:51204 to see:
|
|
148
|
+
- **Test file tree** — Browse and navigate your test structure
|
|
149
|
+
- **Test status and duration** — See pass/fail states and timing at a glance
|
|
150
|
+
- **Console output** — View logs and errors inline with each test
|
|
151
|
+
- **Re-run individual tests** — Click to re-execute specific tests without restarting
|
|
152
|
+
- **Filter and search** — Quickly find tests by name or status
|
|
153
|
+
|
|
154
|
+
<Tip>
|
|
155
|
+
Combine with `--open` to automatically open the UI in your browser: `npx vitest --ui --open`
|
|
156
|
+
</Tip>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## Test Reports
|
|
160
|
+
|
|
161
|
+
After running tests, view detailed reports and video replays at [console.testdriver.ai](https://console.testdriver.ai).
|
|
162
|
+
|
|
163
|
+
Reports include:
|
|
164
|
+
- **Video replays** - Watch exactly what happened during each test
|
|
165
|
+
- **Screenshots** - See the state at each step
|
|
166
|
+
- **Timing breakdown** - Identify slow operations
|
|
167
|
+
- **Error details** - Debug failures with full context
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
$ npx vitest run
|
|
171
|
+
|
|
172
|
+
✓ login.test.js (2) 18.4s
|
|
173
|
+
✓ user can login 12.3s
|
|
174
|
+
✓ shows error for invalid credentials 6.1s
|
|
175
|
+
|
|
176
|
+
📹 View reports at: https://console.testdriver.ai
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
<Tip>
|
|
180
|
+
Bookmark your team's dashboard at [console.testdriver.ai](https://console.testdriver.ai) for quick access to test history and analytics.
|
|
181
|
+
</Tip>
|