testdriverai 7.2.20 → 7.2.22
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/README.md +24 -169
- package/docs/v7/_drafts/plugin-migration.mdx +3 -5
- package/package.json +1 -1
- package/test/testdriver/hover-image.test.mjs +19 -1
- package/test/testdriver/hover-text-with-description.test.mjs +19 -1
- package/test/testdriver/match-image.test.mjs +19 -1
- package/test/testdriver/scroll-until-text.test.mjs +19 -1
- package/docs/v7/_drafts/implementation-plan.mdx +0 -994
- package/docs/v7/_drafts/optimal-sdk-design.mdx +0 -1348
- package/docs/v7/_drafts/performance.mdx +0 -517
- package/docs/v7/_drafts/platforms/linux.mdx +0 -308
- package/docs/v7/_drafts/platforms/macos.mdx +0 -433
- package/docs/v7/_drafts/platforms/windows.mdx +0 -430
- package/docs/v7/_drafts/sdk-logging.mdx +0 -222
- package/test/testdriver/setup/globalTeardown.mjs +0 -11
- package/test/testdriver/setup/lifecycleHelpers.mjs +0 -357
- package/test/testdriver/setup/testHelpers.mjs +0 -541
- package/test/testdriver/setup/vitestSetup.mjs +0 -40
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lifecycle Helpers
|
|
3
|
-
* Shared lifecycle hook functions (prerun, postrun)
|
|
4
|
-
*
|
|
5
|
-
* LEGACY: These helpers are thin wrappers around the new Dashcam class.
|
|
6
|
-
* For new code, prefer using the Dashcam class directly:
|
|
7
|
-
*
|
|
8
|
-
* import { Dashcam } from 'testdriverai/core';
|
|
9
|
-
* const dashcam = new Dashcam(client);
|
|
10
|
-
* await dashcam.auth();
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import Dashcam from '../../../lib/core/Dashcam.js';
|
|
14
|
-
|
|
15
|
-
// Module-level cache to maintain Dashcam instance state across helper calls
|
|
16
|
-
const dashcamInstances = new WeakMap();
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get or create Dashcam instance for a client
|
|
20
|
-
* @private
|
|
21
|
-
* @param {TestDriver} client
|
|
22
|
-
* @param {object} options
|
|
23
|
-
* @returns {Dashcam}
|
|
24
|
-
*/
|
|
25
|
-
function getDashcam(client, options = {}) {
|
|
26
|
-
if (!dashcamInstances.has(client)) {
|
|
27
|
-
dashcamInstances.set(client, new Dashcam(client, options));
|
|
28
|
-
}
|
|
29
|
-
return dashcamInstances.get(client);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Authenticate dashcam with API key
|
|
34
|
-
* @deprecated Use `new Dashcam(client)` and `dashcam.auth()` instead
|
|
35
|
-
* @param {TestDriver} client - TestDriver client
|
|
36
|
-
* @param {string} apiKey - Dashcam API key (default: 4e93d8bf-3886-4d26-a144-116c4063522d)
|
|
37
|
-
*/
|
|
38
|
-
export async function authDashcam(
|
|
39
|
-
client,
|
|
40
|
-
apiKey = "4e93d8bf-3886-4d26-a144-116c4063522d",
|
|
41
|
-
) {
|
|
42
|
-
const dashcam = getDashcam(client, { apiKey });
|
|
43
|
-
await dashcam.auth();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Add log file tracking to dashcam
|
|
48
|
-
* @deprecated Use `new Dashcam(client)` and `dashcam.addFileLog()` instead
|
|
49
|
-
* @param {TestDriver} client - TestDriver client
|
|
50
|
-
* @param {string} logName - Name for the log in dashcam (default: "TestDriver Log")
|
|
51
|
-
*/
|
|
52
|
-
export async function addDashcamLog(client, logName = "TestDriver Log") {
|
|
53
|
-
const dashcam = getDashcam(client);
|
|
54
|
-
const logPath = client.os === "windows"
|
|
55
|
-
? "C:\\Users\\testdriver\\Documents\\testdriver.log"
|
|
56
|
-
: "/tmp/testdriver.log";
|
|
57
|
-
|
|
58
|
-
// Create log file first
|
|
59
|
-
if (client.os === "windows") {
|
|
60
|
-
await client.exec("pwsh", `New-Item -ItemType File -Path "${logPath}" -Force`, 10000, true);
|
|
61
|
-
} else {
|
|
62
|
-
await client.exec("sh", `touch ${logPath}`, 10000, true);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
await dashcam.addFileLog(logPath, logName);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Start dashcam recording
|
|
70
|
-
* @deprecated Use `new Dashcam(client)` and `dashcam.start()` instead
|
|
71
|
-
* @param {TestDriver} client - TestDriver client
|
|
72
|
-
*/
|
|
73
|
-
export async function startDashcam(client) {
|
|
74
|
-
const dashcam = getDashcam(client);
|
|
75
|
-
await dashcam.start();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Stop dashcam recording and retrieve URL
|
|
80
|
-
* @deprecated Use `new Dashcam(client)` and `dashcam.stop()` instead
|
|
81
|
-
* @param {TestDriver} client - TestDriver client
|
|
82
|
-
* @returns {Promise<string|null>} Dashcam URL if available
|
|
83
|
-
*/
|
|
84
|
-
export async function stopDashcam(client) {
|
|
85
|
-
console.log("🎬 Stopping dashcam and retrieving URL...");
|
|
86
|
-
const dashcam = getDashcam(client);
|
|
87
|
-
const url = await dashcam.stop();
|
|
88
|
-
|
|
89
|
-
return url;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Launch Chrome browser with guest mode
|
|
94
|
-
* @param {TestDriver} client - TestDriver client
|
|
95
|
-
* @param {string} url - URL to open (default: https://testdriver-sandbox.vercel.app/)
|
|
96
|
-
*/
|
|
97
|
-
export async function launchChrome(
|
|
98
|
-
client,
|
|
99
|
-
url = "http://testdriver-sandbox.vercel.app/",
|
|
100
|
-
) {
|
|
101
|
-
const shell = client.os === "windows" ? "pwsh" : "sh";
|
|
102
|
-
|
|
103
|
-
if (client.os === "windows") {
|
|
104
|
-
await client.exec(
|
|
105
|
-
"pwsh",
|
|
106
|
-
`Start-Process "C:/Program Files/Google/Chrome/Application/chrome.exe" -ArgumentList "--start-maximized", "--guest", "${url}"`,
|
|
107
|
-
30000,
|
|
108
|
-
);
|
|
109
|
-
} else {
|
|
110
|
-
await client.exec(
|
|
111
|
-
shell,
|
|
112
|
-
`google-chrome --start-maximized --disable-fre --no-default-browser-check --no-first-run --no-experiments --guest "${url}" >/dev/null 2>&1 &`,
|
|
113
|
-
30000,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Launch Chrome for Testing browser with custom profile
|
|
120
|
-
* @param {TestDriver} client - TestDriver client
|
|
121
|
-
* @param {string} url - URL to open (default: https://testdriver-sandbox.vercel.app/)
|
|
122
|
-
*/
|
|
123
|
-
export async function launchChromeForTesting(
|
|
124
|
-
client,
|
|
125
|
-
url = "http://testdriver-sandbox.vercel.app/",
|
|
126
|
-
) {
|
|
127
|
-
const shell = client.os === "windows" ? "pwsh" : "sh";
|
|
128
|
-
const userDataDir = client.os === "windows"
|
|
129
|
-
? "C:\\Users\\testdriver\\AppData\\Local\\TestDriver\\Chrome"
|
|
130
|
-
: "/tmp/testdriver-chrome-profile";
|
|
131
|
-
|
|
132
|
-
// Create user data directory and Default profile directory
|
|
133
|
-
const defaultProfileDir = client.os === "windows"
|
|
134
|
-
? `${userDataDir}\\Default`
|
|
135
|
-
: `${userDataDir}/Default`;
|
|
136
|
-
|
|
137
|
-
const createDirCmd = client.os === "windows"
|
|
138
|
-
? `New-Item -ItemType Directory -Path "${defaultProfileDir}" -Force | Out-Null`
|
|
139
|
-
: `mkdir -p "${defaultProfileDir}"`;
|
|
140
|
-
|
|
141
|
-
await client.exec(shell, createDirCmd, 10000, true);
|
|
142
|
-
|
|
143
|
-
// Write Chrome preferences
|
|
144
|
-
const chromePrefs = {
|
|
145
|
-
credentials_enable_service: false,
|
|
146
|
-
profile: {
|
|
147
|
-
password_manager_enabled: false,
|
|
148
|
-
default_content_setting_values: {}
|
|
149
|
-
},
|
|
150
|
-
signin: {
|
|
151
|
-
allowed: false
|
|
152
|
-
},
|
|
153
|
-
sync: {
|
|
154
|
-
requested: false,
|
|
155
|
-
first_setup_complete: true,
|
|
156
|
-
sync_all_os_types: false
|
|
157
|
-
},
|
|
158
|
-
autofill: {
|
|
159
|
-
enabled: false
|
|
160
|
-
},
|
|
161
|
-
local_state: {
|
|
162
|
-
browser: {
|
|
163
|
-
has_seen_welcome_page: true
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const prefsPath = client.os === "windows"
|
|
169
|
-
? `${defaultProfileDir}\\Preferences`
|
|
170
|
-
: `${defaultProfileDir}/Preferences`;
|
|
171
|
-
|
|
172
|
-
const prefsJson = JSON.stringify(chromePrefs, null, 2);
|
|
173
|
-
const writePrefCmd = client.os === "windows"
|
|
174
|
-
? `Set-Content -Path "${prefsPath}" -Value '${prefsJson.replace(/'/g, "''")}'`
|
|
175
|
-
: `cat > "${prefsPath}" << 'EOF'\n${prefsJson}\nEOF`;
|
|
176
|
-
|
|
177
|
-
await client.exec(shell, writePrefCmd, 10000, true);
|
|
178
|
-
|
|
179
|
-
if (client.os === "windows") {
|
|
180
|
-
// Windows Chrome for Testing path would need to be determined
|
|
181
|
-
// For now, fallback to regular Chrome on Windows
|
|
182
|
-
await client.exec(
|
|
183
|
-
"pwsh",
|
|
184
|
-
`Start-Process "C:/Program Files/Google/Chrome/Application/chrome.exe" -ArgumentList "--start-maximized", "--user-data-dir=${userDataDir}", "--disable-fre", "--no-default-browser-check", "--no-first-run", "--no-experiments", "${url}"`,
|
|
185
|
-
30000,
|
|
186
|
-
);
|
|
187
|
-
} else {
|
|
188
|
-
await client.exec(
|
|
189
|
-
shell,
|
|
190
|
-
`chrome-for-testing --start-maximized --disable-fre --no-default-browser-check --no-first-run --no-experiments --user-data-dir=${userDataDir} "${url}" >/dev/null 2>&1 &`,
|
|
191
|
-
30000,
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Launch Chrome for Testing with a Chrome extension loaded
|
|
198
|
-
* Also loads dashcam-chrome extension for web log capture on Linux
|
|
199
|
-
* @param {TestDriver} client - TestDriver client
|
|
200
|
-
* @param {string} extensionPath - Local filesystem path to the unpacked extension directory
|
|
201
|
-
* @param {string} url - URL to open (default: https://testdriver-sandbox.vercel.app/)
|
|
202
|
-
* @example
|
|
203
|
-
* // Clone an extension and launch Chrome with it
|
|
204
|
-
* await client.exec('sh', 'git clone https://github.com/user/extension.git /tmp/extension');
|
|
205
|
-
* await launchChromeExtension(client, '/tmp/extension');
|
|
206
|
-
*/
|
|
207
|
-
export async function launchChromeExtension(
|
|
208
|
-
client,
|
|
209
|
-
extensionPath,
|
|
210
|
-
url = "http://testdriver-sandbox.vercel.app/",
|
|
211
|
-
) {
|
|
212
|
-
const shell = client.os === "windows" ? "pwsh" : "sh";
|
|
213
|
-
const userDataDir = client.os === "windows"
|
|
214
|
-
? "C:\\Users\\testdriver\\AppData\\Local\\TestDriver\\Chrome"
|
|
215
|
-
: "/tmp/testdriver-chrome-profile";
|
|
216
|
-
|
|
217
|
-
// Create user data directory and Default profile directory
|
|
218
|
-
const defaultProfileDir = client.os === "windows"
|
|
219
|
-
? `${userDataDir}\\Default`
|
|
220
|
-
: `${userDataDir}/Default`;
|
|
221
|
-
|
|
222
|
-
const createDirCmd = client.os === "windows"
|
|
223
|
-
? `New-Item -ItemType Directory -Path "${defaultProfileDir}" -Force | Out-Null`
|
|
224
|
-
: `mkdir -p "${defaultProfileDir}"`;
|
|
225
|
-
|
|
226
|
-
await client.exec(shell, createDirCmd, 10000, true);
|
|
227
|
-
|
|
228
|
-
// Write Chrome preferences
|
|
229
|
-
const chromePrefs = {
|
|
230
|
-
credentials_enable_service: false,
|
|
231
|
-
profile: {
|
|
232
|
-
password_manager_enabled: false,
|
|
233
|
-
default_content_setting_values: {}
|
|
234
|
-
},
|
|
235
|
-
signin: {
|
|
236
|
-
allowed: false
|
|
237
|
-
},
|
|
238
|
-
sync: {
|
|
239
|
-
requested: false,
|
|
240
|
-
first_setup_complete: true,
|
|
241
|
-
sync_all_os_types: false
|
|
242
|
-
},
|
|
243
|
-
autofill: {
|
|
244
|
-
enabled: false
|
|
245
|
-
},
|
|
246
|
-
local_state: {
|
|
247
|
-
browser: {
|
|
248
|
-
has_seen_welcome_page: true
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const prefsPath = client.os === "windows"
|
|
254
|
-
? `${defaultProfileDir}\\Preferences`
|
|
255
|
-
: `${defaultProfileDir}/Preferences`;
|
|
256
|
-
|
|
257
|
-
const prefsJson = JSON.stringify(chromePrefs, null, 2);
|
|
258
|
-
const writePrefCmd = client.os === "windows"
|
|
259
|
-
? `Set-Content -Path "${prefsPath}" -Value '${prefsJson.replace(/'/g, "''")}'`
|
|
260
|
-
: `cat > "${prefsPath}" << 'EOF'\n${prefsJson}\nEOF`;
|
|
261
|
-
|
|
262
|
-
await client.exec(shell, writePrefCmd, 10000, true);
|
|
263
|
-
|
|
264
|
-
if (client.os === "windows") {
|
|
265
|
-
// Windows Chrome for Testing path would need to be determined
|
|
266
|
-
// For now, fallback to regular Chrome on Windows
|
|
267
|
-
await client.exec(
|
|
268
|
-
"pwsh",
|
|
269
|
-
`Start-Process "C:/Program Files/Google/Chrome/Application/chrome.exe" -ArgumentList "--start-maximized", "--user-data-dir=${userDataDir}", "--load-extension=${extensionPath}", "${url}"`,
|
|
270
|
-
30000,
|
|
271
|
-
);
|
|
272
|
-
} else {
|
|
273
|
-
// Load both user extension and dashcam-chrome for web log capture
|
|
274
|
-
const extensionsToLoad = `${extensionPath},/usr/lib/node_modules/dashcam-chrome/build`;
|
|
275
|
-
await client.exec(
|
|
276
|
-
shell,
|
|
277
|
-
`chrome-for-testing --start-maximized --disable-fre --no-default-browser-check --no-first-run --no-experiments --user-data-dir=${userDataDir} --load-extension=${extensionsToLoad} "${url}" >/dev/null 2>&1 &`,
|
|
278
|
-
30000,
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Wait for page to load by polling for text
|
|
285
|
-
* @param {TestDriver} client - TestDriver client
|
|
286
|
-
* @param {string} text - Text to wait for
|
|
287
|
-
* @param {number} maxAttempts - Maximum number of attempts (default: 60)
|
|
288
|
-
* @param {number} pollInterval - Interval between polls in ms (default: 5000)
|
|
289
|
-
*/
|
|
290
|
-
export async function waitForPage(
|
|
291
|
-
client,
|
|
292
|
-
text,
|
|
293
|
-
maxAttempts = 60,
|
|
294
|
-
pollInterval = 5000,
|
|
295
|
-
) {
|
|
296
|
-
console.log("Waiting for page to load, looking for text:", text);
|
|
297
|
-
let element;
|
|
298
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
299
|
-
element = await client.find(text);
|
|
300
|
-
if (element.found()) break;
|
|
301
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Run prerun lifecycle hooks
|
|
307
|
-
* Implements lifecycle/prerun.yaml functionality
|
|
308
|
-
* @param {TestDriver} client - TestDriver client
|
|
309
|
-
*/
|
|
310
|
-
export async function runPrerun(client) {
|
|
311
|
-
await authDashcam(client);
|
|
312
|
-
await addDashcamLog(client);
|
|
313
|
-
await startDashcam(client);
|
|
314
|
-
await launchChrome(client);
|
|
315
|
-
await waitForPage(client, "TestDriver.ai Sandbox");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Run prerun lifecycle hooks with Chrome for Testing
|
|
320
|
-
* Implements lifecycle/prerun.yaml functionality using Chrome for Testing
|
|
321
|
-
* @param {TestDriver} client - TestDriver client
|
|
322
|
-
*/
|
|
323
|
-
export async function runPrerunChromeForTesting(client) {
|
|
324
|
-
await authDashcam(client);
|
|
325
|
-
await addDashcamLog(client);
|
|
326
|
-
await startDashcam(client);
|
|
327
|
-
await launchChromeForTesting(client);
|
|
328
|
-
await waitForPage(client, "TestDriver.ai Sandbox");
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Run prerun lifecycle hooks with Chrome extension loaded
|
|
333
|
-
* Implements lifecycle/prerun.yaml functionality with a Chrome extension
|
|
334
|
-
* @param {TestDriver} client - TestDriver client
|
|
335
|
-
* @param {string} extensionPath - Local filesystem path to the unpacked extension directory
|
|
336
|
-
* @example
|
|
337
|
-
* // Clone an extension and run prerun with it
|
|
338
|
-
* await client.exec('sh', 'git clone https://github.com/user/extension.git /tmp/extension');
|
|
339
|
-
* await runPrerunChromeExtension(client, '/tmp/extension');
|
|
340
|
-
*/
|
|
341
|
-
export async function runPrerunChromeExtension(client, extensionPath) {
|
|
342
|
-
await authDashcam(client);
|
|
343
|
-
await addDashcamLog(client);
|
|
344
|
-
await startDashcam(client);
|
|
345
|
-
await launchChromeExtension(client, extensionPath);
|
|
346
|
-
await waitForPage(client, "TestDriver.ai Sandbox");
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Run postrun lifecycle hooks
|
|
351
|
-
* Implements lifecycle/postrun.yaml functionality
|
|
352
|
-
* @param {TestDriver} client - TestDriver client
|
|
353
|
-
* @returns {Promise<string|null>} Dashcam URL if available
|
|
354
|
-
*/
|
|
355
|
-
export async function runPostrun(client) {
|
|
356
|
-
return await stopDashcam(client);
|
|
357
|
-
}
|