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
package/agent/lib/cache.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const crypto = require("crypto");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate a cache key from a prompt
|
|
7
|
-
* Uses a hash to create a safe filename
|
|
8
|
-
*/
|
|
9
|
-
function getCacheKey(prompt) {
|
|
10
|
-
// Normalize the prompt by trimming and converting to lowercase
|
|
11
|
-
const normalized = prompt.trim().toLowerCase();
|
|
12
|
-
|
|
13
|
-
// Create a hash for the filename
|
|
14
|
-
const hash = crypto.createHash("md5").update(normalized).digest("hex");
|
|
15
|
-
|
|
16
|
-
// Also create a sanitized version of the prompt for readability
|
|
17
|
-
const sanitized = normalized
|
|
18
|
-
.replace(/[^a-z0-9\s]/g, "") // Remove special chars
|
|
19
|
-
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
|
20
|
-
.substring(0, 50); // Limit length
|
|
21
|
-
|
|
22
|
-
// Combine sanitized prompt with hash for uniqueness
|
|
23
|
-
return `${sanitized}-${hash}.yaml`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Get the cache directory path
|
|
28
|
-
* Creates it if it doesn't exist
|
|
29
|
-
*/
|
|
30
|
-
function getCacheDir() {
|
|
31
|
-
const cacheDir = path.join(process.cwd(), ".testdriver", ".cache");
|
|
32
|
-
|
|
33
|
-
if (!fs.existsSync(cacheDir)) {
|
|
34
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return cacheDir;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get the full path to a cache file
|
|
42
|
-
*/
|
|
43
|
-
function getCachePath(prompt) {
|
|
44
|
-
const cacheDir = getCacheDir();
|
|
45
|
-
const key = getCacheKey(prompt);
|
|
46
|
-
return path.join(cacheDir, key);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check if a cached response exists for a prompt
|
|
51
|
-
*/
|
|
52
|
-
function hasCache(prompt) {
|
|
53
|
-
const cachePath = getCachePath(prompt);
|
|
54
|
-
return fs.existsSync(cachePath);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Read cached YAML for a prompt
|
|
59
|
-
* Returns null if no cache exists
|
|
60
|
-
*/
|
|
61
|
-
function readCache(prompt) {
|
|
62
|
-
if (!hasCache(prompt)) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const cachePath = getCachePath(prompt);
|
|
68
|
-
const yaml = fs.readFileSync(cachePath, "utf8");
|
|
69
|
-
return yaml;
|
|
70
|
-
} catch {
|
|
71
|
-
// If there's an error reading the cache, return null
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Write YAML to cache for a prompt
|
|
78
|
-
*/
|
|
79
|
-
function writeCache(prompt, yaml) {
|
|
80
|
-
try {
|
|
81
|
-
const cachePath = getCachePath(prompt);
|
|
82
|
-
fs.writeFileSync(cachePath, yaml, "utf8");
|
|
83
|
-
return cachePath;
|
|
84
|
-
} catch {
|
|
85
|
-
// Silently fail if we can't write to cache
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Clear all cached prompts
|
|
92
|
-
*/
|
|
93
|
-
function clearCache() {
|
|
94
|
-
const cacheDir = getCacheDir();
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const files = fs.readdirSync(cacheDir);
|
|
98
|
-
|
|
99
|
-
for (const file of files) {
|
|
100
|
-
if (file.endsWith(".yaml")) {
|
|
101
|
-
fs.unlinkSync(path.join(cacheDir, file));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return true;
|
|
106
|
-
} catch {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Get cache statistics
|
|
113
|
-
*/
|
|
114
|
-
function getCacheStats() {
|
|
115
|
-
const cacheDir = getCacheDir();
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
const files = fs.readdirSync(cacheDir);
|
|
119
|
-
const yamlFiles = files.filter((f) => f.endsWith(".yaml"));
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
count: yamlFiles.length,
|
|
123
|
-
files: yamlFiles,
|
|
124
|
-
};
|
|
125
|
-
} catch {
|
|
126
|
-
return {
|
|
127
|
-
count: 0,
|
|
128
|
-
files: [],
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
module.exports = {
|
|
134
|
-
getCacheKey,
|
|
135
|
-
getCacheDir,
|
|
136
|
-
getCachePath,
|
|
137
|
-
hasCache,
|
|
138
|
-
readCache,
|
|
139
|
-
writeCache,
|
|
140
|
-
clearCache,
|
|
141
|
-
getCacheStats,
|
|
142
|
-
};
|
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Assertions & Testing"
|
|
3
|
-
sidebarTitle: "Assertions"
|
|
4
|
-
description: "AI-powered assertions and validation"
|
|
5
|
-
icon: "check-circle"
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
TestDriver provides AI-powered assertions that can verify complex visual states and conditions on screen without requiring explicit element locators or coordinates.
|
|
11
|
-
|
|
12
|
-
## AI Assertions
|
|
13
|
-
|
|
14
|
-
### assert()
|
|
15
|
-
|
|
16
|
-
Make an AI-powered assertion about the current screen state.
|
|
17
|
-
|
|
18
|
-
```javascript
|
|
19
|
-
await testdriver.assert(assertion)
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**Parameters:**
|
|
23
|
-
- `assertion` (string) - Natural language description of what should be true
|
|
24
|
-
|
|
25
|
-
**Returns:** `Promise<boolean>` - `true` if assertion passes, throws error if fails
|
|
26
|
-
|
|
27
|
-
### Basic Assertions
|
|
28
|
-
|
|
29
|
-
```javascript
|
|
30
|
-
// Verify page elements
|
|
31
|
-
await testdriver.assert('the login page is displayed');
|
|
32
|
-
await testdriver.assert('submit button is visible');
|
|
33
|
-
await testdriver.assert('error message is shown');
|
|
34
|
-
|
|
35
|
-
// Verify text content
|
|
36
|
-
await testdriver.assert('the page title is "Welcome"');
|
|
37
|
-
await testdriver.assert('username field contains "john.doe"');
|
|
38
|
-
await testdriver.assert('success message says "Account created"');
|
|
39
|
-
|
|
40
|
-
// Verify states
|
|
41
|
-
await testdriver.assert('the form is empty');
|
|
42
|
-
await testdriver.assert('the checkbox is checked');
|
|
43
|
-
await testdriver.assert('the dropdown shows "United States"');
|
|
44
|
-
|
|
45
|
-
// Verify visual appearance
|
|
46
|
-
await testdriver.assert('the button is blue');
|
|
47
|
-
await testdriver.assert('the loading spinner is displayed');
|
|
48
|
-
await testdriver.assert('the modal dialog is open');
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Pattern: Polling Assertions
|
|
52
|
-
|
|
53
|
-
For conditions that may take time to become true, use polling:
|
|
54
|
-
|
|
55
|
-
```javascript
|
|
56
|
-
// Poll until condition is true
|
|
57
|
-
async function waitForAssertion(testdriver, assertion, timeout = 30000) {
|
|
58
|
-
const startTime = Date.now();
|
|
59
|
-
|
|
60
|
-
while (Date.now() - startTime < timeout) {
|
|
61
|
-
try {
|
|
62
|
-
await testdriver.assert(assertion);
|
|
63
|
-
return true; // Assertion passed
|
|
64
|
-
} catch (error) {
|
|
65
|
-
// Assertion failed, wait and retry
|
|
66
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
throw new Error(`Assertion timeout: "${assertion}"`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Usage
|
|
74
|
-
await waitForAssertion(testdriver, 'the page has finished loading', 30000);
|
|
75
|
-
await waitForAssertion(testdriver, 'results are displayed', 10000);
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Extracting Information
|
|
79
|
-
|
|
80
|
-
### extract()
|
|
81
|
-
|
|
82
|
-
Extract information from the screen using AI.
|
|
83
|
-
|
|
84
|
-
```javascript
|
|
85
|
-
await testdriver.extract(description)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
**Parameters:**
|
|
89
|
-
- `description` (string) - What information to extract from the screen
|
|
90
|
-
|
|
91
|
-
**Returns:** `Promise<string>` - Extracted information
|
|
92
|
-
|
|
93
|
-
### Examples
|
|
94
|
-
|
|
95
|
-
```javascript
|
|
96
|
-
// Extract text from screen
|
|
97
|
-
const password = await testdriver.extract('the password displayed on screen');
|
|
98
|
-
const total = await testdriver.extract('the order total amount');
|
|
99
|
-
const errorMessage = await testdriver.extract('the error message text');
|
|
100
|
-
|
|
101
|
-
// Extract structured data
|
|
102
|
-
const email = await testdriver.extract('the email address in the confirmation');
|
|
103
|
-
const orderId = await testdriver.extract('the order ID number');
|
|
104
|
-
const phoneNumber = await testdriver.extract('the phone number');
|
|
105
|
-
|
|
106
|
-
// Use extracted data
|
|
107
|
-
const password = await testdriver.extract('the password for standard_user');
|
|
108
|
-
const passwordField = await testdriver.find('password input');
|
|
109
|
-
await passwordField.click();
|
|
110
|
-
await testdriver.type(password);
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Use Cases
|
|
114
|
-
|
|
115
|
-
**Dynamic Content:**
|
|
116
|
-
```javascript
|
|
117
|
-
// Extract generated values
|
|
118
|
-
const confirmationCode = await testdriver.extract('the 6-digit confirmation code');
|
|
119
|
-
console.log('Code:', confirmationCode);
|
|
120
|
-
|
|
121
|
-
// Use it later in the test
|
|
122
|
-
await testdriver.type(confirmationCode);
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**Verification:**
|
|
126
|
-
```javascript
|
|
127
|
-
// Extract and verify
|
|
128
|
-
const displayedTotal = await testdriver.extract('the cart total');
|
|
129
|
-
const expectedTotal = '$99.99';
|
|
130
|
-
|
|
131
|
-
expect(displayedTotal).toBe(expectedTotal);
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
**Conditional Logic:**
|
|
135
|
-
```javascript
|
|
136
|
-
// Extract state and make decisions
|
|
137
|
-
const status = await testdriver.extract('the order status');
|
|
138
|
-
|
|
139
|
-
if (status.includes('Pending')) {
|
|
140
|
-
// Wait for processing
|
|
141
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
142
|
-
} else if (status.includes('Completed')) {
|
|
143
|
-
// Continue with test
|
|
144
|
-
const downloadButton = await testdriver.find('download receipt button');
|
|
145
|
-
await downloadButton.click();
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
## Testing Patterns
|
|
150
|
-
|
|
151
|
-
### Test-Driven Assertions
|
|
152
|
-
|
|
153
|
-
Structure tests with clear arrange-act-assert pattern:
|
|
154
|
-
|
|
155
|
-
```javascript
|
|
156
|
-
it('should display validation error for empty email', async () => {
|
|
157
|
-
// Arrange
|
|
158
|
-
await testdriver.focusApplication('Google Chrome');
|
|
159
|
-
|
|
160
|
-
// Act
|
|
161
|
-
const submitButton = await testdriver.find('submit button');
|
|
162
|
-
await submitButton.click();
|
|
163
|
-
|
|
164
|
-
// Assert
|
|
165
|
-
const result = await testdriver.assert('validation error says "Email is required"');
|
|
166
|
-
expect(result).toBeTruthy();
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Multi-Step Assertions
|
|
171
|
-
|
|
172
|
-
Verify state at each step of a workflow:
|
|
173
|
-
|
|
174
|
-
```javascript
|
|
175
|
-
it('should complete checkout flow', async () => {
|
|
176
|
-
// Add item to cart
|
|
177
|
-
const addButton = await testdriver.find('add to cart button');
|
|
178
|
-
await addButton.click();
|
|
179
|
-
|
|
180
|
-
// Verify item added
|
|
181
|
-
await testdriver.assert('cart shows 1 item');
|
|
182
|
-
|
|
183
|
-
// Go to checkout
|
|
184
|
-
const cartIcon = await testdriver.find('cart icon');
|
|
185
|
-
await cartIcon.click();
|
|
186
|
-
|
|
187
|
-
// Verify cart page
|
|
188
|
-
await testdriver.assert('shopping cart page is displayed');
|
|
189
|
-
await testdriver.assert('cart contains the selected item');
|
|
190
|
-
|
|
191
|
-
// Proceed to checkout
|
|
192
|
-
const checkoutButton = await testdriver.find('proceed to checkout button');
|
|
193
|
-
await checkoutButton.click();
|
|
194
|
-
|
|
195
|
-
// Verify checkout page
|
|
196
|
-
await testdriver.assert('checkout form is displayed');
|
|
197
|
-
});
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Soft Assertions
|
|
201
|
-
|
|
202
|
-
Collect multiple assertion failures without stopping:
|
|
203
|
-
|
|
204
|
-
```javascript
|
|
205
|
-
it('should validate all form fields', async () => {
|
|
206
|
-
const errors = [];
|
|
207
|
-
|
|
208
|
-
// Try multiple assertions
|
|
209
|
-
try {
|
|
210
|
-
await testdriver.assert('username field has error border');
|
|
211
|
-
} catch (e) {
|
|
212
|
-
errors.push('Username validation failed');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
try {
|
|
216
|
-
await testdriver.assert('email field has error border');
|
|
217
|
-
} catch (e) {
|
|
218
|
-
errors.push('Email validation failed');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
await testdriver.assert('password field has error border');
|
|
223
|
-
} catch (e) {
|
|
224
|
-
errors.push('Password validation failed');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Report all errors
|
|
228
|
-
if (errors.length > 0) {
|
|
229
|
-
throw new Error(`Validation errors:\n${errors.join('\n')}`);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## Complete Example
|
|
235
|
-
|
|
236
|
-
```javascript
|
|
237
|
-
import { beforeAll, afterAll, describe, it, expect } from 'vitest';
|
|
238
|
-
import TestDriver from 'testdriverai';
|
|
239
|
-
|
|
240
|
-
describe('E2E Shopping Flow', () => {
|
|
241
|
-
let testdriver;
|
|
242
|
-
|
|
243
|
-
beforeAll(async () => {
|
|
244
|
-
client = new TestDriver(process.env.TD_API_KEY);
|
|
245
|
-
await testdriver.auth();
|
|
246
|
-
await testdriver.connect({ newSandbox: true });
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
afterAll(async () => {
|
|
250
|
-
await testdriver.disconnect();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('should complete a purchase', async () => {
|
|
254
|
-
await testdriver.focusApplication('Google Chrome');
|
|
255
|
-
|
|
256
|
-
// Verify initial state
|
|
257
|
-
await testdriver.assert('the product listing page is displayed');
|
|
258
|
-
await testdriver.assert('cart is empty');
|
|
259
|
-
|
|
260
|
-
// Add product to cart
|
|
261
|
-
const addButton = await testdriver.find('add to cart button for first product');
|
|
262
|
-
await addButton.click();
|
|
263
|
-
|
|
264
|
-
// Verify cart updated
|
|
265
|
-
await testdriver.assert('cart badge shows 1 item');
|
|
266
|
-
|
|
267
|
-
// Extract product details
|
|
268
|
-
const productName = await testdriver.extract('the name of the product just added');
|
|
269
|
-
const price = await testdriver.extract('the price of the product');
|
|
270
|
-
|
|
271
|
-
console.log(`Added ${productName} at ${price}`);
|
|
272
|
-
|
|
273
|
-
// Go to cart
|
|
274
|
-
const cartIcon = await testdriver.find('shopping cart icon');
|
|
275
|
-
await cartIcon.click();
|
|
276
|
-
|
|
277
|
-
// Verify cart contents
|
|
278
|
-
await testdriver.assert(`cart contains ${productName}`);
|
|
279
|
-
await testdriver.assert(`cart total is ${price}`);
|
|
280
|
-
|
|
281
|
-
// Proceed to checkout
|
|
282
|
-
const checkoutButton = await testdriver.find('checkout button');
|
|
283
|
-
await checkoutButton.click();
|
|
284
|
-
|
|
285
|
-
// Fill shipping info
|
|
286
|
-
const emailField = await testdriver.find('email input');
|
|
287
|
-
await emailField.click();
|
|
288
|
-
await testdriver.type('test@example.com');
|
|
289
|
-
|
|
290
|
-
await testdriver.pressKeys(['tab']);
|
|
291
|
-
await testdriver.type('John Doe');
|
|
292
|
-
|
|
293
|
-
await testdriver.pressKeys(['tab']);
|
|
294
|
-
await testdriver.type('123 Main St');
|
|
295
|
-
|
|
296
|
-
// Submit order
|
|
297
|
-
const submitButton = await testdriver.find('place order button');
|
|
298
|
-
await submitButton.click();
|
|
299
|
-
|
|
300
|
-
// Verify success
|
|
301
|
-
await testdriver.assert('order confirmation page is displayed');
|
|
302
|
-
await testdriver.assert('success message is shown');
|
|
303
|
-
|
|
304
|
-
// Extract order number
|
|
305
|
-
const orderNumber = await testdriver.extract('the order number');
|
|
306
|
-
console.log('Order placed:', orderNumber);
|
|
307
|
-
expect(orderNumber).toBeTruthy();
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('should show validation errors', async () => {
|
|
311
|
-
// Try to submit empty form
|
|
312
|
-
const submitButton = await testdriver.find('submit button');
|
|
313
|
-
await submitButton.click();
|
|
314
|
-
|
|
315
|
-
// Verify multiple validation errors
|
|
316
|
-
await testdriver.assert('email field shows "required" error');
|
|
317
|
-
await testdriver.assert('name field shows "required" error');
|
|
318
|
-
await testdriver.assert('address field shows "required" error');
|
|
319
|
-
|
|
320
|
-
// Verify form not submitted
|
|
321
|
-
await testdriver.assert('still on checkout page', false, false);
|
|
322
|
-
await testdriver.assert('order confirmation page is shown', false, true); // Inverted
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
## Best Practices
|
|
328
|
-
|
|
329
|
-
<AccordionGroup>
|
|
330
|
-
<Accordion title="Be specific in assertions">
|
|
331
|
-
More specific assertions are more reliable:
|
|
332
|
-
|
|
333
|
-
```javascript
|
|
334
|
-
// ❌ Too vague
|
|
335
|
-
await testdriver.assert('button is visible');
|
|
336
|
-
|
|
337
|
-
// ✅ Specific
|
|
338
|
-
await testdriver.assert('blue submit button is visible below the form');
|
|
339
|
-
```
|
|
340
|
-
</Accordion>
|
|
341
|
-
|
|
342
|
-
<Accordion title="Assert state changes">
|
|
343
|
-
Verify state before and after actions:
|
|
344
|
-
|
|
345
|
-
```javascript
|
|
346
|
-
// Before
|
|
347
|
-
await testdriver.assert('cart is empty');
|
|
348
|
-
|
|
349
|
-
// Action
|
|
350
|
-
const addButton = await testdriver.find('add to cart');
|
|
351
|
-
await addButton.click();
|
|
352
|
-
|
|
353
|
-
// After
|
|
354
|
-
await testdriver.assert('cart contains 1 item');
|
|
355
|
-
```
|
|
356
|
-
</Accordion>
|
|
357
|
-
|
|
358
|
-
<Accordion title="Use polling for dynamic content">
|
|
359
|
-
Some assertions may need time to become true:
|
|
360
|
-
|
|
361
|
-
```javascript
|
|
362
|
-
async function waitFor(assertion, timeout = 10000) {
|
|
363
|
-
const start = Date.now();
|
|
364
|
-
while (Date.now() - start < timeout) {
|
|
365
|
-
try {
|
|
366
|
-
await testdriver.assert(assertion);
|
|
367
|
-
return;
|
|
368
|
-
} catch {
|
|
369
|
-
await new Promise(r => setTimeout(r, 1000));
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
throw new Error(`Timeout: ${assertion}`);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
await waitFor('loading complete');
|
|
376
|
-
```
|
|
377
|
-
</Accordion>
|
|
378
|
-
|
|
379
|
-
<Accordion title="Extract before comparing">
|
|
380
|
-
Use `extract()` to extract values for detailed comparisons:
|
|
381
|
-
|
|
382
|
-
```javascript
|
|
383
|
-
const actualTotal = await testdriver.extract('the cart total');
|
|
384
|
-
const expectedTotal = '$99.99';
|
|
385
|
-
|
|
386
|
-
expect(actualTotal).toBe(expectedTotal);
|
|
387
|
-
```
|
|
388
|
-
</Accordion>
|
|
389
|
-
|
|
390
|
-
<Accordion title="Combine with traditional assertions">
|
|
391
|
-
Mix AI assertions with framework assertions for comprehensive testing:
|
|
392
|
-
|
|
393
|
-
```javascript
|
|
394
|
-
// AI assertion for UI state
|
|
395
|
-
await testdriver.assert('success message is displayed');
|
|
396
|
-
|
|
397
|
-
// Extract and use traditional assertion for exact values
|
|
398
|
-
const message = await testdriver.extract('the success message text');
|
|
399
|
-
expect(message).toContain('successfully');
|
|
400
|
-
expect(message).toMatch(/order #\d+/i);
|
|
401
|
-
```
|
|
402
|
-
</Accordion>
|
|
403
|
-
</AccordionGroup>
|