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.
Files changed (142) hide show
  1. package/.github/workflows/publish.yaml +15 -7
  2. package/.github/workflows/testdriver.yml +163 -0
  3. package/.testdriver/last-sandbox +7 -0
  4. package/agent/events.js +1 -0
  5. package/agent/index.js +99 -163
  6. package/agent/lib/sandbox.js +11 -1
  7. package/agents.md +393 -0
  8. package/bin/testdriverai.js +8 -0
  9. package/debug/01-table-initial.png +0 -0
  10. package/debug/02-after-ai-explore.png +0 -0
  11. package/debug/02-after-scroll.png +0 -0
  12. package/debugger/index.html +37 -0
  13. package/docs/docs.json +93 -125
  14. package/docs/v7/_drafts/architecture.mdx +1 -26
  15. package/docs/v7/_drafts/caching.mdx +2 -2
  16. package/docs/v7/{getting-started → _drafts}/installation.mdx +0 -66
  17. package/docs/v7/{features/coverage.mdx → _drafts/powerful.mdx} +1 -90
  18. package/docs/v7/_drafts/quick-start-test-recording.mdx +0 -1
  19. package/docs/v7/{features → _drafts}/scalable.mdx +126 -4
  20. package/docs/v7/_drafts/screenshot.mdx +155 -0
  21. package/docs/v7/_drafts/test-recording.mdx +0 -6
  22. package/docs/v7/_drafts/writing-tests.mdx +25 -0
  23. package/docs/v7/{api/act.mdx → ai.mdx} +28 -27
  24. package/docs/v7/{api/assert.mdx → assert.mdx} +3 -3
  25. package/docs/v7/aws-setup.mdx +338 -0
  26. package/docs/v7/caching.mdx +128 -0
  27. package/docs/v7/ci-cd.mdx +605 -0
  28. package/docs/v7/{api/click.mdx → click.mdx} +4 -4
  29. package/docs/v7/cloud.mdx +120 -0
  30. package/docs/v7/customizing-devices.mdx +129 -0
  31. package/docs/v7/{api/doubleClick.mdx → double-click.mdx} +5 -5
  32. package/docs/v7/enterprise.mdx +135 -0
  33. package/docs/v7/examples.mdx +5 -0
  34. package/docs/v7/{api/exec.mdx → exec.mdx} +3 -3
  35. package/docs/v7/{api/find.mdx → find.mdx} +17 -21
  36. package/docs/v7/{api/focusApplication.mdx → focus-application.mdx} +3 -3
  37. package/docs/v7/generating-tests.mdx +32 -0
  38. package/docs/v7/{api/hover.mdx → hover.mdx} +3 -3
  39. package/docs/v7/locating-elements.mdx +71 -0
  40. package/docs/v7/making-assertions.mdx +32 -0
  41. package/docs/v7/{api/mouseDown.mdx → mouse-down.mdx} +7 -7
  42. package/docs/v7/{api/mouseUp.mdx → mouse-up.mdx} +8 -8
  43. package/docs/v7/performing-actions.mdx +51 -0
  44. package/docs/v7/{api/pressKeys.mdx → press-keys.mdx} +3 -3
  45. package/docs/v7/quickstart.mdx +162 -0
  46. package/docs/v7/reusable-code.mdx +240 -0
  47. package/docs/v7/{api/rightClick.mdx → right-click.mdx} +5 -5
  48. package/docs/v7/running-tests.mdx +181 -0
  49. package/docs/v7/{api/scroll.mdx → scroll.mdx} +3 -3
  50. package/docs/v7/secrets.mdx +115 -0
  51. package/docs/v7/self-hosted.mdx +66 -0
  52. package/docs/v7/{api/type.mdx → type.mdx} +3 -3
  53. package/docs/v7/variables.mdx +111 -0
  54. package/docs/v7/waiting-for-elements.mdx +66 -0
  55. package/docs/v7/what-is-testdriver.mdx +54 -0
  56. package/interfaces/cli/commands/init.js +33 -19
  57. package/interfaces/cli/lib/base.js +24 -0
  58. package/interfaces/cli.js +8 -1
  59. package/interfaces/logger.js +8 -3
  60. package/interfaces/vitest-plugin.mjs +16 -71
  61. package/lib/sentry.js +343 -0
  62. package/lib/vitest/hooks.mjs +81 -81
  63. package/package.json +4 -3
  64. package/sdk-log-formatter.js +41 -0
  65. package/sdk.d.ts +22 -9
  66. package/sdk.js +344 -100
  67. package/test/manual/reconnect-provision.test.mjs +49 -0
  68. package/test/manual/reconnect-signin.test.mjs +41 -0
  69. package/test/testdriver/act.test.mjs +30 -0
  70. package/test/testdriver/ai.test.mjs +30 -0
  71. package/test/testdriver/assert.test.mjs +1 -1
  72. package/test/testdriver/hover-text.test.mjs +1 -1
  73. package/test/testdriver/setup/testHelpers.mjs +8 -119
  74. package/test/testdriver/windows-installer.test.mjs +61 -0
  75. package/tests/example.test.js +33 -0
  76. package/tests/login.js +28 -0
  77. package/tests/table-sort-enrollments.test.mjs +72 -0
  78. package/tests/table-sort-experiment.test.mjs +42 -0
  79. package/tests/table-sort-setup.test.mjs +59 -0
  80. package/vitest.config.mjs +3 -1
  81. package/agent/lib/cache.js +0 -142
  82. package/docs/v7/api/assertions.mdx +0 -403
  83. package/docs/v7/features/ai-native.mdx +0 -413
  84. package/docs/v7/features/application-logs.mdx +0 -353
  85. package/docs/v7/features/browser-logs.mdx +0 -414
  86. package/docs/v7/features/cache-management.mdx +0 -402
  87. package/docs/v7/features/continuous-testing.mdx +0 -346
  88. package/docs/v7/features/data-driven-testing.mdx +0 -441
  89. package/docs/v7/features/easy-to-write.mdx +0 -280
  90. package/docs/v7/features/enterprise.mdx +0 -656
  91. package/docs/v7/features/fast.mdx +0 -406
  92. package/docs/v7/features/managed-sandboxes.mdx +0 -384
  93. package/docs/v7/features/network-monitoring.mdx +0 -568
  94. package/docs/v7/features/parallel-execution.mdx +0 -381
  95. package/docs/v7/features/powerful.mdx +0 -531
  96. package/docs/v7/features/sandbox-customization.mdx +0 -229
  97. package/docs/v7/features/stable.mdx +0 -473
  98. package/docs/v7/features/system-performance.mdx +0 -616
  99. package/docs/v7/features/test-analytics.mdx +0 -373
  100. package/docs/v7/features/test-cases.mdx +0 -393
  101. package/docs/v7/features/test-replays.mdx +0 -408
  102. package/docs/v7/features/test-reports.mdx +0 -308
  103. package/docs/v7/getting-started/debugging-tests.mdx +0 -382
  104. package/docs/v7/getting-started/quickstart.mdx +0 -90
  105. package/docs/v7/getting-started/running-tests.mdx +0 -173
  106. package/docs/v7/getting-started/setting-up-in-ci.mdx +0 -612
  107. package/docs/v7/getting-started/writing-tests.mdx +0 -534
  108. package/docs/v7/overview/what-is-testdriver.mdx +0 -386
  109. package/docs/v7/presets/chrome-extension.mdx +0 -248
  110. package/docs/v7/presets/chrome.mdx +0 -300
  111. package/docs/v7/presets/electron.mdx +0 -460
  112. package/docs/v7/presets/vscode.mdx +0 -417
  113. package/docs/v7/presets/webapp.mdx +0 -393
  114. /package/docs/v7/{commands → _drafts/commands}/assert.mdx +0 -0
  115. /package/docs/v7/{commands → _drafts/commands}/exec.mdx +0 -0
  116. /package/docs/v7/{commands → _drafts/commands}/focus-application.mdx +0 -0
  117. /package/docs/v7/{commands → _drafts/commands}/hover-image.mdx +0 -0
  118. /package/docs/v7/{commands → _drafts/commands}/hover-text.mdx +0 -0
  119. /package/docs/v7/{commands → _drafts/commands}/if.mdx +0 -0
  120. /package/docs/v7/{commands → _drafts/commands}/match-image.mdx +0 -0
  121. /package/docs/v7/{commands → _drafts/commands}/press-keys.mdx +0 -0
  122. /package/docs/v7/{commands → _drafts/commands}/remember.mdx +0 -0
  123. /package/docs/v7/{commands → _drafts/commands}/run.mdx +0 -0
  124. /package/docs/v7/{commands → _drafts/commands}/scroll-until-image.mdx +0 -0
  125. /package/docs/v7/{commands → _drafts/commands}/scroll-until-text.mdx +0 -0
  126. /package/docs/v7/{commands → _drafts/commands}/scroll.mdx +0 -0
  127. /package/docs/v7/{commands → _drafts/commands}/type.mdx +0 -0
  128. /package/docs/v7/{commands → _drafts/commands}/wait-for-image.mdx +0 -0
  129. /package/docs/v7/{commands → _drafts/commands}/wait-for-text.mdx +0 -0
  130. /package/docs/v7/{commands → _drafts/commands}/wait.mdx +0 -0
  131. /package/docs/v7/{getting-started → _drafts}/configuration.mdx +0 -0
  132. /package/docs/v7/{features → _drafts}/observable.mdx +0 -0
  133. /package/docs/v7/{platforms → _drafts/platforms}/linux.mdx +0 -0
  134. /package/docs/v7/{platforms → _drafts/platforms}/macos.mdx +0 -0
  135. /package/docs/v7/{platforms → _drafts/platforms}/windows.mdx +0 -0
  136. /package/docs/v7/{playwright.mdx → _drafts/playwright.mdx} +0 -0
  137. /package/docs/v7/{overview → _drafts}/readme.mdx +0 -0
  138. /package/docs/v7/{features → _drafts}/reports.mdx +0 -0
  139. /package/docs/v7/{api/client.mdx → client.mdx} +0 -0
  140. /package/docs/v7/{api/dashcam.mdx → dashcam.mdx} +0 -0
  141. /package/docs/v7/{api/elements.mdx → elements.mdx} +0 -0
  142. /package/docs/v7/{api/sandbox.mdx → sandbox.mdx} +0 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * TestDriver SDK - Reconnect Test Part 1: Provision
3
+ *
4
+ * This test provisions a new sandbox and navigates to the login page.
5
+ * The sandbox ID is saved to .testdriver/last-sandbox for the next test.
6
+ *
7
+ * The sandbox has keepAlive: 120000 (2 minutes) after disconnect.
8
+ * Run reconnect-signin.test.mjs within 2 minutes of this test completing.
9
+ *
10
+ * Usage:
11
+ * 1. npm test -- test/testdriver/reconnect-provision.test.mjs
12
+ * 2. (within 2 minutes) npm test -- test/testdriver/reconnect-signin.test.mjs
13
+ */
14
+
15
+ import { afterAll, describe, expect, it } from "vitest";
16
+ import { TestDriver } from "../../lib/vitest/hooks.mjs";
17
+
18
+ describe("Reconnect Test - Part 1: Provision", () => {
19
+
20
+ afterAll(async () => {
21
+ // Explicitly DO NOT disconnect - we want the sandbox to stay alive
22
+ // for the reconnect test. The sandbox will auto-terminate after keepAlive TTL.
23
+ console.log("\n⚠️ NOT disconnecting - sandbox will stay alive for ~2 minutes (keepAlive: 120000)");
24
+ console.log(" Run reconnect-signin.test.mjs within 2 minutes to test reconnect\n");
25
+ });
26
+
27
+ it("should provision sandbox and navigate to login page", async (context) => {
28
+
29
+ const testdriver = TestDriver(context, { newSandbox: true, headless: false });
30
+
31
+ // Provision Chrome and navigate to login page
32
+ await testdriver.provision.chrome({
33
+ url: 'http://testdriver-sandbox.vercel.app/login',
34
+ });
35
+
36
+
37
+ // Verify we're on the login page
38
+ const result = await testdriver.assert("I can see a Sign In button");
39
+ expect(result).toBeTruthy();
40
+
41
+ // Get the sandbox ID that was saved
42
+ const lastSandbox = testdriver.getLastSandboxId();
43
+ console.log("\n✅ Sandbox provisioned:", lastSandbox?.sandboxId);
44
+ console.log(" Sandbox info saved to .testdriver/last-sandbox");
45
+
46
+ expect(lastSandbox).toBeTruthy();
47
+ expect(lastSandbox.sandboxId).toBeTruthy();
48
+ });
49
+ });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * TestDriver SDK - Reconnect Test Part 2: Sign In
3
+ *
4
+ * This test reconnects to the sandbox provisioned by reconnect-provision.test.mjs
5
+ * and clicks the Sign In button.
6
+ *
7
+ * IMPORTANT: Run this within 2 minutes of reconnect-provision.test.mjs completing.
8
+ * The sandbox auto-terminates after the keepAlive TTL (default 2 minutes).
9
+ *
10
+ * Usage:
11
+ * 1. npm test -- test/testdriver/reconnect-provision.test.mjs
12
+ * 2. (within 2 minutes) npm test -- test/testdriver/reconnect-signin.test.mjs
13
+ */
14
+
15
+ import { describe, expect, it } from "vitest";
16
+ import { TestDriver } from "../../lib/vitest/hooks.mjs";
17
+
18
+ describe("Reconnect Test - Part 2: Sign In", () => {
19
+
20
+ it("should reconnect to existing sandbox and click Sign In", async (context) => {
21
+
22
+ const testdriver = TestDriver(context, { newSandbox: true, headless: false, reconnect: true });
23
+
24
+ // Provision Chrome and navigate to login page
25
+ await testdriver.provision.chrome({
26
+ url: 'http://testdriver-sandbox.vercel.app/login',
27
+ });
28
+
29
+ // Click on Sign In button - the page should already be loaded from provision test
30
+ const signInButton = await testdriver.find(
31
+ "Sign In, black button below the password field",
32
+ );
33
+ await signInButton.click();
34
+
35
+ // Assert that an error shows that fields are required
36
+ const result = await testdriver.assert(
37
+ "an error shows that fields are required",
38
+ );
39
+ expect(result).toBeTruthy();
40
+ });
41
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * TestDriver SDK - Act Test (Vitest)
3
+ * Tests the AI exploratory loop (act) functionality
4
+ */
5
+
6
+ import { describe, expect, it } from "vitest";
7
+ import { TestDriver } from "../../lib/vitest/hooks.mjs";
8
+
9
+ describe("Act Test", () => {
10
+ it("should use act to search for testdriver on Google", async (context) => {
11
+ const testdriver = TestDriver(context, { newSandbox: true });
12
+
13
+ // provision.chrome() automatically calls ready() and starts dashcam
14
+ await testdriver.provision.chrome({
15
+ url: 'https://www.google.com',
16
+ });
17
+
18
+ // Use act to search for testdriver
19
+ let actRes = await testdriver.act("click on the empty search box, type 'testdriver', and hit enter. do not click the plus button in the search bar");
20
+
21
+ console.log("Act response:", actRes);
22
+
23
+ // Assert the search results are displayed
24
+ const result = await testdriver.assert(
25
+ "search results for testdriver are visible",
26
+ );
27
+
28
+ expect(result).toBeTruthy();
29
+ });
30
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * TestDriver SDK - AI Test (Vitest)
3
+ * Tests the AI exploratory loop (ai) functionality
4
+ */
5
+
6
+ import { describe, expect, it } from "vitest";
7
+ import { TestDriver } from "../../lib/vitest/hooks.mjs";
8
+
9
+ describe("AI Test", () => {
10
+ it("should use ai to search for testdriver on Google", async (context) => {
11
+ const testdriver = TestDriver(context, { newSandbox: true });
12
+
13
+ // provision.chrome() automatically calls ready() and starts dashcam
14
+ await testdriver.provision.chrome({
15
+ url: 'https://duckduckgo.com',
16
+ });
17
+
18
+ // Use ai to search for testdriver
19
+ let aiRes = await testdriver.ai("click on the empty search box, type 'testdriver', and hit enter.");
20
+
21
+ console.log("AI response:", aiRes);
22
+
23
+ // Assert the search results are displayed
24
+ const result = await testdriver.assert(
25
+ "search results for testdriver are visible",
26
+ );
27
+
28
+ expect(result).toBeTruthy();
29
+ });
30
+ });
@@ -8,7 +8,7 @@ import { TestDriver } from "../../lib/vitest/hooks.mjs";
8
8
 
9
9
  describe("Assert Test", () => {
10
10
  it("should assert the testdriver login page shows", async (context) => {
11
- const testdriver = TestDriver(context, { newSandbox: true });
11
+ const testdriver = TestDriver(context, { newSandbox: true, headless: false });
12
12
 
13
13
  // provision.chrome() automatically calls ready() and starts dashcam
14
14
  await testdriver.provision.chrome({
@@ -8,7 +8,7 @@ import { TestDriver } from "../../lib/vitest/hooks.mjs";
8
8
 
9
9
  describe("Hover Text Test", () => {
10
10
  it("should click Sign In and verify error message", async (context) => {
11
- const testdriver = TestDriver(context, { headless: true, newSandbox: true, cacheKey: 'hover-text-test' });
11
+ const testdriver = TestDriver(context, { headless: false, newSandbox: true, cacheKey: 'hover-text-test' });
12
12
  await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
13
13
 
14
14
  // Click on Sign In button using new find() API
@@ -5,8 +5,6 @@
5
5
 
6
6
  import crypto from "crypto";
7
7
  import { config } from "dotenv";
8
- import fs from "fs";
9
- import os from "os";
10
8
  import path, { dirname } from "path";
11
9
  import { fileURLToPath } from "url";
12
10
  import TestDriver from "../../../sdk.js";
@@ -51,85 +49,6 @@ console.log(
51
49
  process.env.TD_OS || "Not set (will default to linux)",
52
50
  );
53
51
 
54
- // Global test results storage
55
- const testResults = {
56
- tests: [],
57
- startTime: Date.now(),
58
- };
59
-
60
- /**
61
- * Store test result with dashcam URL
62
- * @param {string} testName - Name of the test
63
- * @param {string} testFile - Test file path
64
- * @param {string|null} dashcamUrl - Dashcam URL if available
65
- * @param {Object} sessionInfo - Session information
66
- */
67
- export function storeTestResult(
68
- testName,
69
- testFile,
70
- dashcamUrl,
71
- sessionInfo = {},
72
- ) {
73
-
74
- // Extract replay object ID from dashcam URL
75
- let replayObjectId = null;
76
- if (dashcamUrl) {
77
- const replayIdMatch = dashcamUrl.match(/\/replay\/([^?]+)/);
78
- replayObjectId = replayIdMatch ? replayIdMatch[1] : null;
79
- if (replayObjectId) {
80
- console.log(` Replay Object ID: ${replayObjectId}`);
81
- }
82
- }
83
-
84
- testResults.tests.push({
85
- name: testName,
86
- file: testFile,
87
- dashcamUrl,
88
- replayObjectId,
89
- sessionId: sessionInfo.sessionId,
90
- timestamp: new Date().toISOString(),
91
- });
92
- }
93
-
94
- /**
95
- * Get all test results
96
- * @returns {Object} All collected test results
97
- */
98
- export function getTestResults() {
99
- return {
100
- ...testResults,
101
- endTime: Date.now(),
102
- duration: Date.now() - testResults.startTime,
103
- };
104
- }
105
-
106
- /**
107
- * Save test results to a JSON file
108
- * @param {string} outputPath - Path to save the results
109
- */
110
- export function saveTestResults(outputPath = "test-results/sdk-summary.json") {
111
- const results = getTestResults();
112
- const dir = path.dirname(outputPath);
113
-
114
- // Create directory if it doesn't exist
115
- if (!fs.existsSync(dir)) {
116
- fs.mkdirSync(dir, { recursive: true });
117
- }
118
-
119
- fs.writeFileSync(outputPath, JSON.stringify(results, null, 2));
120
- console.log(`\n📊 Test results saved to: ${outputPath}`);
121
-
122
- // Also print dashcam URLs to console
123
- console.log("\n🎥 Dashcam URLs:");
124
- results.tests.forEach((test) => {
125
- if (test.dashcamUrl) {
126
- console.log(` ${test.name}: ${test.dashcamUrl}`);
127
- }
128
- });
129
-
130
- return results;
131
- }
132
-
133
52
  /**
134
53
  * Intercept console logs and forward to TestDriver sandbox
135
54
  * @param {TestDriver} client - TestDriver client instance
@@ -494,21 +413,9 @@ export async function teardownTest(client, options = {}) {
494
413
  console.log("⏭️ Postrun skipped (disabled in options)");
495
414
  }
496
415
 
497
- // Write test result to a file for the reporter to pick up (cross-process communication)
416
+ // Use Vitest's task.meta for cross-process communication with the reporter
498
417
  if (options.task) {
499
- const testResultFile = path.join(
500
- os.tmpdir(),
501
- "testdriver-results",
502
- `${options.task.id}.json`,
503
- );
504
-
505
418
  try {
506
- // Ensure directory exists
507
- const dir = path.dirname(testResultFile);
508
- if (!fs.existsSync(dir)) {
509
- fs.mkdirSync(dir, { recursive: true });
510
- }
511
-
512
419
  // Get test file path - make it relative to project root
513
420
  const absolutePath =
514
421
  options.task.file?.filepath || options.task.file?.name || "unknown";
@@ -523,33 +430,15 @@ export async function teardownTest(client, options = {}) {
523
430
  testOrder = options.task.suite.tasks.indexOf(options.task);
524
431
  }
525
432
 
526
- // Note: Duration is calculated by Vitest and passed via result.duration
527
- // We include it in the test result file so the reporter can use it
528
-
529
- // Get duration from Vitest result
530
- const result = options.task.result?.();
531
- const duration = result?.duration || 0;
532
-
533
- // Write test result with dashcam URL, platform, and metadata
534
- const testResult = {
535
- testId: options.task.id,
536
- testName: options.task.name,
537
- testFile: testFile,
538
- testOrder: testOrder,
539
- dashcamUrl: dashcamUrl,
540
- replayObjectId: dashcamUrl
541
- ? dashcamUrl.match(/\/replay\/([^?]+)/)?.[1]
542
- : null,
543
- platform: client.os, // Include platform from SDK client (source of truth)
544
- timestamp: Date.now(),
545
- duration: duration, // Include duration from Vitest
546
- };
547
-
548
- fs.writeFileSync(testResultFile, JSON.stringify(testResult, null, 2));
549
-
433
+ // Set metadata on task for the reporter to pick up
434
+ options.task.meta.dashcamUrl = dashcamUrl;
435
+ options.task.meta.platform = client.os; // Include platform from SDK client (source of truth)
436
+ options.task.meta.testFile = testFile;
437
+ options.task.meta.testOrder = testOrder;
438
+ options.task.meta.sessionId = client.getSessionId?.() || null;
550
439
  } catch (error) {
551
440
  console.error(
552
- `[TestHelpers] ❌ Failed to write test result file:`,
441
+ `[TestHelpers] ❌ Failed to set test metadata:`,
553
442
  error.message,
554
443
  );
555
444
  }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * TestDriver SDK - Windows Installer Example (Vitest)
3
+ *
4
+ * This example demonstrates how to download and install a Windows application
5
+ * using PowerShell commands, then launch and interact with it.
6
+ *
7
+ * Based on the v6 GitButler provisioning workflow.
8
+ *
9
+ * Run: TD_OS=windows npx vitest run examples/windows-installer.test.mjs
10
+ */
11
+
12
+ import { describe, expect, it } from "vitest";
13
+ import { TestDriver } from "../../lib/vitest/hooks.mjs";
14
+
15
+ const isLinux = (process.env.TD_OS || "linux") === "linux";
16
+
17
+ describe("Windows App Installation", () => {
18
+
19
+ it.skipIf(isLinux)("should download, install, and launch GitButler on Windows", async (context) => {
20
+ // Alternative approach using provision.installer helper
21
+ const testdriver = TestDriver(context, {
22
+ newSandbox: true,
23
+ os: 'windows'
24
+ });
25
+
26
+ // Download the MSI installer
27
+ const installerPath = await testdriver.provision.installer({
28
+ url: 'https://app.gitbutler.com/downloads/release/windows/x86_64/msi',
29
+ launch: false, // Don't auto-launch, we'll install manually
30
+ });
31
+
32
+ // The installer should be an .msi or .exe file
33
+ expect(installerPath).toMatch(/\.(msi|exe)$/i);
34
+
35
+ // Install the MSI silently (check which type it is)
36
+ if (installerPath.toLowerCase().endsWith('.msi')) {
37
+ await testdriver.exec('pwsh',
38
+ `Start-Process msiexec.exe -ArgumentList "/i \`"${installerPath}\`" /qn /norestart" -Wait`,
39
+ 120000
40
+ );
41
+ } else {
42
+ await testdriver.exec('pwsh',
43
+ `Start-Process "${installerPath}" -ArgumentList "/S" -Wait`,
44
+ 120000
45
+ );
46
+ }
47
+
48
+ // Verify installation by checking if executable exists
49
+ const verifyScript = `
50
+ $exePath = "C:\\Program Files\\GitButler\\gitbutler-tauri.exe"
51
+ if (Test-Path $exePath) {
52
+ Write-Host "GitButler installed successfully at $exePath"
53
+ } else {
54
+ Write-Error "GitButler not found"
55
+ exit 1
56
+ }
57
+ `;
58
+
59
+ await testdriver.exec('pwsh', verifyScript, 5000);
60
+ });
61
+ });
@@ -0,0 +1,33 @@
1
+ import { test, expect } from 'vitest';
2
+ import { TestDriver } from 'testdriverai/vitest/hooks';
3
+ import { login } from './login.js';
4
+
5
+ test('should login and add item to cart', async (context) => {
6
+
7
+ // Create TestDriver instance - automatically connects to sandbox
8
+ const testdriver = TestDriver(context);
9
+
10
+ // Launch chrome and navigate to demo app
11
+ await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
12
+
13
+ // Use the login snippet to handle authentication
14
+ // This demonstrates how to reuse test logic across multiple tests
15
+ await login(testdriver);
16
+
17
+ // Add item to cart
18
+ const addToCartButton = await testdriver.find(
19
+ 'add to cart button under TestDriver Hat'
20
+ );
21
+ await addToCartButton.click();
22
+
23
+ // Open cart
24
+ const cartButton = await testdriver.find(
25
+ 'cart button in the top right corner'
26
+ );
27
+ await cartButton.click();
28
+
29
+ // Verify item in cart
30
+ const result = await testdriver.assert('TestDriver Hat is in the cart');
31
+ expect(result).toBeTruthy();
32
+
33
+ });
package/tests/login.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Login snippet - reusable login function
3
+ *
4
+ * This demonstrates how to create reusable test snippets that can be
5
+ * imported and used across multiple test files.
6
+ */
7
+ export async function login(testdriver) {
8
+
9
+ // The password is displayed on screen, have TestDriver extract it
10
+ const password = await testdriver.extract('the password');
11
+
12
+ // Find the username field
13
+ const usernameField = await testdriver.find(
14
+ 'Username, label above the username input field on the login form'
15
+ );
16
+ await usernameField.click();
17
+
18
+ // Type username
19
+ await testdriver.type('standard_user');
20
+
21
+ // Enter password form earlier
22
+ // Marked as secret so it's not logged or stored
23
+ await testdriver.pressKeys(['tab']);
24
+ await testdriver.type(password, { secret: true });
25
+
26
+ // Submit the form
27
+ await testdriver.find('submit button on the login form').click();
28
+ }
@@ -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
@@ -10,8 +10,10 @@ export default defineConfig({
10
10
  test: {
11
11
  testTimeout: 900000,
12
12
  hookTimeout: 900000,
13
+ disableConsoleIntercept: true,
14
+ maxConcurrency: 3,
13
15
  reporters: [
14
- 'verbose',
16
+ 'default',
15
17
  TestDriver(),
16
18
  ['junit', { outputFile: 'test-report.junit.xml' }]
17
19
  ],