testdriverai 6.2.2 → 7.0.0
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/acceptance-linux.yml +75 -0
- package/.github/workflows/acceptance-sdk-tests.yml +133 -0
- package/.vscode/settings.json +5 -1
- package/MIGRATION.md +389 -0
- package/PLUGIN_MIGRATION.md +222 -0
- package/PROMPT_CACHE.md +200 -0
- package/SDK_LOGGING.md +222 -0
- package/SDK_MIGRATION.md +474 -0
- package/SDK_README.md +1122 -0
- package/{testdriver → _testdriver}/acceptance/drag-and-drop.yaml +2 -2
- package/{testdriver → _testdriver}/acceptance/snippets/login.yaml +1 -1
- package/_testdriver/examples/desktop/lifecycle/prerun.yaml +0 -0
- package/{testdriver → _testdriver}/examples/web/lifecycle/prerun.yaml +6 -1
- package/{testdriver → _testdriver}/lifecycle/postrun.yaml +3 -2
- package/_testdriver/lifecycle/prerun.yaml +15 -0
- package/{testdriver → _testdriver}/lifecycle/provision.yaml +7 -2
- package/agent/index.js +258 -68
- package/agent/interface.js +15 -0
- package/agent/lib/cache.js +142 -0
- package/agent/lib/commander.js +1 -39
- package/agent/lib/commands.js +143 -188
- package/agent/lib/redraw.js +6 -3
- package/agent/lib/sandbox.js +19 -5
- package/agent/lib/sdk.js +1 -0
- package/agent/lib/system.js +0 -3
- package/agent/lib/validation.js +1 -7
- package/debug-locate-response.js +82 -0
- package/debug-screenshot-1763401388589.png +0 -0
- package/debugger/index.html +15 -4
- package/docs/ARCHITECTURE.md +424 -0
- package/docs/AWESOME_LOGS_QUICK_REF.md +100 -0
- package/docs/QUICK_START_TEST_RECORDING.md +215 -0
- package/docs/SDK_AWESOME_LOGS.md +468 -0
- package/docs/TEST_RECORDING.md +388 -0
- package/docs/docs.json +232 -152
- package/docs/sdk-browser-rendering.md +167 -0
- package/docs/v6/getting-started/self-hosting.mdx +407 -0
- package/docs/{guide → v6/guide}/dashcam.mdx +1 -1
- package/docs/{guide → v6/guide}/environment-variables.mdx +4 -5
- package/docs/{guide → v6/guide}/lifecycle.mdx +1 -1
- package/docs/v6/overview/comparison.mdx +101 -0
- package/docs/v7/README.md +135 -0
- package/docs/v7/api/ai.mdx +205 -0
- package/docs/v7/api/assert.mdx +285 -0
- package/docs/v7/api/assertions.mdx +403 -0
- package/docs/v7/api/click.mdx +287 -0
- package/docs/v7/api/client.mdx +322 -0
- package/docs/v7/api/elements.mdx +479 -0
- package/docs/v7/api/exec.mdx +346 -0
- package/docs/v7/api/find.mdx +316 -0
- package/docs/v7/api/focusApplication.mdx +294 -0
- package/docs/v7/api/hover.mdx +279 -0
- package/docs/v7/api/pressKeys.mdx +349 -0
- package/docs/v7/api/sandbox.mdx +404 -0
- package/docs/v7/api/scroll.mdx +300 -0
- package/docs/v7/api/type.mdx +314 -0
- package/docs/v7/commands/assert.mdx +45 -0
- package/docs/v7/commands/exec.mdx +282 -0
- package/docs/v7/commands/focus-application.mdx +44 -0
- package/docs/v7/commands/hover-image.mdx +69 -0
- package/docs/v7/commands/hover-text.mdx +47 -0
- package/docs/v7/commands/if.mdx +53 -0
- package/docs/v7/commands/match-image.mdx +67 -0
- package/docs/v7/commands/press-keys.mdx +87 -0
- package/docs/v7/commands/remember.mdx +49 -0
- package/docs/v7/commands/run.mdx +44 -0
- package/docs/v7/commands/scroll-until-image.mdx +66 -0
- package/docs/v7/commands/scroll-until-text.mdx +60 -0
- package/docs/v7/commands/scroll.mdx +69 -0
- package/docs/v7/commands/type.mdx +45 -0
- package/docs/v7/commands/wait-for-image.mdx +54 -0
- package/docs/v7/commands/wait-for-text.mdx +48 -0
- package/docs/v7/commands/wait.mdx +45 -0
- package/docs/v7/getting-started/quickstart.mdx +199 -0
- package/docs/v7/guides/migration.mdx +562 -0
- package/docs/{getting-started → v7/guides}/self-hosting.mdx +11 -12
- package/docs/v7/playwright.mdx +342 -0
- package/eslint.config.js +19 -1
- package/examples/run-tests-with-recording.sh +70 -0
- package/examples/screenshot-example.js +63 -0
- package/examples/sdk-awesome-logs-demo.js +177 -0
- package/examples/sdk-cache-thresholds.js +96 -0
- package/examples/sdk-element-properties.js +155 -0
- package/examples/sdk-simple-example.js +65 -0
- package/examples/test-recording-example.test.js +166 -0
- package/interfaces/cli/lib/base.js +10 -4
- package/interfaces/logger.js +2 -1
- package/interfaces/shared-test-state.mjs +69 -0
- package/interfaces/vitest-plugin.mjs +744 -0
- package/mcp-server/AI_GUIDELINES.md +57 -0
- package/package.json +18 -5
- package/schema.json +8 -29
- package/scripts/view-test-results.mjs +96 -0
- package/sdk-log-formatter.js +714 -0
- package/sdk.d.ts +735 -0
- package/sdk.js +1906 -0
- package/{.github/workflows/self-hosted.yml → self-hosted.yml} +13 -4
- package/setup/aws/cloudformation.yaml +9 -2
- package/test/mcp-example-test.yaml +27 -0
- package/test-find-api.js +73 -0
- package/test-prompt-cache.js +96 -0
- package/test-sandbox-render.js +28 -0
- package/test-sdk-methods.js +15 -0
- package/test-sdk-refactor.js +53 -0
- package/test-stack-trace.mjs +57 -0
- package/testdriver/acceptance-sdk/QUICK_REFERENCE.md +61 -0
- package/testdriver/acceptance-sdk/README.md +128 -0
- package/testdriver/acceptance-sdk/TEST_REPORTING.md +245 -0
- package/testdriver/acceptance-sdk/assert.test.mjs +44 -0
- package/testdriver/acceptance-sdk/drag-and-drop.test.mjs +70 -0
- package/testdriver/acceptance-sdk/element-not-found.test.mjs +38 -0
- package/testdriver/acceptance-sdk/exec-js.test.mjs +55 -0
- package/testdriver/acceptance-sdk/exec-output.test.mjs +71 -0
- package/testdriver/acceptance-sdk/exec-pwsh.test.mjs +69 -0
- package/testdriver/acceptance-sdk/focus-window.test.mjs +48 -0
- package/testdriver/acceptance-sdk/formatted-logging.test.mjs +41 -0
- package/testdriver/acceptance-sdk/hover-image.test.mjs +43 -0
- package/testdriver/acceptance-sdk/hover-text-with-description.test.mjs +50 -0
- package/testdriver/acceptance-sdk/hover-text.test.mjs +41 -0
- package/testdriver/acceptance-sdk/match-image.test.mjs +48 -0
- package/testdriver/acceptance-sdk/press-keys.test.mjs +64 -0
- package/testdriver/acceptance-sdk/prompt.test.mjs +45 -0
- package/testdriver/acceptance-sdk/scroll-keyboard.test.mjs +52 -0
- package/testdriver/acceptance-sdk/scroll-until-image.test.mjs +51 -0
- package/testdriver/acceptance-sdk/scroll-until-text.test.mjs +42 -0
- package/testdriver/acceptance-sdk/scroll.test.mjs +50 -0
- package/testdriver/acceptance-sdk/setup/globalTeardown.mjs +11 -0
- package/testdriver/acceptance-sdk/setup/lifecycleHelpers.mjs +239 -0
- package/testdriver/acceptance-sdk/setup/testHelpers.mjs +648 -0
- package/testdriver/acceptance-sdk/setup/vitestSetup.mjs +40 -0
- package/testdriver/acceptance-sdk/type-checking-demo.js +49 -0
- package/testdriver/acceptance-sdk/type.test.mjs +84 -0
- package/verify-element-api.js +89 -0
- package/verify-types.js +0 -0
- package/vitest.config.example.js +19 -0
- package/vitest.config.mjs +65 -0
- package/vitest.config.mjs.bak +44 -0
- package/.github/workflows/acceptance-v6.yml +0 -169
- package/docs/overview/comparison.mdx +0 -82
- package/testdriver/lifecycle/prerun.yaml +0 -17
- /package/{testdriver/examples/desktop/lifecycle/prerun.yaml → .env.example} +0 -0
- /package/{testdriver → _testdriver}/acceptance/assert.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/dashcam.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/embed.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/exec-js.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/exec-output.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/exec-shell.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/focus-window.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/hover-image.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/hover-text-with-description.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/hover-text.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/if-else.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/match-image.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/press-keys.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/prompt.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/remember.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/screenshots/cart.png +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll-keyboard.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll-until-image.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll-until-text.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/snippets/match-cart.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/type.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/failure.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/hover-text.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/lifecycle/postrun.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/lifecycle/prerun.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/secrets.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/dashcam-chrome.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/exec-pwsh-multiline.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/js-exception.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/js-promise.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/lifecycle/postrun.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/prompt-in-middle.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/prompt-nested.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/success-test.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/example.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/lifecycle/postrun.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/readme.md +0 -0
- /package/{testdriver → _testdriver}/examples/chrome-extension/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/desktop/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/vscode-extension/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/web/lifecycle/postrun.yaml +0 -0
- /package/docs/{account → v6/account}/dashboard.mdx +0 -0
- /package/docs/{account → v6/account}/enterprise.mdx +0 -0
- /package/docs/{account → v6/account}/pricing.mdx +0 -0
- /package/docs/{account → v6/account}/projects.mdx +0 -0
- /package/docs/{account → v6/account}/team.mdx +0 -0
- /package/docs/{action → v6/action}/ami.mdx +0 -0
- /package/docs/{action → v6/action}/performance.mdx +0 -0
- /package/docs/{action → v6/action}/secrets.mdx +0 -0
- /package/docs/{apps → v6/apps}/chrome-extensions.mdx +0 -0
- /package/docs/{apps → v6/apps}/desktop-apps.mdx +0 -0
- /package/docs/{apps → v6/apps}/mobile-apps.mdx +0 -0
- /package/docs/{apps → v6/apps}/static-websites.mdx +0 -0
- /package/docs/{apps → v6/apps}/tauri-apps.mdx +0 -0
- /package/docs/{bugs → v6/bugs}/jira.mdx +0 -0
- /package/docs/{cli → v6/cli}/overview.mdx +0 -0
- /package/docs/{commands → v6/commands}/assert.mdx +0 -0
- /package/docs/{commands → v6/commands}/exec.mdx +0 -0
- /package/docs/{commands → v6/commands}/focus-application.mdx +0 -0
- /package/docs/{commands → v6/commands}/hover-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/hover-text.mdx +0 -0
- /package/docs/{commands → v6/commands}/if.mdx +0 -0
- /package/docs/{commands → v6/commands}/match-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/press-keys.mdx +0 -0
- /package/docs/{commands → v6/commands}/remember.mdx +0 -0
- /package/docs/{commands → v6/commands}/run.mdx +0 -0
- /package/docs/{commands → v6/commands}/scroll-until-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/scroll-until-text.mdx +0 -0
- /package/docs/{commands → v6/commands}/scroll.mdx +0 -0
- /package/docs/{commands → v6/commands}/type.mdx +0 -0
- /package/docs/{commands → v6/commands}/wait-for-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/wait-for-text.mdx +0 -0
- /package/docs/{commands → v6/commands}/wait.mdx +0 -0
- /package/docs/{exporting → v6/exporting}/junit.mdx +0 -0
- /package/docs/{exporting → v6/exporting}/playwright.mdx +0 -0
- /package/docs/{features → v6/features}/auto-healing.mdx +0 -0
- /package/docs/{features → v6/features}/generation.mdx +0 -0
- /package/docs/{features → v6/features}/parallel-testing.mdx +0 -0
- /package/docs/{features → v6/features}/reusable-snippets.mdx +0 -0
- /package/docs/{features → v6/features}/selectorless.mdx +0 -0
- /package/docs/{features → v6/features}/visual-assertions.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/ci.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/cli.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/editing.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/playwright.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/running.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/vscode.mdx +0 -0
- /package/docs/{guide → v6/guide}/assertions.mdx +0 -0
- /package/docs/{guide → v6/guide}/authentication.mdx +0 -0
- /package/docs/{guide → v6/guide}/code.mdx +0 -0
- /package/docs/{guide → v6/guide}/locating.mdx +0 -0
- /package/docs/{guide → v6/guide}/protips.mdx +0 -0
- /package/docs/{guide → v6/guide}/variables.mdx +0 -0
- /package/docs/{guide → v6/guide}/waiting.mdx +0 -0
- /package/docs/{importing → v6/importing}/csv.mdx +0 -0
- /package/docs/{importing → v6/importing}/gherkin.mdx +0 -0
- /package/docs/{importing → v6/importing}/jira.mdx +0 -0
- /package/docs/{importing → v6/importing}/testrail.mdx +0 -0
- /package/docs/{integrations → v6/integrations}/electron.mdx +0 -0
- /package/docs/{integrations → v6/integrations}/netlify.mdx +0 -0
- /package/docs/{integrations → v6/integrations}/vercel.mdx +0 -0
- /package/docs/{interactive → v6/interactive}/explore.mdx +0 -0
- /package/docs/{interactive → v6/interactive}/run.mdx +0 -0
- /package/docs/{interactive → v6/interactive}/save.mdx +0 -0
- /package/docs/{overview → v6/overview}/faq.mdx +0 -0
- /package/docs/{overview → v6/overview}/performance.mdx +0 -0
- /package/docs/{overview → v6/overview}/quickstart.mdx +0 -0
- /package/docs/{overview → v6/overview}/what-is-testdriver.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/ai-chatbot.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/cookie-banner.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/file-upload.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/form-filling.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/log-in.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/pdf-generation.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/spell-check.mdx +0 -0
- /package/docs/{security → v6/security}/action.mdx +0 -0
- /package/docs/{security → v6/security}/agent.mdx +0 -0
- /package/docs/{security → v6/security}/platform.mdx +0 -0
- /package/docs/{tutorials → v6/tutorials}/advanced-test.mdx +0 -0
- /package/docs/{tutorials → v6/tutorials}/basic-test.mdx +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TestDriver SDK - Cache Thresholds Example
|
|
5
|
+
*
|
|
6
|
+
* This example demonstrates how to configure cache thresholds for different
|
|
7
|
+
* operations and view cache debugging information.
|
|
8
|
+
*
|
|
9
|
+
* Run with VERBOSE=true to see cache hit/miss information:
|
|
10
|
+
* TD_API_KEY=your_key VERBOSE=true node examples/sdk-cache-thresholds.js
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const TestDriver = require("../sdk.js");
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
try {
|
|
17
|
+
// Create client with custom cache thresholds
|
|
18
|
+
const client = new TestDriver(process.env.TD_API_KEY, {
|
|
19
|
+
os: "windows",
|
|
20
|
+
logging: true,
|
|
21
|
+
cacheThreshold: {
|
|
22
|
+
find: 0.03, // 3% difference = 97% similarity required for cache hit
|
|
23
|
+
findAll: 0.05, // 5% difference = 95% similarity required for cache hit
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log("\n=== TestDriver SDK - Cache Thresholds Demo ===\n");
|
|
28
|
+
console.log("Cache thresholds configured:");
|
|
29
|
+
console.log(" - find: 0.03 (97% similarity required)");
|
|
30
|
+
console.log(" - findAll: 0.05 (95% similarity required)\n");
|
|
31
|
+
console.log("You can also override thresholds per-command:");
|
|
32
|
+
console.log(' await client.find("element", 0.01) // 99% similarity\n');
|
|
33
|
+
|
|
34
|
+
// Connect to sandbox
|
|
35
|
+
console.log("Connecting to sandbox...");
|
|
36
|
+
await client.connect({ headless: true });
|
|
37
|
+
|
|
38
|
+
// Open a test page
|
|
39
|
+
console.log("Opening test page...");
|
|
40
|
+
await client.focusApplication("Google Chrome");
|
|
41
|
+
await client.type("https://example.com");
|
|
42
|
+
await client.pressKeys(["enter"]);
|
|
43
|
+
|
|
44
|
+
// Wait for page load
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
46
|
+
|
|
47
|
+
// Example 1: First find - should be a cache MISS
|
|
48
|
+
console.log("\n--- First find (cache MISS expected) ---");
|
|
49
|
+
const heading1 = await client.find("heading that says Example Domain");
|
|
50
|
+
|
|
51
|
+
if (heading1.found()) {
|
|
52
|
+
console.log(`✓ Element found at (${heading1.x}, ${heading1.y})`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Example 2: Second find - should be a cache HIT (same element, same screen)
|
|
56
|
+
console.log("\n--- Second find (cache HIT expected) ---");
|
|
57
|
+
// eslint-disable-next-line no-unused-vars
|
|
58
|
+
const _heading2 = await client.find("heading that says Example Domain");
|
|
59
|
+
|
|
60
|
+
// Example 3: Find with custom threshold override
|
|
61
|
+
console.log("\n--- Find with strict threshold (0.01 = 99% similarity) ---");
|
|
62
|
+
// eslint-disable-next-line no-unused-vars
|
|
63
|
+
const _heading3 = await client.find(
|
|
64
|
+
"heading that says Example Domain",
|
|
65
|
+
0.01,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Example 4: Find a different element - cache MISS
|
|
69
|
+
console.log("\n--- Finding different element (cache MISS expected) ---");
|
|
70
|
+
// eslint-disable-next-line no-unused-vars
|
|
71
|
+
const _paragraph = await client.find(
|
|
72
|
+
"paragraph with text about illustrative examples",
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Example 5: Find the same paragraph again - cache HIT
|
|
76
|
+
console.log("\n--- Finding same paragraph again (cache HIT expected) ---");
|
|
77
|
+
// eslint-disable-next-line no-unused-vars
|
|
78
|
+
const _paragraph2 = await client.find(
|
|
79
|
+
"paragraph with text about illustrative examples",
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
console.log("\n=== Demo Complete ===");
|
|
83
|
+
console.log(
|
|
84
|
+
"\nNote: Run with VERBOSE=true to see detailed cache information:",
|
|
85
|
+
);
|
|
86
|
+
console.log(" - Cache hit/miss status");
|
|
87
|
+
console.log(" - Cache strategy (image/text)");
|
|
88
|
+
console.log(" - Similarity scores");
|
|
89
|
+
console.log(" - Response times\n");
|
|
90
|
+
|
|
91
|
+
await client.disconnect();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("Test failed:", error);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TestDriver SDK - Element Properties Example
|
|
5
|
+
*
|
|
6
|
+
* This example demonstrates accessing all available properties from located elements,
|
|
7
|
+
* including coordinates, dimensions, confidence scores, screenshots, and more.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const TestDriverSDK = require("../sdk");
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const client = new TestDriverSDK(process.env.TD_API_KEY);
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
await client.connect();
|
|
17
|
+
|
|
18
|
+
// Example 1: Basic coordinate properties
|
|
19
|
+
console.log("=== Example 1: Basic Coordinates ===");
|
|
20
|
+
const button = await client.find("the login button");
|
|
21
|
+
|
|
22
|
+
if (button.found()) {
|
|
23
|
+
console.log("Button found!");
|
|
24
|
+
console.log(" X (top-left):", button.x);
|
|
25
|
+
console.log(" Y (top-left):", button.y);
|
|
26
|
+
console.log(" Center X:", button.centerX);
|
|
27
|
+
console.log(" Center Y:", button.centerY);
|
|
28
|
+
console.log(" Coordinates object:", button.getCoordinates());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Example 2: Element dimensions
|
|
32
|
+
console.log("\n=== Example 2: Element Dimensions ===");
|
|
33
|
+
const input = await client.find("username input field");
|
|
34
|
+
|
|
35
|
+
if (input.found()) {
|
|
36
|
+
console.log("Input field found!");
|
|
37
|
+
console.log(" Width:", input.width);
|
|
38
|
+
console.log(" Height:", input.height);
|
|
39
|
+
|
|
40
|
+
if (input.boundingBox) {
|
|
41
|
+
console.log(" Bounding box:", input.boundingBox);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Example 3: Confidence and text data
|
|
46
|
+
console.log("\n=== Example 3: Match Quality & Text ===");
|
|
47
|
+
const link = await client.find("sign up link");
|
|
48
|
+
|
|
49
|
+
if (link.found()) {
|
|
50
|
+
console.log("Link found!");
|
|
51
|
+
console.log(" Confidence score:", link.confidence);
|
|
52
|
+
console.log(" Text content:", link.text);
|
|
53
|
+
console.log(" Label:", link.label);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Example 4: Screenshot data
|
|
57
|
+
console.log("\n=== Example 4: Element Screenshot ===");
|
|
58
|
+
const icon = await client.find("settings icon");
|
|
59
|
+
|
|
60
|
+
if (icon.found() && icon.screenshot) {
|
|
61
|
+
console.log("Icon found with screenshot!");
|
|
62
|
+
console.log(" Screenshot (base64) length:", icon.screenshot.length);
|
|
63
|
+
|
|
64
|
+
// You could save this to a file:
|
|
65
|
+
// const fs = require('fs');
|
|
66
|
+
// fs.writeFileSync('element.png', Buffer.from(icon.screenshot, 'base64'));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Example 5: Full API response
|
|
70
|
+
console.log("\n=== Example 5: Full API Response ===");
|
|
71
|
+
const widget = await client.find("main content area");
|
|
72
|
+
|
|
73
|
+
if (widget.found()) {
|
|
74
|
+
const fullResponse = widget.getResponse();
|
|
75
|
+
console.log("Full API response:", JSON.stringify(fullResponse, null, 2));
|
|
76
|
+
|
|
77
|
+
// Log all available properties
|
|
78
|
+
if (fullResponse) {
|
|
79
|
+
console.log("\nAll available properties:");
|
|
80
|
+
Object.keys(fullResponse).forEach((key) => {
|
|
81
|
+
const value = fullResponse[key];
|
|
82
|
+
const preview =
|
|
83
|
+
typeof value === "string" && value.length > 50
|
|
84
|
+
? value.substring(0, 50) + "..."
|
|
85
|
+
: value;
|
|
86
|
+
console.log(` ${key}:`, preview);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Example 6: Property-based validation
|
|
92
|
+
console.log("\n=== Example 6: Property-based Validation ===");
|
|
93
|
+
const message = await client.find("error message");
|
|
94
|
+
|
|
95
|
+
if (message.found()) {
|
|
96
|
+
// Check position
|
|
97
|
+
if (message.centerY < 200) {
|
|
98
|
+
console.log("✓ Error message is at top of screen");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Check confidence
|
|
102
|
+
if (message.confidence && message.confidence > 0.9) {
|
|
103
|
+
console.log("✓ High confidence match (", message.confidence, ")");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Check text content
|
|
107
|
+
if (message.text) {
|
|
108
|
+
console.log("✓ Message text:", message.text);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Example 7: Position-based logic
|
|
113
|
+
console.log("\n=== Example 7: Position-based Logic ===");
|
|
114
|
+
const menu = await client.find("dropdown menu");
|
|
115
|
+
|
|
116
|
+
if (menu.found()) {
|
|
117
|
+
// Calculate positions
|
|
118
|
+
const offsetX = menu.x + 10;
|
|
119
|
+
const offsetY = menu.y + 20;
|
|
120
|
+
console.log("Menu position:", { x: menu.x, y: menu.y });
|
|
121
|
+
console.log("Offset position:", { x: offsetX, y: offsetY });
|
|
122
|
+
|
|
123
|
+
// Check if element is in viewport
|
|
124
|
+
const viewportHeight = 768;
|
|
125
|
+
if (menu.y > 0 && menu.y < viewportHeight) {
|
|
126
|
+
console.log("✓ Element is visible in viewport");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Example 8: Conditional actions based on properties
|
|
131
|
+
console.log("\n=== Example 8: Conditional Actions ===");
|
|
132
|
+
const notification = await client.find("notification popup");
|
|
133
|
+
|
|
134
|
+
if (notification.found()) {
|
|
135
|
+
// Only interact if confidence is high
|
|
136
|
+
if (notification.confidence && notification.confidence > 0.8) {
|
|
137
|
+
console.log("High confidence, clicking notification");
|
|
138
|
+
await notification.click();
|
|
139
|
+
} else {
|
|
140
|
+
console.log("Low confidence, skipping interaction");
|
|
141
|
+
console.log("Debug info:", {
|
|
142
|
+
coordinates: notification.getCoordinates(),
|
|
143
|
+
confidence: notification.confidence,
|
|
144
|
+
text: notification.text,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
await client.disconnect();
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error("Test failed:", error);
|
|
152
|
+
await client.disconnect();
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
})();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TestDriver SDK - Simple Example with AWESOME Logs 🎨
|
|
5
|
+
*
|
|
6
|
+
* A straightforward example showing the beautiful logging in action.
|
|
7
|
+
*
|
|
8
|
+
* Run: TD_API_KEY=your_key node examples/sdk-simple-example.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const TestDriver = require("../sdk.js");
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
try {
|
|
15
|
+
// Create client with logging enabled (default)
|
|
16
|
+
const client = new TestDriver(process.env.TD_API_KEY, {
|
|
17
|
+
os: "windows",
|
|
18
|
+
logging: true, // This enables the awesome logs!
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log("\n🚀 Starting TestDriver SDK Example...\n");
|
|
22
|
+
|
|
23
|
+
// Connect to sandbox - you'll see: 🔌 Connected
|
|
24
|
+
await client.connect({ headless: true });
|
|
25
|
+
|
|
26
|
+
// Navigate to a test page
|
|
27
|
+
await client.focusApplication("Google Chrome");
|
|
28
|
+
await client.type("https://example.com");
|
|
29
|
+
await client.pressKeys(["enter"]);
|
|
30
|
+
|
|
31
|
+
// Wait for page load
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
33
|
+
|
|
34
|
+
// Find an element - you'll see: 🔍 Found "heading..." · 📍 (x, y) · ⏱️ XXXms · ⚡ cached
|
|
35
|
+
const heading = await client.find("heading that says Example Domain");
|
|
36
|
+
|
|
37
|
+
if (heading.found()) {
|
|
38
|
+
// Click the element - you'll see: 👆 Click "heading..."
|
|
39
|
+
await heading.click();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Find another element
|
|
43
|
+
const link = await client.find("More information link");
|
|
44
|
+
|
|
45
|
+
if (link.found()) {
|
|
46
|
+
// Hover over it - you'll see: 👉 Hover "More information link"
|
|
47
|
+
await link.hover();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Scroll down - you'll see: 📜 Scroll
|
|
51
|
+
await client.scroll("down", 300);
|
|
52
|
+
|
|
53
|
+
// Take a screenshot - you'll see: 📸 Screenshot
|
|
54
|
+
const screenshot = await client.screenshot();
|
|
55
|
+
console.log(`\n📸 Screenshot captured (${screenshot.length} bytes)\n`);
|
|
56
|
+
|
|
57
|
+
// Disconnect - you'll see: 🔌 Disconnected
|
|
58
|
+
await client.disconnect();
|
|
59
|
+
|
|
60
|
+
console.log("\n✅ Example completed successfully!\n");
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(`\n❌ Error: ${error.message}\n`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Vitest test file demonstrating TestDriver test recording
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to:
|
|
5
|
+
* 1. Use TestDriver SDK in tests
|
|
6
|
+
* 2. Associate dashcam recordings with tests
|
|
7
|
+
* 3. Record custom test metadata
|
|
8
|
+
*
|
|
9
|
+
* Run with: npx vitest run examples/test-recording-example.test.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { afterAll, beforeAll, describe, test } from "vitest";
|
|
13
|
+
import TestDriverSDK from "../sdk.js";
|
|
14
|
+
|
|
15
|
+
// Initialize TestDriver client
|
|
16
|
+
let client;
|
|
17
|
+
let runId;
|
|
18
|
+
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
// Connect to TestDriver
|
|
21
|
+
client = new TestDriverSDK({
|
|
22
|
+
apiKey: process.env.TD_API_KEY || "your-api-key",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await client.connect();
|
|
26
|
+
|
|
27
|
+
// Create a test run (usually done by the Vitest reporter, but shown here for demo)
|
|
28
|
+
runId = `example-${Date.now()}`;
|
|
29
|
+
|
|
30
|
+
const testRun = await client.createTestRun({
|
|
31
|
+
runId,
|
|
32
|
+
suiteName: "Example Test Suite",
|
|
33
|
+
platform: "windows",
|
|
34
|
+
git: {
|
|
35
|
+
repo: "testdriverai/cli",
|
|
36
|
+
branch: "main",
|
|
37
|
+
commit: "abc123",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
console.log("Test run created:", testRun.runId);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterAll(async () => {
|
|
45
|
+
// Complete the test run
|
|
46
|
+
await client.completeTestRun({
|
|
47
|
+
runId,
|
|
48
|
+
status: "passed",
|
|
49
|
+
totalTests: 3,
|
|
50
|
+
passedTests: 3,
|
|
51
|
+
failedTests: 0,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await client.disconnect();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("Login Tests", () => {
|
|
58
|
+
test("should display login page", async () => {
|
|
59
|
+
const testStart = Date.now();
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
// Your test logic here
|
|
63
|
+
await client.click("Login");
|
|
64
|
+
|
|
65
|
+
// Record the test result
|
|
66
|
+
await client.recordTestCase({
|
|
67
|
+
runId,
|
|
68
|
+
testName: "should display login page",
|
|
69
|
+
testFile: "examples/test-recording-example.test.js",
|
|
70
|
+
suiteName: "Login Tests",
|
|
71
|
+
status: "passed",
|
|
72
|
+
startTime: testStart,
|
|
73
|
+
endTime: Date.now(),
|
|
74
|
+
duration: Date.now() - testStart,
|
|
75
|
+
});
|
|
76
|
+
} catch (error) {
|
|
77
|
+
// Record failure
|
|
78
|
+
await client.recordTestCase({
|
|
79
|
+
runId,
|
|
80
|
+
testName: "should display login page",
|
|
81
|
+
testFile: "examples/test-recording-example.test.js",
|
|
82
|
+
status: "failed",
|
|
83
|
+
errorMessage: error.message,
|
|
84
|
+
errorStack: error.stack,
|
|
85
|
+
});
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("should login with valid credentials", async () => {
|
|
91
|
+
const testStart = Date.now();
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
// Test logic
|
|
95
|
+
await client.type("username", "testuser");
|
|
96
|
+
await client.type("password", "password123");
|
|
97
|
+
await client.click("Submit");
|
|
98
|
+
|
|
99
|
+
// Wait for dashboard
|
|
100
|
+
await client.waitForText("Dashboard");
|
|
101
|
+
|
|
102
|
+
// Record success
|
|
103
|
+
await client.recordTestCase({
|
|
104
|
+
runId,
|
|
105
|
+
testName: "should login with valid credentials",
|
|
106
|
+
testFile: "examples/test-recording-example.test.js",
|
|
107
|
+
suiteName: "Login Tests",
|
|
108
|
+
status: "passed",
|
|
109
|
+
startTime: testStart,
|
|
110
|
+
endTime: Date.now(),
|
|
111
|
+
duration: Date.now() - testStart,
|
|
112
|
+
// Associate with dashcam replay (if you have the URL)
|
|
113
|
+
replayUrl: process.env.DASHCAM_REPLAY_URL,
|
|
114
|
+
});
|
|
115
|
+
} catch (error) {
|
|
116
|
+
await client.recordTestCase({
|
|
117
|
+
runId,
|
|
118
|
+
testName: "should login with valid credentials",
|
|
119
|
+
testFile: "examples/test-recording-example.test.js",
|
|
120
|
+
status: "failed",
|
|
121
|
+
errorMessage: error.message,
|
|
122
|
+
errorStack: error.stack,
|
|
123
|
+
});
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("should show error with invalid credentials", async () => {
|
|
129
|
+
const testStart = Date.now();
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
await client.type("username", "wrong");
|
|
133
|
+
await client.type("password", "wrong");
|
|
134
|
+
await client.click("Submit");
|
|
135
|
+
|
|
136
|
+
await client.waitForText("Invalid credentials");
|
|
137
|
+
|
|
138
|
+
await client.recordTestCase({
|
|
139
|
+
runId,
|
|
140
|
+
testName: "should show error with invalid credentials",
|
|
141
|
+
testFile: "examples/test-recording-example.test.js",
|
|
142
|
+
suiteName: "Login Tests",
|
|
143
|
+
status: "passed",
|
|
144
|
+
startTime: testStart,
|
|
145
|
+
endTime: Date.now(),
|
|
146
|
+
duration: Date.now() - testStart,
|
|
147
|
+
steps: [
|
|
148
|
+
{ action: "type", target: "username", value: "wrong" },
|
|
149
|
+
{ action: "type", target: "password", value: "wrong" },
|
|
150
|
+
{ action: "click", target: "Submit" },
|
|
151
|
+
{ action: "waitForText", target: "Invalid credentials" },
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
await client.recordTestCase({
|
|
156
|
+
runId,
|
|
157
|
+
testName: "should show error with invalid credentials",
|
|
158
|
+
testFile: "examples/test-recording-example.test.js",
|
|
159
|
+
status: "failed",
|
|
160
|
+
errorMessage: error.message,
|
|
161
|
+
errorStack: error.stack,
|
|
162
|
+
});
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -37,12 +37,14 @@ class BaseCommand extends Command {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
sendToSandbox(message) {
|
|
40
|
+
if (!message) return;
|
|
41
|
+
|
|
40
42
|
// ensure message is a string
|
|
41
43
|
if (typeof message !== "string") {
|
|
42
44
|
message = JSON.stringify(message);
|
|
43
45
|
}
|
|
46
|
+
|
|
44
47
|
this.agent.sandbox.send({
|
|
45
|
-
os: "linux",
|
|
46
48
|
type: "output",
|
|
47
49
|
output: Buffer.from(message).toString("base64"),
|
|
48
50
|
});
|
|
@@ -95,7 +97,7 @@ class BaseCommand extends Command {
|
|
|
95
97
|
});
|
|
96
98
|
|
|
97
99
|
// Handle sandbox connection with pattern matching for subsequent events
|
|
98
|
-
this.agent.emitter.
|
|
100
|
+
this.agent.emitter.once("sandbox:connected", () => {
|
|
99
101
|
isConnected = true;
|
|
100
102
|
// Once sandbox is connected, send all log and error events to sandbox
|
|
101
103
|
this.agent.emitter.on("log:*", (message) => {
|
|
@@ -145,8 +147,12 @@ class BaseCommand extends Command {
|
|
|
145
147
|
console.log(`Live test execution: `);
|
|
146
148
|
if (this.agent.config.CI) {
|
|
147
149
|
let u = new URL(url);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
try {
|
|
151
|
+
u = JSON.parse(u.searchParams.get("data"));
|
|
152
|
+
console.log(`${u.url}&view_only=true`);
|
|
153
|
+
} catch {
|
|
154
|
+
console.log(url);
|
|
155
|
+
}
|
|
150
156
|
} else {
|
|
151
157
|
console.log(url);
|
|
152
158
|
await openBrowser(url);
|
package/interfaces/logger.js
CHANGED
|
@@ -21,6 +21,8 @@ class CustomTransport extends Transport {
|
|
|
21
21
|
this.sandbox = require("../agent/lib/sandbox");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
console.log("CustomTransport log message:", message);
|
|
25
|
+
|
|
24
26
|
if (this.sandbox && this.sandbox.instanceSocketConnected) {
|
|
25
27
|
if (typeof message === "object") {
|
|
26
28
|
console.log(chalk.cyan("protecting against base64 error"));
|
|
@@ -29,7 +31,6 @@ class CustomTransport extends Transport {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
this.sandbox.send({
|
|
32
|
-
os: "linux",
|
|
33
34
|
type: "output",
|
|
34
35
|
output: Buffer.from(message).toString("base64"),
|
|
35
36
|
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Test State Module
|
|
3
|
+
*
|
|
4
|
+
* This module uses Node.js module caching to share state between
|
|
5
|
+
* the reporter process and worker processes in Vitest.
|
|
6
|
+
*
|
|
7
|
+
* Since Node.js caches modules, all imports of this file will
|
|
8
|
+
* receive the same state object instance.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Shared state object that persists across all imports
|
|
12
|
+
const sharedState = {
|
|
13
|
+
testRun: null,
|
|
14
|
+
testRunId: null,
|
|
15
|
+
token: null,
|
|
16
|
+
apiKey: null,
|
|
17
|
+
apiRoot: null,
|
|
18
|
+
startTime: null,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set the test run information
|
|
23
|
+
*/
|
|
24
|
+
export function setTestRunInfo(info) {
|
|
25
|
+
console.log("[SharedState] Setting test run info:", {
|
|
26
|
+
testRunId: info.testRunId,
|
|
27
|
+
hasToken: !!info.token,
|
|
28
|
+
hasTestRun: !!info.testRun,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (info.testRun) sharedState.testRun = info.testRun;
|
|
32
|
+
if (info.testRunId) sharedState.testRunId = info.testRunId;
|
|
33
|
+
if (info.token) sharedState.token = info.token;
|
|
34
|
+
if (info.apiKey) sharedState.apiKey = info.apiKey;
|
|
35
|
+
if (info.apiRoot) sharedState.apiRoot = info.apiRoot;
|
|
36
|
+
if (info.startTime) sharedState.startTime = info.startTime;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the test run information
|
|
41
|
+
*/
|
|
42
|
+
export function getTestRunInfo() {
|
|
43
|
+
return {
|
|
44
|
+
testRun: sharedState.testRun,
|
|
45
|
+
testRunId: sharedState.testRunId,
|
|
46
|
+
token: sharedState.token,
|
|
47
|
+
apiKey: sharedState.apiKey,
|
|
48
|
+
apiRoot: sharedState.apiRoot,
|
|
49
|
+
startTime: sharedState.startTime,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Clear the test run information
|
|
55
|
+
*/
|
|
56
|
+
export function clearTestRunInfo() {
|
|
57
|
+
console.log("[SharedState] Clearing test run info");
|
|
58
|
+
sharedState.testRun = null;
|
|
59
|
+
sharedState.testRunId = null;
|
|
60
|
+
sharedState.token = null;
|
|
61
|
+
sharedState.startTime = null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Direct access to state (for debugging)
|
|
66
|
+
*/
|
|
67
|
+
export function getState() {
|
|
68
|
+
return sharedState;
|
|
69
|
+
}
|