testdriverai 7.2.11 → 7.2.13

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.
@@ -1,7 +1,7 @@
1
1
  {
2
- "sandboxId": "i-034317335b2eb9678",
3
- "os": "windows",
2
+ "sandboxId": "i4kn8zrl6y0483ooe10pl",
3
+ "os": "linux",
4
4
  "ami": null,
5
5
  "instanceType": null,
6
- "timestamp": "2025-12-22T23:09:20.319Z"
6
+ "timestamp": "2026-01-06T19:39:48.956Z"
7
7
  }
@@ -110,10 +110,8 @@ commands:
110
110
  case "hover-text":
111
111
  emitter.emit(events.log.log, generator.jsonToManual(object));
112
112
  response = await commands["hover-text"](
113
- object.text,
114
113
  object.description,
115
114
  object.action,
116
- object.method,
117
115
  object.timeout,
118
116
  );
119
117
  break;
@@ -719,47 +719,40 @@ const createCommands = (
719
719
  hover: hover,
720
720
  /**
721
721
  * Hover over text on screen
722
- * @param {Object|string} options - Options object or text (for backward compatibility)
723
- * @param {string} options.text - Text to find and hover over
724
- * @param {string|null} [options.description] - Optional description of the element
722
+ * @param {Object|string} options - Options object or description (for backward compatibility)
723
+ * @param {string} options.description - Description of the element to find
725
724
  * @param {string} [options.action='click'] - Action to perform
726
725
  * @param {number} [options.timeout=5000] - Timeout in milliseconds
727
726
  */
728
727
  "hover-text": async (...args) => {
729
- let text, description, action, timeout;
728
+ let description, action, timeout;
730
729
 
731
730
  // Handle both object and positional argument styles
732
- if (isObjectArgs(args, ['text', 'description', 'action', 'timeout'])) {
733
- ({ text, description = null, action = 'click', timeout = 5000 } = args[0]);
731
+ if (isObjectArgs(args, ['description', 'action', 'timeout'])) {
732
+ ({ description, action = 'click', timeout = 5000 } = args[0]);
734
733
  } else {
735
- // Legacy positional: hoverText(text, description, action, timeout)
736
- [text, description = null, action = 'click', timeout = 5000] = args;
734
+ // Legacy positional: hoverText(description, action, timeout)
735
+ [description, action = 'click', timeout = 5000] = args;
736
+ }
737
+
738
+ if (!description) {
739
+ throw new CommandError("hover-text requires a description parameter");
737
740
  }
738
741
 
742
+ description = description.toString();
743
+
739
744
  emitter.emit(
740
745
  events.log.narration,
741
- theme.dim(
742
- `searching for "${text}"${description ? ` (${description})` : ""}...`,
743
- ),
746
+ theme.dim(`searching for "${description}"...`),
744
747
  );
745
748
 
746
- text = text ? text.toString() : null;
747
-
748
749
  // wait for the text to appear on screen
749
- await commands["wait-for-text"]({ text, timeout });
750
-
751
- description = description ? description.toString() : null;
750
+ await commands["wait-for-text"]({ text: description, timeout });
752
751
 
753
752
  emitter.emit(events.log.narration, theme.dim("thinking..."), true);
754
753
 
755
- // Combine text and description into element parameter
756
- let element = text;
757
- if (description) {
758
- element = `"${text}" with description ${description}`;
759
- }
760
-
761
754
  let response = await sdk.req("find", {
762
- element,
755
+ element: description,
763
756
  image: await system.captureScreenBase64(),
764
757
  });
765
758
 
@@ -0,0 +1,320 @@
1
+ ---
2
+ title: "Configuring the Device"
3
+ description: "Launch browsers, desktop apps, and extensions in your TestDriver sandbox"
4
+ icon: "wrench"
5
+ ---
6
+
7
+ Provision methods are the starting point for most tests. They launch applications in your sandbox and prepare the environment for testing.
8
+
9
+ ## Chrome Browser
10
+
11
+ The most common starting point for web testing. Launches Chrome browser and navigates to a URL.
12
+
13
+ ```javascript
14
+ await testdriver.provision.chrome({
15
+ url: 'https://example.com',
16
+ });
17
+ ```
18
+
19
+ ### Options
20
+
21
+ | Option | Type | Default | Description |
22
+ |--------|------|---------|-------------|
23
+ | `url` | string | `'http://testdriver-sandbox.vercel.app/'` | URL to navigate to |
24
+ | `maximized` | boolean | `true` | Start browser maximized |
25
+ | `guest` | boolean | `false` | Use guest mode (no profile) |
26
+
27
+ ### Example: Basic Web Test
28
+
29
+ ```javascript
30
+ import { describe, expect, it } from "vitest";
31
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
32
+
33
+ describe("Login Flow", () => {
34
+ it("should log in successfully", async (context) => {
35
+ const testdriver = TestDriver(context, { newSandbox: true });
36
+
37
+ await testdriver.provision.chrome({
38
+ url: 'https://myapp.com/login',
39
+ });
40
+
41
+ await testdriver.find("Email input").click();
42
+ await testdriver.type("user@example.com");
43
+
44
+ await testdriver.find("Password input").click();
45
+ await testdriver.type("password123");
46
+
47
+ await testdriver.find("Sign In button").click();
48
+
49
+ const result = await testdriver.assert("the dashboard is visible");
50
+ expect(result).toBeTruthy();
51
+ });
52
+ });
53
+ ```
54
+
55
+ <Info>
56
+ `provision.chrome()` automatically starts Dashcam recording and waits for Chrome to be ready before returning.
57
+ </Info>
58
+
59
+ ---
60
+
61
+ ## Chrome Extensions
62
+
63
+ Launch Chrome with a custom extension loaded. Supports both local extensions and Chrome Web Store extensions.
64
+
65
+ ### Load from Local Path
66
+
67
+ Clone or create an extension locally, then load it:
68
+
69
+ ```javascript
70
+ // First, get the extension onto the sandbox
71
+ await testdriver.exec(
72
+ 'sh',
73
+ 'git clone https://github.com/user/my-extension.git /tmp/my-extension',
74
+ 60000
75
+ );
76
+
77
+ // Launch Chrome with the extension
78
+ await testdriver.provision.chromeExtension({
79
+ extensionPath: '/tmp/my-extension',
80
+ url: 'https://example.com'
81
+ });
82
+ ```
83
+
84
+ ### Load from Chrome Web Store
85
+
86
+ Load any published extension by its Chrome Web Store ID:
87
+
88
+ ```javascript
89
+ await testdriver.provision.chromeExtension({
90
+ extensionId: 'cjpalhdlnbpafiamejdnhcphjbkeiagm', // uBlock Origin
91
+ url: 'https://example.com'
92
+ });
93
+ ```
94
+
95
+ <Tip>
96
+ Find the extension ID in the Chrome Web Store URL. For example, `https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm` → ID is `cjpalhdlnbpafiamejdnhcphjbkeiagm`
97
+ </Tip>
98
+
99
+ ### Options
100
+
101
+ | Option | Type | Default | Description |
102
+ |--------|------|---------|-------------|
103
+ | `extensionPath` | string | - | Local path to unpacked extension directory |
104
+ | `extensionId` | string | - | Chrome Web Store extension ID |
105
+ | `url` | string | - | URL to navigate to after launch |
106
+ | `maximized` | boolean | `true` | Start browser maximized |
107
+
108
+ <Warning>
109
+ You must provide either `extensionPath` or `extensionId`, but not both.
110
+ </Warning>
111
+
112
+ ### Example: Testing a Chrome Extension
113
+
114
+ ```javascript
115
+ import { describe, expect, it } from "vitest";
116
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
117
+
118
+ describe("Chrome Extension Test", () => {
119
+ it("should load and interact with extension", async (context) => {
120
+ const testdriver = TestDriver(context, { newSandbox: true });
121
+
122
+ // Clone extension from GitHub
123
+ await testdriver.ready();
124
+ await testdriver.exec(
125
+ 'sh',
126
+ 'git clone https://github.com/user/my-extension.git /tmp/my-extension',
127
+ 60000,
128
+ true
129
+ );
130
+
131
+ // Launch Chrome with extension loaded
132
+ await testdriver.provision.chromeExtension({
133
+ extensionPath: '/tmp/my-extension',
134
+ url: 'https://testdriver.ai'
135
+ });
136
+
137
+ // Click extensions puzzle icon
138
+ const extensionsButton = await testdriver.find("puzzle-shaped icon in Chrome toolbar");
139
+ await extensionsButton.click();
140
+
141
+ // Interact with your extension
142
+ const myExtension = await testdriver.find("My Extension in the dropdown");
143
+ await myExtension.click();
144
+
145
+ const result = await testdriver.assert("extension popup is visible");
146
+ expect(result).toBeTruthy();
147
+ });
148
+ });
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Desktop Apps
154
+
155
+ Download and install desktop applications. Supports `.deb`, `.rpm`, `.msi`, `.exe`, `.AppImage`, `.dmg`, `.pkg`, and shell scripts.
156
+
157
+ ```javascript
158
+ const filePath = await testdriver.provision.installer({
159
+ url: 'https://example.com/app.deb',
160
+ appName: 'MyApp', // Focus this app after install
161
+ launch: true, // Auto-launch after install
162
+ });
163
+ ```
164
+
165
+ ### Options
166
+
167
+ | Option | Type | Default | Description |
168
+ |--------|------|---------|-------------|
169
+ | `url` | string | **required** | URL to download the installer from |
170
+ | `filename` | string | auto-detected | Filename to save as |
171
+ | `appName` | string | - | Application name to focus after install |
172
+ | `launch` | boolean | `true` | Launch the app after installation |
173
+
174
+ ### Supported File Types
175
+
176
+ | Extension | OS | Install Method |
177
+ |-----------|-----|----------------|
178
+ | `.deb` | Linux | `dpkg -i` + `apt-get install -f` |
179
+ | `.rpm` | Linux | `rpm -i` |
180
+ | `.AppImage` | Linux | `chmod +x` |
181
+ | `.sh` | Linux | `chmod +x` + execute |
182
+ | `.msi` | Windows | `msiexec /i /quiet` |
183
+ | `.exe` | Windows | Silent install (`/S`) |
184
+ | `.dmg` | macOS | Mount + copy to Applications |
185
+ | `.pkg` | macOS | `installer -pkg` |
186
+
187
+ ### Example: Install and Test a Desktop App
188
+
189
+ ```javascript
190
+ import { describe, expect, it } from "vitest";
191
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
192
+
193
+ describe("Desktop App Test", () => {
194
+ it("should install and launch app", async (context) => {
195
+ const testdriver = TestDriver(context, { newSandbox: true });
196
+
197
+ // Download and install
198
+ const installerPath = await testdriver.provision.installer({
199
+ url: 'https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_amd64.deb',
200
+ });
201
+
202
+ // Verify installation
203
+ const output = await testdriver.exec('sh', 'bat --version', 5000);
204
+ expect(output).toContain('bat');
205
+ });
206
+ });
207
+ ```
208
+
209
+ ### Example: Windows Installer
210
+
211
+ ```javascript
212
+ import { describe, expect, it } from "vitest";
213
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
214
+
215
+ describe("Windows App Test", () => {
216
+ it("should install on Windows", async (context) => {
217
+ const testdriver = TestDriver(context, {
218
+ newSandbox: true,
219
+ os: 'windows'
220
+ });
221
+
222
+ // Download MSI installer
223
+ const installerPath = await testdriver.provision.installer({
224
+ url: 'https://example.com/app.msi',
225
+ launch: false, // Don't auto-launch
226
+ });
227
+
228
+ // Custom installation if needed
229
+ await testdriver.exec(
230
+ 'pwsh',
231
+ `Start-Process msiexec.exe -ArgumentList "/i", "${installerPath}", "/qn" -Wait`,
232
+ 120000
233
+ );
234
+
235
+ // Verify installation
236
+ const result = await testdriver.assert("application is installed");
237
+ expect(result).toBeTruthy();
238
+ });
239
+ });
240
+ ```
241
+
242
+ ### Manual Installation
243
+
244
+ Set `launch: false` to download without auto-installing:
245
+
246
+ ```javascript
247
+ const filePath = await testdriver.provision.installer({
248
+ url: 'https://example.com/custom-script.sh',
249
+ launch: false,
250
+ });
251
+
252
+ // Run custom install commands
253
+ await testdriver.exec('sh', `chmod +x "${filePath}"`, 5000);
254
+ await testdriver.exec('sh', `"${filePath}" --custom-flag`, 60000);
255
+ ```
256
+
257
+ ---
258
+
259
+ ## VS Code
260
+
261
+ Launch Visual Studio Code with optional workspace and extensions.
262
+
263
+ ```javascript
264
+ await testdriver.provision.vscode({
265
+ workspace: '/home/testdriver/my-project',
266
+ extensions: ['ms-python.python', 'esbenp.prettier-vscode'],
267
+ });
268
+ ```
269
+
270
+ ### Options
271
+
272
+ | Option | Type | Default | Description |
273
+ |--------|------|---------|-------------|
274
+ | `workspace` | string | - | Workspace folder to open |
275
+ | `extensions` | string[] | `[]` | Extensions to install (by ID) |
276
+
277
+ ### Example: VS Code Extension Test
278
+
279
+ ```javascript
280
+ import { describe, expect, it } from "vitest";
281
+ import { TestDriver } from "testdriverai/lib/vitest/hooks.mjs";
282
+
283
+ describe("VS Code Test", () => {
284
+ it("should open workspace with extensions", async (context) => {
285
+ const testdriver = TestDriver(context, { newSandbox: true });
286
+
287
+ // Create a test project
288
+ await testdriver.ready();
289
+ await testdriver.exec('sh', 'mkdir -p /tmp/test-project && echo "print(1)" > /tmp/test-project/test.py', 10000);
290
+
291
+ // Launch VS Code
292
+ await testdriver.provision.vscode({
293
+ workspace: '/tmp/test-project',
294
+ extensions: ['ms-python.python'],
295
+ });
296
+
297
+ // Verify VS Code is ready
298
+ const result = await testdriver.assert("VS Code is open with the project");
299
+ expect(result).toBeTruthy();
300
+
301
+ // Open the Python file
302
+ await testdriver.find("test.py in the explorer").click();
303
+ });
304
+ });
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Choosing the Right Provision Method
310
+
311
+ | Use Case | Method |
312
+ |----------|--------|
313
+ | Testing a website | `provision.chrome` |
314
+ | Testing a Chrome extension | `provision.chromeExtension` |
315
+ | Testing a desktop app (needs installation) | `provision.installer` |
316
+ | Testing VS Code or VS Code extensions | `provision.vscode` |
317
+
318
+ <Tip>
319
+ All provision methods automatically start Dashcam recording and wait for the application to be ready before returning. You don't need to call `dashcam.start()` manually.
320
+ </Tip>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "7.2.11",
3
+ "version": "7.2.13",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "sdk.js",
6
6
  "exports": {
@@ -35,7 +35,7 @@ describe("Chrome Extension Test", () => {
35
35
  // When clicked, it shows a popup with "Hello Extensions"
36
36
 
37
37
  // First, let's verify Chrome loaded and we can see the page
38
- const pageResult = await testdriver.assert("the testdriver.ai website is visible");
38
+ const pageResult = await testdriver.assert("the google.com website is visible");
39
39
  expect(pageResult).toBeTruthy();
40
40
 
41
41
  // Click on the extensions button (puzzle piece icon) in Chrome toolbar
@@ -57,8 +57,7 @@ describe("Chrome Extension Test", () => {
57
57
  // Launch Chrome with Loom loaded by its Chrome Web Store ID
58
58
  // Loom ID: liecbddmkiiihnedobmlmillhodjkdmb
59
59
  await testdriver.provision.chromeExtension({
60
- extensionId: 'liecbddmkiiihnedobmlmillhodjkdmb',
61
- url: 'https://testdriver.ai'
60
+ extensionId: 'liecbddmkiiihnedobmlmillhodjkdmb'
62
61
  });
63
62
 
64
63
  // Click on the extensions button (puzzle piece icon) in Chrome toolbar
@@ -1,30 +0,0 @@
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
- });
@@ -1,33 +0,0 @@
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 DELETED
@@ -1,28 +0,0 @@
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
- }
@@ -1,72 +0,0 @@
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
- });
@@ -1,42 +0,0 @@
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
- });
@@ -1,59 +0,0 @@
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
- });