testdriverai 7.2.9 → 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/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 +93 -125
- 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/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/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/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
- /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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test case 7: Sort by Enrollments (ascending, numeric)
|
|
3
|
+
*
|
|
4
|
+
* 1. Open page: https://practicetestautomation.com/practice-test-table/
|
|
5
|
+
* 2. Set Sort by = Enrollments
|
|
6
|
+
* 3. Verify visible rows are ordered from smallest to largest enrollment
|
|
7
|
+
* 4. Verify numbers with commas sort correctly
|
|
8
|
+
* 5. Fails if the sort is lexicographic (string-based) instead of numeric
|
|
9
|
+
*
|
|
10
|
+
* EXPECTED: This test should PASS if enrollments are sorted ascending numerically
|
|
11
|
+
* This test should FAIL if sort is lexicographic or descending
|
|
12
|
+
*/
|
|
13
|
+
import { describe, expect, it } from "vitest";
|
|
14
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
15
|
+
|
|
16
|
+
describe("Table Sort - Enrollments", () => {
|
|
17
|
+
|
|
18
|
+
it("should sort enrollments numerically ascending", async (context) => {
|
|
19
|
+
const testdriver = TestDriver(context, {
|
|
20
|
+
newSandbox: true,
|
|
21
|
+
headless: false
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Step 1: Open the page
|
|
25
|
+
await testdriver.provision.chrome({
|
|
26
|
+
url: 'https://practicetestautomation.com/practice-test-table/',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Scroll down to see the Sort by dropdown
|
|
30
|
+
await testdriver.scroll("down");
|
|
31
|
+
await testdriver.scroll("down");
|
|
32
|
+
|
|
33
|
+
// Step 2: Find and click the Sort by dropdown
|
|
34
|
+
const sortDropdown = await testdriver.find("Sort by dropdown", { timeout: 15000 });
|
|
35
|
+
console.log("Sort by dropdown found:", sortDropdown.found());
|
|
36
|
+
expect(sortDropdown.found()).toBeTruthy();
|
|
37
|
+
await sortDropdown.click();
|
|
38
|
+
|
|
39
|
+
// Select "Enrollments" from the dropdown options
|
|
40
|
+
const enrollmentsOption = await testdriver.find("Enrollments option", { timeout: 10000 });
|
|
41
|
+
console.log("Enrollments option found:", enrollmentsOption.found());
|
|
42
|
+
expect(enrollmentsOption.found()).toBeTruthy();
|
|
43
|
+
await enrollmentsOption.click();
|
|
44
|
+
|
|
45
|
+
// Scroll to the TOP of the page to see the first rows of the sorted table
|
|
46
|
+
await testdriver.scroll("up");
|
|
47
|
+
await testdriver.scroll("up");
|
|
48
|
+
await testdriver.scroll("up");
|
|
49
|
+
|
|
50
|
+
// Small wait for sort to complete
|
|
51
|
+
await testdriver.pressKeys([""]); // No-op to add small delay
|
|
52
|
+
|
|
53
|
+
// Scroll down just enough to see the table header and first data rows
|
|
54
|
+
await testdriver.scroll("down");
|
|
55
|
+
|
|
56
|
+
// Step 3: Verify the sort is NUMERIC ASCENDING (smallest to largest)
|
|
57
|
+
// For numeric ascending: 10 < 11 < 50 < 1000 < 1200 < 1365
|
|
58
|
+
// If lexicographic: "1,000" < "10" < "11" < "1,200" < "1365" < "50" (wrong - strings compare char by char)
|
|
59
|
+
//
|
|
60
|
+
// The TEST PASSES if first rows show small numbers like 10, 11, 50
|
|
61
|
+
// The TEST FAILS if first rows show large numbers like 1000, 1200, 1365
|
|
62
|
+
const sortResult = await testdriver.assert(
|
|
63
|
+
"The table is sorted by Enrollments in ASCENDING numeric order. " +
|
|
64
|
+
"The FIRST visible enrollment numbers in the table should be the SMALLEST values. " +
|
|
65
|
+
"For example, if the data contains values like 10, 11, 50, 1000, and 1365, " +
|
|
66
|
+
"then 10 or 11 should appear at the TOP of the sorted table. " +
|
|
67
|
+
"If a large number like 1365 appears first, the sort is WRONG (descending or lexicographic)."
|
|
68
|
+
);
|
|
69
|
+
console.log("Numeric ascending sort assertion result:", sortResult);
|
|
70
|
+
expect(sortResult).toBeTruthy();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experiment file - reconnects to existing sandbox
|
|
3
|
+
* Test case 7: Sort by Enrollments (ascending, numeric)
|
|
4
|
+
* Run AFTER table-sort-setup.test.mjs passes (within 2 minutes)
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
8
|
+
|
|
9
|
+
describe("Table Sort Experiment", () => {
|
|
10
|
+
|
|
11
|
+
it("should sort by Enrollments and verify numeric ordering", async (context) => {
|
|
12
|
+
const testdriver = TestDriver(context, {
|
|
13
|
+
newSandbox: true,
|
|
14
|
+
headless: false,
|
|
15
|
+
reconnect: true // Reconnects to last sandbox
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// NO provision here! The sandbox is already running from setup.test.mjs
|
|
19
|
+
|
|
20
|
+
// Click on the Sort By dropdown and select Enrollments
|
|
21
|
+
const sortDropdown = await testdriver.find("Sort By dropdown");
|
|
22
|
+
console.log("Sort dropdown found:", sortDropdown.found());
|
|
23
|
+
await sortDropdown.click();
|
|
24
|
+
|
|
25
|
+
// Select Enrollments from the dropdown
|
|
26
|
+
const enrollmentsOption = await testdriver.find("Enrollments option in dropdown");
|
|
27
|
+
console.log("Enrollments option found:", enrollmentsOption.found());
|
|
28
|
+
await enrollmentsOption.click();
|
|
29
|
+
|
|
30
|
+
// Verify the table is now sorted by enrollments (ascending, numeric)
|
|
31
|
+
// The numbers should be ordered from smallest to largest: 10, 11, 50, 1000, 1,200
|
|
32
|
+
// If lexicographic: 1,000, 1,200, 10, 11, 50 (wrong - strings sort by first character)
|
|
33
|
+
const result = await testdriver.assert("The table shows enrollment numbers in ascending numeric order where smaller numbers like 10 or 11 appear before larger numbers like 1000 or 1200");
|
|
34
|
+
console.log("Sort assertion result:", result);
|
|
35
|
+
expect(result).toBeTruthy();
|
|
36
|
+
|
|
37
|
+
// Also verify numbers with commas sort correctly (1,200 should be after 1,000)
|
|
38
|
+
const commaResult = await testdriver.assert("Numbers with commas like 1,000 and 1,200 are sorted correctly as numbers, not as text");
|
|
39
|
+
console.log("Comma sort assertion:", commaResult);
|
|
40
|
+
expect(commaResult).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test case 7: Sort by Enrollments (ascending, numeric)
|
|
3
|
+
*
|
|
4
|
+
* 1. Open page: https://practicetestautomation.com/practice-test-table/
|
|
5
|
+
* 2. Set Sort by = Enrollments
|
|
6
|
+
* 3. Verify visible rows are ordered from smallest to largest enrollment
|
|
7
|
+
* 4. Verify numbers with commas sort correctly
|
|
8
|
+
* 5. Fails if the sort is lexicographic
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
12
|
+
|
|
13
|
+
describe("Table Sort - Enrollments", () => {
|
|
14
|
+
|
|
15
|
+
it("should sort enrollments numerically ascending", async (context) => {
|
|
16
|
+
const testdriver = TestDriver(context, {
|
|
17
|
+
newSandbox: true,
|
|
18
|
+
headless: false
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Step 1: Open the page
|
|
22
|
+
await testdriver.provision.chrome({
|
|
23
|
+
url: 'https://practicetestautomation.com/practice-test-table/',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Wait for page to load - find the Sort By dropdown
|
|
27
|
+
const sortDropdown = await testdriver.find("Sort By dropdown or select box", { timeout: 30000 });
|
|
28
|
+
console.log("Sort dropdown found:", sortDropdown.found());
|
|
29
|
+
expect(sortDropdown.found()).toBeTruthy();
|
|
30
|
+
|
|
31
|
+
// Step 2: Click the Sort By dropdown
|
|
32
|
+
await sortDropdown.click();
|
|
33
|
+
|
|
34
|
+
// Select "Enrollments" from the dropdown options
|
|
35
|
+
const enrollmentsOption = await testdriver.find("Enrollments option in the dropdown list", { timeout: 10000 });
|
|
36
|
+
console.log("Enrollments option found:", enrollmentsOption.found());
|
|
37
|
+
await enrollmentsOption.click();
|
|
38
|
+
|
|
39
|
+
// Step 3 & 4: Verify the sort is numeric ascending (not lexicographic)
|
|
40
|
+
// If numeric: smaller numbers (10, 11, 50) come before larger numbers (1000, 1200)
|
|
41
|
+
// If lexicographic: would sort as strings (1,000 before 10 because '1' < '1')
|
|
42
|
+
const sortResult = await testdriver.assert(
|
|
43
|
+
"The table enrollment column is sorted in ascending NUMERIC order: " +
|
|
44
|
+
"smaller enrollment numbers like 10, 11, 50 appear BEFORE larger numbers like 1000 or 1200. " +
|
|
45
|
+
"This is correct numeric sorting, not alphabetical/lexicographic sorting."
|
|
46
|
+
);
|
|
47
|
+
console.log("Numeric sort assertion result:", sortResult);
|
|
48
|
+
expect(sortResult).toBeTruthy();
|
|
49
|
+
|
|
50
|
+
// Step 5: Verify numbers with commas are handled correctly
|
|
51
|
+
// 1,200 should be treated as 1200 (greater than 1000), not as a string
|
|
52
|
+
const commaResult = await testdriver.assert(
|
|
53
|
+
"Any enrollment numbers with commas (like 1,200 or 1,000) are sorted correctly as numbers, " +
|
|
54
|
+
"with 1,000 appearing before 1,200 in ascending order"
|
|
55
|
+
);
|
|
56
|
+
console.log("Comma number sorting result:", commaResult);
|
|
57
|
+
expect(commaResult).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
});
|
package/vitest.config.mjs
CHANGED
|
@@ -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>
|