spana-test 0.6.0 → 0.7.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/.agents/skills/spana-testing/SKILL.md +19 -15
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +3 -3
- package/dist/{app-DcLXtpv4.d.ts → app-D_UyZBsl.d.ts} +9 -2
- package/dist/{chunk-S4JVAHBR.js → chunk-2IXXEXTL.js} +2 -2
- package/dist/{chunk-4K3FZTSV.js → chunk-54ASKII6.js} +6 -2
- package/dist/chunk-54ASKII6.js.map +1 -0
- package/dist/{chunk-KEUZLBQS.js → chunk-6B5Y75V4.js} +544 -79
- package/dist/chunk-6B5Y75V4.js.map +1 -0
- package/dist/{chunk-KBRLIQRA.js → chunk-JYFPZRCN.js} +6 -3
- package/dist/chunk-JYFPZRCN.js.map +1 -0
- package/dist/{chunk-WBBMEAHU.js → chunk-KNSAHEXI.js} +3 -3
- package/dist/{chunk-C4E4XULT.js → chunk-RURZVMZ7.js} +3 -3
- package/dist/{chunk-LCV673G3.js → chunk-T3EBOYLS.js} +154 -26
- package/dist/chunk-T3EBOYLS.js.map +1 -0
- package/dist/{chunk-PWUJT5HE.js → chunk-T5CROOR7.js} +3 -3
- package/dist/cli.js +8 -8
- package/dist/config-loader-NIDQGP3K.js +9 -0
- package/dist/{doctor-command-WEHFANT7.js → doctor-command-WPEVZEZ4.js} +3 -3
- package/dist/{flow-C2JQ7gUu.d.ts → flow-g6AICPAl.d.ts} +1 -1
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-F3X3XPSX.js → html-IKCTZH2U.js} +194 -3
- package/dist/html-IKCTZH2U.js.map +1 -0
- package/dist/index.d.ts +228 -7
- package/dist/index.js +161 -7
- package/dist/index.js.map +1 -1
- package/dist/{screenshot-compare-5NINZVOK.js → screenshot-compare-POTXVUTL.js} +2 -2
- package/dist/{server-OANRDAHN.js → server-EBPYK3VE.js} +4 -4
- package/dist/{server-3MGZNK67.js → server-IGLBFEU7.js} +2 -2
- package/dist/{session-Q3QYHT4Q.js → session-QRWH3SPW.js} +4 -4
- package/dist/{session-Daq0mE_a.d.ts → session-cJ_tZjCL.d.ts} +1 -1
- package/dist/{studio-command-RJYLJT4I.js → studio-command-FLA5HKRK.js} +2 -2
- package/dist/{test-command-ALH5ZQY5.js → test-command-P5W7UD52.js} +7 -7
- package/package.json +2 -1
- package/dist/chunk-4K3FZTSV.js.map +0 -1
- package/dist/chunk-KBRLIQRA.js.map +0 -1
- package/dist/chunk-KEUZLBQS.js.map +0 -1
- package/dist/chunk-LCV673G3.js.map +0 -1
- package/dist/config-loader-J4Z2PMUQ.js +0 -9
- package/dist/html-F3X3XPSX.js.map +0 -1
- /package/dist/{chunk-S4JVAHBR.js.map → chunk-2IXXEXTL.js.map} +0 -0
- /package/dist/{chunk-WBBMEAHU.js.map → chunk-KNSAHEXI.js.map} +0 -0
- /package/dist/{chunk-C4E4XULT.js.map → chunk-RURZVMZ7.js.map} +0 -0
- /package/dist/{chunk-PWUJT5HE.js.map → chunk-T5CROOR7.js.map} +0 -0
- /package/dist/{config-loader-J4Z2PMUQ.js.map → config-loader-NIDQGP3K.js.map} +0 -0
- /package/dist/{doctor-command-WEHFANT7.js.map → doctor-command-WPEVZEZ4.js.map} +0 -0
- /package/dist/{screenshot-compare-5NINZVOK.js.map → screenshot-compare-POTXVUTL.js.map} +0 -0
- /package/dist/{server-OANRDAHN.js.map → server-EBPYK3VE.js.map} +0 -0
- /package/dist/{server-3MGZNK67.js.map → server-IGLBFEU7.js.map} +0 -0
- /package/dist/{session-Q3QYHT4Q.js.map → session-QRWH3SPW.js.map} +0 -0
- /package/dist/{studio-command-RJYLJT4I.js.map → studio-command-FLA5HKRK.js.map} +0 -0
- /package/dist/{test-command-ALH5ZQY5.js.map → test-command-P5W7UD52.js.map} +0 -0
|
@@ -16,13 +16,13 @@ import {
|
|
|
16
16
|
parseWebHierarchy,
|
|
17
17
|
resolveNetworkConditions,
|
|
18
18
|
setupUiAutomator2
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-T5CROOR7.js";
|
|
20
20
|
import {
|
|
21
21
|
CdpDomChannel,
|
|
22
22
|
DriverError,
|
|
23
23
|
createSpanaBridgeChannel,
|
|
24
24
|
makeElectrobunDriver
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-T3EBOYLS.js";
|
|
26
26
|
import {
|
|
27
27
|
setupWDA
|
|
28
28
|
} from "./chunk-HYSTRWYN.js";
|
|
@@ -509,6 +509,12 @@ function makeLightweightCdpDriver(options) {
|
|
|
509
509
|
}),
|
|
510
510
|
cdpChannel.sendCommand("Runtime.enable", {}, sessionId).catch(() => {
|
|
511
511
|
}),
|
|
512
|
+
cdpChannel.sendCommand(
|
|
513
|
+
"Target.setAutoAttach",
|
|
514
|
+
{ autoAttach: true, waitForDebuggerOnStart: false, flatten: true },
|
|
515
|
+
sessionId
|
|
516
|
+
).catch(() => {
|
|
517
|
+
}),
|
|
512
518
|
...needsNetworkDomain ? [cdpChannel.sendCommand("Network.enable", {}, sessionId).catch(() => {
|
|
513
519
|
})] : [],
|
|
514
520
|
cdpChannel.sendCommand(
|
|
@@ -619,6 +625,40 @@ function makeLightweightCdpDriver(options) {
|
|
|
619
625
|
prefetchedSlotPromise = void 0;
|
|
620
626
|
});
|
|
621
627
|
};
|
|
628
|
+
cdpChannel.onEvent("Target.attachedToTarget", (params) => {
|
|
629
|
+
const targetInfo = params?.targetInfo;
|
|
630
|
+
const childSid = params?.sessionId;
|
|
631
|
+
if (targetInfo?.type === "iframe" && typeof childSid === "string") {
|
|
632
|
+
cdpChannel.addChildSession(childSid, {
|
|
633
|
+
targetId: typeof targetInfo.targetId === "string" ? targetInfo.targetId : void 0,
|
|
634
|
+
url: typeof targetInfo.url === "string" ? targetInfo.url : void 0
|
|
635
|
+
});
|
|
636
|
+
void cdpChannel.sendCommand("Runtime.enable", {}, childSid).catch(() => {
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
cdpChannel.onEvent("Target.detachedFromTarget", (params) => {
|
|
641
|
+
if (typeof params?.sessionId === "string") {
|
|
642
|
+
cdpChannel.removeChildSession(params.sessionId);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
cdpChannel.setFrameOffsetResolver(async (child) => {
|
|
646
|
+
if (!child.targetId) return { x: 0, y: 0 };
|
|
647
|
+
try {
|
|
648
|
+
await cdpChannel.sendCommand("DOM.enable");
|
|
649
|
+
const owner = await cdpChannel.sendCommand("DOM.getFrameOwner", {
|
|
650
|
+
frameId: child.targetId
|
|
651
|
+
});
|
|
652
|
+
const boxParams = owner.backendNodeId ? { backendNodeId: owner.backendNodeId } : { nodeId: owner.nodeId };
|
|
653
|
+
const box = await cdpChannel.sendCommand("DOM.getBoxModel", boxParams);
|
|
654
|
+
const quad = box?.model?.content ?? box?.model?.border;
|
|
655
|
+
if (Array.isArray(quad) && quad.length >= 2) {
|
|
656
|
+
return { x: quad[0] ?? 0, y: quad[1] ?? 0 };
|
|
657
|
+
}
|
|
658
|
+
} catch {
|
|
659
|
+
}
|
|
660
|
+
return { x: 0, y: 0 };
|
|
661
|
+
});
|
|
622
662
|
cdpChannel.onEvent("Runtime.consoleAPICalled", (params, sid) => {
|
|
623
663
|
if (activeSlot && sid && sid !== activeSlot.sessionId) return;
|
|
624
664
|
const args = Array.isArray(params?.args) ? params.args.map((a) => a.value ?? a.description ?? "").join(" ") : "";
|
|
@@ -717,6 +757,7 @@ function makeLightweightCdpDriver(options) {
|
|
|
717
757
|
try: async () => {
|
|
718
758
|
consoleLogs.length = 0;
|
|
719
759
|
jsErrors.length = 0;
|
|
760
|
+
cdpChannel.clearChildSessions();
|
|
720
761
|
if (useContexts && options.freshContextPerFlow && hasRunFirstFlow) {
|
|
721
762
|
const previousSlot = activeSlot;
|
|
722
763
|
const pending = prefetchedSlotPromise;
|
|
@@ -1260,19 +1301,35 @@ function buildEngineConfig(appId, platform, parseFn, config, screenSize) {
|
|
|
1260
1301
|
visualRegression: config.visualRegression
|
|
1261
1302
|
};
|
|
1262
1303
|
}
|
|
1304
|
+
function resolveWebEngine(config) {
|
|
1305
|
+
const webExecution = config.execution?.web;
|
|
1306
|
+
const requested = webExecution?.engine;
|
|
1307
|
+
if (requested === "cdp" || requested === "lightpanda" || requested === "playwright") {
|
|
1308
|
+
return requested;
|
|
1309
|
+
}
|
|
1310
|
+
if (requested === "auto") {
|
|
1311
|
+
const isChromium = (webExecution?.browser ?? "chromium") === "chromium";
|
|
1312
|
+
const needsPlaywrightOnly = Boolean(
|
|
1313
|
+
webExecution?.wsEndpoint || webExecution?.channel || config.artifacts?.har
|
|
1314
|
+
);
|
|
1315
|
+
return isChromium && !needsPlaywrightOnly ? "cdp" : "playwright";
|
|
1316
|
+
}
|
|
1317
|
+
return "playwright";
|
|
1318
|
+
}
|
|
1263
1319
|
function speculativelyPrelaunchWebBrowser(config) {
|
|
1264
1320
|
const webExecution = config.execution?.web;
|
|
1265
|
-
|
|
1321
|
+
const engine = resolveWebEngine(config);
|
|
1322
|
+
if (engine === "lightpanda") {
|
|
1266
1323
|
return void 0;
|
|
1267
1324
|
}
|
|
1268
|
-
if (
|
|
1269
|
-
if (webExecution
|
|
1270
|
-
const useWarm2 = webExecution
|
|
1325
|
+
if (engine === "cdp") {
|
|
1326
|
+
if (webExecution?.cdpUrl) return void 0;
|
|
1327
|
+
const useWarm2 = webExecution?.warmBrowser ?? config.execution?.warmDaemons?.enabled ?? false;
|
|
1271
1328
|
const cdpBrowserPromise = launchDirectCdpBrowser({
|
|
1272
|
-
executablePath: webExecution
|
|
1273
|
-
headless: webExecution
|
|
1329
|
+
executablePath: webExecution?.executablePath,
|
|
1330
|
+
headless: webExecution?.headless ?? true,
|
|
1274
1331
|
warmBrowser: useWarm2,
|
|
1275
|
-
warmBrowserScope: webExecution
|
|
1332
|
+
warmBrowserScope: webExecution?.warmBrowserScope ? `${webExecution.warmBrowserScope}-w0` : void 0
|
|
1276
1333
|
});
|
|
1277
1334
|
cdpBrowserPromise.catch(() => {
|
|
1278
1335
|
});
|
|
@@ -1305,15 +1362,16 @@ async function buildWebRuntime(config, prelaunched) {
|
|
|
1305
1362
|
const prelaunchedBrowser = prelaunched && !prelaunched.cdpBrowserPromise ? await prelaunched.browserPromise : void 0;
|
|
1306
1363
|
let launchedDirectCdp;
|
|
1307
1364
|
let rawDriver;
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1365
|
+
const engine = resolveWebEngine(config);
|
|
1366
|
+
if (engine === "cdp" || engine === "lightpanda") {
|
|
1367
|
+
let targetCdpUrl = webExecution?.cdpUrl;
|
|
1368
|
+
const useContexts = engine === "cdp";
|
|
1369
|
+
if (!targetCdpUrl && engine === "cdp") {
|
|
1312
1370
|
launchedDirectCdp = prelaunched?.cdpBrowserPromise ? await prelaunched.cdpBrowserPromise : await launchDirectCdpBrowser({
|
|
1313
|
-
executablePath: webExecution
|
|
1314
|
-
headless: webExecution
|
|
1315
|
-
warmBrowser: webExecution
|
|
1316
|
-
warmBrowserScope: webExecution
|
|
1371
|
+
executablePath: webExecution?.executablePath,
|
|
1372
|
+
headless: webExecution?.headless ?? true,
|
|
1373
|
+
warmBrowser: webExecution?.warmBrowser ?? config.execution?.warmDaemons?.enabled ?? false,
|
|
1374
|
+
warmBrowserScope: webExecution?.warmBrowserScope ? `${webExecution.warmBrowserScope}-w0` : void 0
|
|
1317
1375
|
});
|
|
1318
1376
|
targetCdpUrl = launchedDirectCdp.browserWsUrl;
|
|
1319
1377
|
}
|
|
@@ -1321,14 +1379,14 @@ async function buildWebRuntime(config, prelaunched) {
|
|
|
1321
1379
|
makeLightweightCdpDriver({
|
|
1322
1380
|
cdpUrl: targetCdpUrl ?? "http://127.0.0.1:9222",
|
|
1323
1381
|
baseUrl: webUrl,
|
|
1324
|
-
engineLabel:
|
|
1382
|
+
engineLabel: engine,
|
|
1325
1383
|
useBrowserContexts: useContexts,
|
|
1326
|
-
freshContextPerFlow: webExecution
|
|
1327
|
-
waitUntil: webExecution
|
|
1328
|
-
instantAnimations: webExecution
|
|
1329
|
-
blockResources: webExecution
|
|
1330
|
-
virtualAuthenticator: webExecution
|
|
1331
|
-
storageState: webExecution
|
|
1384
|
+
freshContextPerFlow: webExecution?.freshContextPerFlow,
|
|
1385
|
+
waitUntil: webExecution?.waitUntil,
|
|
1386
|
+
instantAnimations: webExecution?.instantAnimations,
|
|
1387
|
+
blockResources: webExecution?.blockResources,
|
|
1388
|
+
virtualAuthenticator: webExecution?.virtualAuthenticator,
|
|
1389
|
+
storageState: webExecution?.storageState
|
|
1332
1390
|
})
|
|
1333
1391
|
);
|
|
1334
1392
|
} else {
|
|
@@ -1379,29 +1437,30 @@ async function buildWebRuntime(config, prelaunched) {
|
|
|
1379
1437
|
}
|
|
1380
1438
|
async function buildWebRuntimePool(config, workerCount, prelaunched) {
|
|
1381
1439
|
const webExecution = config.execution?.web;
|
|
1382
|
-
|
|
1440
|
+
const engine = resolveWebEngine(config);
|
|
1441
|
+
if (workerCount <= 1 || engine === "lightpanda") {
|
|
1383
1442
|
return [await buildWebRuntime(config, prelaunched)];
|
|
1384
1443
|
}
|
|
1385
1444
|
const webUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
1386
1445
|
const maxPerBrowser = Math.max(
|
|
1387
1446
|
1,
|
|
1388
|
-
webExecution?.maxContextsPerBrowser ?? (
|
|
1447
|
+
webExecution?.maxContextsPerBrowser ?? (engine === "cdp" ? 1 : 2)
|
|
1389
1448
|
);
|
|
1390
|
-
if (
|
|
1391
|
-
const useExternalCdp = Boolean(webExecution
|
|
1449
|
+
if (engine === "cdp") {
|
|
1450
|
+
const useExternalCdp = Boolean(webExecution?.cdpUrl);
|
|
1392
1451
|
const browserCount2 = useExternalCdp ? 1 : Math.ceil(workerCount / maxPerBrowser);
|
|
1393
1452
|
const handles = [];
|
|
1394
1453
|
if (useExternalCdp) {
|
|
1395
1454
|
handles.push({ cdpUrl: webExecution.cdpUrl, remaining: workerCount });
|
|
1396
1455
|
} else {
|
|
1397
|
-
const useWarm2 = webExecution
|
|
1398
|
-
const baseScope = webExecution
|
|
1456
|
+
const useWarm2 = webExecution?.warmBrowser ?? config.execution?.warmDaemons?.enabled ?? false;
|
|
1457
|
+
const baseScope = webExecution?.warmBrowserScope ?? "pool";
|
|
1399
1458
|
const launched = await Promise.all(
|
|
1400
1459
|
Array.from(
|
|
1401
1460
|
{ length: browserCount2 },
|
|
1402
1461
|
(_v, bIdx) => bIdx === 0 && prelaunched?.cdpBrowserPromise ? prelaunched.cdpBrowserPromise : launchDirectCdpBrowser({
|
|
1403
|
-
executablePath: webExecution
|
|
1404
|
-
headless: webExecution
|
|
1462
|
+
executablePath: webExecution?.executablePath,
|
|
1463
|
+
headless: webExecution?.headless ?? true,
|
|
1405
1464
|
warmBrowser: useWarm2,
|
|
1406
1465
|
warmBrowserScope: `${baseScope}-w${bIdx}`
|
|
1407
1466
|
})
|
|
@@ -1423,12 +1482,12 @@ async function buildWebRuntimePool(config, workerCount, prelaunched) {
|
|
|
1423
1482
|
baseUrl: webUrl,
|
|
1424
1483
|
engineLabel: "cdp",
|
|
1425
1484
|
useBrowserContexts: true,
|
|
1426
|
-
freshContextPerFlow: webExecution
|
|
1427
|
-
waitUntil: webExecution
|
|
1428
|
-
instantAnimations: webExecution
|
|
1429
|
-
blockResources: webExecution
|
|
1430
|
-
virtualAuthenticator: webExecution
|
|
1431
|
-
storageState: webExecution
|
|
1485
|
+
freshContextPerFlow: webExecution?.freshContextPerFlow,
|
|
1486
|
+
waitUntil: webExecution?.waitUntil,
|
|
1487
|
+
instantAnimations: webExecution?.instantAnimations,
|
|
1488
|
+
blockResources: webExecution?.blockResources,
|
|
1489
|
+
virtualAuthenticator: webExecution?.virtualAuthenticator,
|
|
1490
|
+
storageState: webExecution?.storageState
|
|
1432
1491
|
})
|
|
1433
1492
|
);
|
|
1434
1493
|
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
@@ -1886,12 +1945,291 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
1886
1945
|
}
|
|
1887
1946
|
}
|
|
1888
1947
|
|
|
1948
|
+
// src/core/video-recorder.ts
|
|
1949
|
+
import { execFileSync, spawn as spawn2 } from "child_process";
|
|
1950
|
+
import {
|
|
1951
|
+
existsSync as existsSync2,
|
|
1952
|
+
mkdirSync,
|
|
1953
|
+
mkdtempSync as mkdtempSync2,
|
|
1954
|
+
readFileSync,
|
|
1955
|
+
rmSync as rmSync2,
|
|
1956
|
+
unlinkSync,
|
|
1957
|
+
writeFileSync
|
|
1958
|
+
} from "fs";
|
|
1959
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
1960
|
+
import { join as join2 } from "path";
|
|
1961
|
+
function hasFfmpegOnPath() {
|
|
1962
|
+
try {
|
|
1963
|
+
execFileSync(process.platform === "win32" ? "where" : "which", ["ffmpeg"], {
|
|
1964
|
+
stdio: "ignore"
|
|
1965
|
+
});
|
|
1966
|
+
return true;
|
|
1967
|
+
} catch {
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
async function exportFramesToMp4(frames, outputPath, spawnFn = spawn2) {
|
|
1972
|
+
if (frames.length === 0 || !hasFfmpegOnPath()) return void 0;
|
|
1973
|
+
const tempDir = mkdtempSync2(join2(tmpdir2(), "spana-vid-"));
|
|
1974
|
+
try {
|
|
1975
|
+
const ext = frames[0].mimeType === "image/png" ? "png" : "jpg";
|
|
1976
|
+
const listLines = [];
|
|
1977
|
+
for (let i = 0; i < frames.length; i++) {
|
|
1978
|
+
const f = frames[i];
|
|
1979
|
+
const framePath = join2(tempDir, `frame-${String(i).padStart(5, "0")}.${ext}`);
|
|
1980
|
+
writeFileSync(framePath, Buffer.from(f.dataBase64, "base64"));
|
|
1981
|
+
const nextTs = frames[i + 1]?.timestampMs ?? f.timestampMs + 250;
|
|
1982
|
+
const durSec = Math.max(0.05, Math.min(2, (nextTs - f.timestampMs) / 1e3));
|
|
1983
|
+
listLines.push(`file '${framePath.replaceAll("'", "'\\''")}'`);
|
|
1984
|
+
listLines.push(`duration ${durSec.toFixed(3)}`);
|
|
1985
|
+
}
|
|
1986
|
+
const lastPath = join2(tempDir, `frame-${String(frames.length - 1).padStart(5, "0")}.${ext}`);
|
|
1987
|
+
listLines.push(`file '${lastPath.replaceAll("'", "'\\''")}'`);
|
|
1988
|
+
const listFile = join2(tempDir, "frames.txt");
|
|
1989
|
+
writeFileSync(listFile, listLines.join("\n"), "utf8");
|
|
1990
|
+
const ok = await new Promise((resolve) => {
|
|
1991
|
+
const child = spawnFn(
|
|
1992
|
+
"ffmpeg",
|
|
1993
|
+
[
|
|
1994
|
+
"-y",
|
|
1995
|
+
"-f",
|
|
1996
|
+
"concat",
|
|
1997
|
+
"-safe",
|
|
1998
|
+
"0",
|
|
1999
|
+
"-i",
|
|
2000
|
+
listFile,
|
|
2001
|
+
"-vf",
|
|
2002
|
+
"pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
|
2003
|
+
"-c:v",
|
|
2004
|
+
"libx264",
|
|
2005
|
+
"-pix_fmt",
|
|
2006
|
+
"yuv420p",
|
|
2007
|
+
"-movflags",
|
|
2008
|
+
"+faststart",
|
|
2009
|
+
outputPath
|
|
2010
|
+
],
|
|
2011
|
+
{ stdio: "ignore" }
|
|
2012
|
+
);
|
|
2013
|
+
child.on("error", () => resolve(false));
|
|
2014
|
+
child.on("close", (code) => resolve(code === 0));
|
|
2015
|
+
});
|
|
2016
|
+
return ok && existsSync2(outputPath) ? outputPath : void 0;
|
|
2017
|
+
} catch {
|
|
2018
|
+
return void 0;
|
|
2019
|
+
} finally {
|
|
2020
|
+
try {
|
|
2021
|
+
rmSync2(tempDir, { recursive: true, force: true });
|
|
2022
|
+
} catch {
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
async function startCdpScreencastRecorder(cdp, options) {
|
|
2027
|
+
const startedAt = Date.now();
|
|
2028
|
+
const startedAtIso = new Date(startedAt).toISOString();
|
|
2029
|
+
const maxFrames = options.maxFrames ?? 180;
|
|
2030
|
+
const frames = [];
|
|
2031
|
+
let stopped = false;
|
|
2032
|
+
const unsubscribe = cdp.onEvent("Page.screencastFrame", (params) => {
|
|
2033
|
+
if (stopped) return;
|
|
2034
|
+
const sessionId = params?.sessionId;
|
|
2035
|
+
if (sessionId !== void 0) {
|
|
2036
|
+
void cdp.sendCommand("Page.screencastFrameAck", { sessionId }).catch(() => {
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
if (typeof params?.data === "string" && params.data.length > 0) {
|
|
2040
|
+
if (frames.length >= maxFrames) {
|
|
2041
|
+
frames.splice(1, 1);
|
|
2042
|
+
}
|
|
2043
|
+
frames.push({
|
|
2044
|
+
timestampMs: Math.max(0, Date.now() - startedAt),
|
|
2045
|
+
dataBase64: params.data,
|
|
2046
|
+
mimeType: "image/jpeg"
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
});
|
|
2050
|
+
await cdp.sendCommand("Page.startScreencast", {
|
|
2051
|
+
format: "jpeg",
|
|
2052
|
+
quality: options.quality ?? 65,
|
|
2053
|
+
maxWidth: options.maxWidth ?? 1280,
|
|
2054
|
+
maxHeight: options.maxHeight ?? 720,
|
|
2055
|
+
everyNthFrame: options.everyNthFrame ?? 2
|
|
2056
|
+
}).catch(() => {
|
|
2057
|
+
});
|
|
2058
|
+
return {
|
|
2059
|
+
stop: async (stopOpts) => {
|
|
2060
|
+
if (stopped) return { frameCount: frames.length };
|
|
2061
|
+
stopped = true;
|
|
2062
|
+
unsubscribe();
|
|
2063
|
+
await cdp.sendCommand("Page.stopScreencast").catch(() => {
|
|
2064
|
+
});
|
|
2065
|
+
if (!stopOpts.keep || frames.length === 0) {
|
|
2066
|
+
return { frameCount: 0 };
|
|
2067
|
+
}
|
|
2068
|
+
mkdirSync(stopOpts.outputDir, { recursive: true });
|
|
2069
|
+
let videoPath;
|
|
2070
|
+
if (options.exportMp4 !== false) {
|
|
2071
|
+
const mp4Target = join2(stopOpts.outputDir, `${stopOpts.fileStem}.mp4`);
|
|
2072
|
+
videoPath = await exportFramesToMp4(frames, mp4Target, options.spawnFn);
|
|
2073
|
+
}
|
|
2074
|
+
const trace = {
|
|
2075
|
+
version: 1,
|
|
2076
|
+
flowName: options.flowName,
|
|
2077
|
+
platform: options.platform,
|
|
2078
|
+
startedAtIso,
|
|
2079
|
+
durationMs: Math.max(1, Date.now() - startedAt),
|
|
2080
|
+
viewport: stopOpts.viewport,
|
|
2081
|
+
frames,
|
|
2082
|
+
steps: stopOpts.steps ?? [],
|
|
2083
|
+
...videoPath ? { videoPath } : {}
|
|
2084
|
+
};
|
|
2085
|
+
const playbackJsonPath = join2(stopOpts.outputDir, `${stopOpts.fileStem}-playback.json`);
|
|
2086
|
+
writeFileSync(playbackJsonPath, JSON.stringify(trace), "utf8");
|
|
2087
|
+
return { playbackJsonPath, videoPath, frameCount: frames.length };
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
function startAndroidVideoRecorder(serial, options) {
|
|
2092
|
+
const spawnFn = options.spawnFn ?? spawn2;
|
|
2093
|
+
const execSyncFn = options.execFileSyncFn ?? execFileSync;
|
|
2094
|
+
const remotePath = `/sdcard/spana-rec-${Date.now()}-${Math.floor(Math.random() * 1e4)}.mp4`;
|
|
2095
|
+
const child = spawnFn(
|
|
2096
|
+
"adb",
|
|
2097
|
+
["-s", serial, "shell", "screenrecord", "--time-limit", "180", remotePath],
|
|
2098
|
+
{ stdio: "ignore" }
|
|
2099
|
+
);
|
|
2100
|
+
let stopped = false;
|
|
2101
|
+
return {
|
|
2102
|
+
stop: async ({ keep }) => {
|
|
2103
|
+
if (stopped) return { frameCount: 0 };
|
|
2104
|
+
stopped = true;
|
|
2105
|
+
try {
|
|
2106
|
+
child.kill("SIGINT");
|
|
2107
|
+
} catch {
|
|
2108
|
+
}
|
|
2109
|
+
await new Promise((resolve) => {
|
|
2110
|
+
const timer = setTimeout(resolve, 1200);
|
|
2111
|
+
child.once("close", () => {
|
|
2112
|
+
clearTimeout(timer);
|
|
2113
|
+
resolve();
|
|
2114
|
+
});
|
|
2115
|
+
});
|
|
2116
|
+
let savedPath;
|
|
2117
|
+
if (keep) {
|
|
2118
|
+
try {
|
|
2119
|
+
execSyncFn("adb", ["-s", serial, "pull", remotePath, options.outputPath], {
|
|
2120
|
+
stdio: "ignore"
|
|
2121
|
+
});
|
|
2122
|
+
if (existsSync2(options.outputPath)) savedPath = options.outputPath;
|
|
2123
|
+
} catch {
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
try {
|
|
2127
|
+
execSyncFn("adb", ["-s", serial, "shell", "rm", "-f", remotePath], { stdio: "ignore" });
|
|
2128
|
+
} catch {
|
|
2129
|
+
}
|
|
2130
|
+
return { videoPath: savedPath, frameCount: savedPath ? 1 : 0 };
|
|
2131
|
+
}
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
function startIosSimulatorVideoRecorder(udid, options) {
|
|
2135
|
+
const spawnFn = options.spawnFn ?? spawn2;
|
|
2136
|
+
const child = spawnFn(
|
|
2137
|
+
"xcrun",
|
|
2138
|
+
["simctl", "io", udid, "recordVideo", "--codec=h264", "--force", options.outputPath],
|
|
2139
|
+
{ stdio: "ignore" }
|
|
2140
|
+
);
|
|
2141
|
+
let stopped = false;
|
|
2142
|
+
return {
|
|
2143
|
+
stop: async ({ keep }) => {
|
|
2144
|
+
if (stopped) return { frameCount: 0 };
|
|
2145
|
+
stopped = true;
|
|
2146
|
+
try {
|
|
2147
|
+
child.kill("SIGINT");
|
|
2148
|
+
} catch {
|
|
2149
|
+
}
|
|
2150
|
+
await new Promise((resolve) => {
|
|
2151
|
+
const timer = setTimeout(resolve, 1500);
|
|
2152
|
+
child.once("close", () => {
|
|
2153
|
+
clearTimeout(timer);
|
|
2154
|
+
resolve();
|
|
2155
|
+
});
|
|
2156
|
+
});
|
|
2157
|
+
if (!keep) {
|
|
2158
|
+
try {
|
|
2159
|
+
if (existsSync2(options.outputPath)) unlinkSync(options.outputPath);
|
|
2160
|
+
} catch {
|
|
2161
|
+
}
|
|
2162
|
+
return { frameCount: 0 };
|
|
2163
|
+
}
|
|
2164
|
+
return {
|
|
2165
|
+
videoPath: existsSync2(options.outputPath) ? options.outputPath : void 0,
|
|
2166
|
+
frameCount: existsSync2(options.outputPath) ? 1 : 0
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
function buildPlaybackTraceFromSteps(input) {
|
|
2172
|
+
const frames = [];
|
|
2173
|
+
const markers = [];
|
|
2174
|
+
let cursorMs = 0;
|
|
2175
|
+
for (let i = 0; i < input.steps.length; i++) {
|
|
2176
|
+
const step = input.steps[i];
|
|
2177
|
+
const tapPoint = extractTapPointFromStep(step);
|
|
2178
|
+
markers.push({
|
|
2179
|
+
index: i,
|
|
2180
|
+
command: step.command,
|
|
2181
|
+
selector: step.selector,
|
|
2182
|
+
startedAtMs: cursorMs,
|
|
2183
|
+
durationMs: step.durationMs,
|
|
2184
|
+
status: step.status,
|
|
2185
|
+
error: step.error,
|
|
2186
|
+
...tapPoint ? { tapPoint } : {}
|
|
2187
|
+
});
|
|
2188
|
+
const img = step.attachments?.find(
|
|
2189
|
+
(a) => a.contentType === "image/png" || a.contentType === "image/jpeg"
|
|
2190
|
+
);
|
|
2191
|
+
if (img && existsSync2(img.path)) {
|
|
2192
|
+
try {
|
|
2193
|
+
const dataBase64 = readFileSync(img.path).toString("base64");
|
|
2194
|
+
frames.push({
|
|
2195
|
+
timestampMs: cursorMs + step.durationMs,
|
|
2196
|
+
dataBase64,
|
|
2197
|
+
mimeType: img.contentType === "image/jpeg" ? "image/jpeg" : "image/png"
|
|
2198
|
+
});
|
|
2199
|
+
} catch {
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
cursorMs += Math.max(1, step.durationMs);
|
|
2203
|
+
}
|
|
2204
|
+
if (frames.length === 0 && !input.videoPath) return null;
|
|
2205
|
+
return {
|
|
2206
|
+
version: 1,
|
|
2207
|
+
flowName: input.flowName,
|
|
2208
|
+
platform: input.platform,
|
|
2209
|
+
startedAtIso: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2210
|
+
durationMs: Math.max(1, input.durationMs),
|
|
2211
|
+
viewport: input.viewport,
|
|
2212
|
+
frames,
|
|
2213
|
+
steps: markers,
|
|
2214
|
+
...input.videoPath ? { videoPath: input.videoPath } : {}
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2217
|
+
function extractTapPointFromStep(step) {
|
|
2218
|
+
const sel = step.selector;
|
|
2219
|
+
if (!sel || typeof sel !== "object") return void 0;
|
|
2220
|
+
const pt = sel["point"];
|
|
2221
|
+
if (pt && typeof pt["x"] === "number" && typeof pt["y"] === "number") {
|
|
2222
|
+
return { x: pt["x"], y: pt["y"] };
|
|
2223
|
+
}
|
|
2224
|
+
return void 0;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
1889
2227
|
// src/core/engine.ts
|
|
1890
2228
|
import { Effect as Effect7 } from "effect";
|
|
1891
2229
|
|
|
1892
2230
|
// src/core/artifacts.ts
|
|
1893
|
-
import { writeFileSync, mkdirSync } from "fs";
|
|
1894
|
-
import { join as
|
|
2231
|
+
import { writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
2232
|
+
import { join as join3 } from "path";
|
|
1895
2233
|
import { Effect as Effect5 } from "effect";
|
|
1896
2234
|
var DEFAULT_ARTIFACT_CONFIG = {
|
|
1897
2235
|
outputDir: "./spana-output",
|
|
@@ -1902,27 +2240,30 @@ var DEFAULT_ARTIFACT_CONFIG = {
|
|
|
1902
2240
|
uiHierarchy: true,
|
|
1903
2241
|
consoleLogs: true,
|
|
1904
2242
|
jsErrors: true,
|
|
1905
|
-
har: true
|
|
2243
|
+
har: true,
|
|
2244
|
+
video: "off",
|
|
2245
|
+
playback: false
|
|
1906
2246
|
};
|
|
1907
|
-
function
|
|
2247
|
+
function safeArtifactName(value) {
|
|
1908
2248
|
return value.replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").replaceAll(/^_+|_+$/g, "").slice(0, 80) || "artifact";
|
|
1909
2249
|
}
|
|
2250
|
+
var safeName = safeArtifactName;
|
|
1910
2251
|
function flowArtifactDir(config, flowName, platform) {
|
|
1911
|
-
const dir =
|
|
1912
|
-
|
|
2252
|
+
const dir = join3(config.outputDir, `${safeName(flowName)}-${platform}`);
|
|
2253
|
+
mkdirSync2(dir, { recursive: true });
|
|
1913
2254
|
return dir;
|
|
1914
2255
|
}
|
|
1915
2256
|
function createAttachment(name, contentType, path) {
|
|
1916
2257
|
return { name, contentType, path };
|
|
1917
2258
|
}
|
|
1918
2259
|
function writeJsonAttachment(dir, fileName, attachmentName, value) {
|
|
1919
|
-
const path =
|
|
1920
|
-
|
|
2260
|
+
const path = join3(dir, fileName);
|
|
2261
|
+
writeFileSync2(path, JSON.stringify(value, null, 2), "utf-8");
|
|
1921
2262
|
return createAttachment(attachmentName, "application/json", path);
|
|
1922
2263
|
}
|
|
1923
2264
|
function writeTextAttachment(dir, fileName, attachmentName, value) {
|
|
1924
|
-
const path =
|
|
1925
|
-
|
|
2265
|
+
const path = join3(dir, fileName);
|
|
2266
|
+
writeFileSync2(path, value, "utf-8");
|
|
1926
2267
|
return createAttachment(attachmentName, "text/plain", path);
|
|
1927
2268
|
}
|
|
1928
2269
|
function resolveArtifactConfig(...configs) {
|
|
@@ -1942,8 +2283,8 @@ async function captureArtifacts(driver, config, flowName, platform, status) {
|
|
|
1942
2283
|
if (config.screenshot) {
|
|
1943
2284
|
try {
|
|
1944
2285
|
const screenshot = await Effect5.runPromise(Effect5.orDie(driver.takeScreenshot()));
|
|
1945
|
-
const path =
|
|
1946
|
-
|
|
2286
|
+
const path = join3(dir, "screenshot.png");
|
|
2287
|
+
writeFileSync2(path, screenshot);
|
|
1947
2288
|
attachments.push(createAttachment(`${status}-screenshot`, "image/png", path));
|
|
1948
2289
|
} catch {
|
|
1949
2290
|
}
|
|
@@ -1951,8 +2292,8 @@ async function captureArtifacts(driver, config, flowName, platform, status) {
|
|
|
1951
2292
|
if (config.uiHierarchy) {
|
|
1952
2293
|
try {
|
|
1953
2294
|
const hierarchy = await Effect5.runPromise(Effect5.orDie(driver.dumpHierarchy()));
|
|
1954
|
-
const path =
|
|
1955
|
-
|
|
2295
|
+
const path = join3(dir, "hierarchy.json");
|
|
2296
|
+
writeFileSync2(path, hierarchy, "utf-8");
|
|
1956
2297
|
attachments.push(createAttachment(`${status}-hierarchy`, "application/json", path));
|
|
1957
2298
|
} catch {
|
|
1958
2299
|
}
|
|
@@ -2009,12 +2350,12 @@ async function captureArtifacts(driver, config, flowName, platform, status) {
|
|
|
2009
2350
|
async function captureStepScreenshot(driver, config, flowName, platform, stepIndex, stepName, screenshot) {
|
|
2010
2351
|
if (!config.screenshot) return void 0;
|
|
2011
2352
|
try {
|
|
2012
|
-
const dir =
|
|
2013
|
-
|
|
2353
|
+
const dir = join3(flowArtifactDir(config, flowName, platform), "steps");
|
|
2354
|
+
mkdirSync2(dir, { recursive: true });
|
|
2014
2355
|
const fileName = `${String(stepIndex).padStart(3, "0")}-${safeName(stepName)}.png`;
|
|
2015
|
-
const path =
|
|
2356
|
+
const path = join3(dir, fileName);
|
|
2016
2357
|
const bytes = screenshot ?? await Effect5.runPromise(Effect5.orDie(driver.takeScreenshot()));
|
|
2017
|
-
|
|
2358
|
+
writeFileSync2(path, bytes);
|
|
2018
2359
|
return createAttachment(stepName, "image/png", path);
|
|
2019
2360
|
} catch {
|
|
2020
2361
|
return void 0;
|
|
@@ -2438,11 +2779,12 @@ function classifyError(error) {
|
|
|
2438
2779
|
}
|
|
2439
2780
|
|
|
2440
2781
|
// src/core/engine.ts
|
|
2441
|
-
import {
|
|
2782
|
+
import { writeFileSync as writeFileSync4 } from "fs";
|
|
2783
|
+
import { join as join5 } from "path";
|
|
2442
2784
|
|
|
2443
2785
|
// src/report/failure-bundle.ts
|
|
2444
|
-
import { writeFileSync as
|
|
2445
|
-
import { join as
|
|
2786
|
+
import { writeFileSync as writeFileSync3, readFileSync as readFileSync2, existsSync as existsSync3 } from "fs";
|
|
2787
|
+
import { join as join4, basename } from "path";
|
|
2446
2788
|
function levenshtein(a, b) {
|
|
2447
2789
|
const m = a.length;
|
|
2448
2790
|
const n = b.length;
|
|
@@ -2549,11 +2891,11 @@ function createFailureBundle(flowName, platform, steps, error, artifactDir, atta
|
|
|
2549
2891
|
} : null;
|
|
2550
2892
|
let selectorContext;
|
|
2551
2893
|
if (failedStep?.selector && (error.category === "element-not-found" || error.category === "element-not-visible")) {
|
|
2552
|
-
const hierarchyPath =
|
|
2894
|
+
const hierarchyPath = join4(artifactDir, "hierarchy.json");
|
|
2553
2895
|
let hierarchyJson = null;
|
|
2554
|
-
if (
|
|
2896
|
+
if (existsSync3(hierarchyPath)) {
|
|
2555
2897
|
try {
|
|
2556
|
-
hierarchyJson =
|
|
2898
|
+
hierarchyJson = readFileSync2(hierarchyPath, "utf-8");
|
|
2557
2899
|
} catch {
|
|
2558
2900
|
}
|
|
2559
2901
|
}
|
|
@@ -2566,17 +2908,17 @@ function createFailureBundle(flowName, platform, steps, error, artifactDir, atta
|
|
|
2566
2908
|
const flowFile = flowPath ?? `flows/${flowName.replaceAll(" ", "-")}.flow.ts`;
|
|
2567
2909
|
const reproCommand = `spana test ${flowFile} --platform ${platform} --grep '${flowName}'`;
|
|
2568
2910
|
let runtimeDiagnostics;
|
|
2569
|
-
const consolePath =
|
|
2570
|
-
const jsErrPath =
|
|
2571
|
-
if (
|
|
2911
|
+
const consolePath = join4(artifactDir, "console-logs.json");
|
|
2912
|
+
const jsErrPath = join4(artifactDir, "js-errors.json");
|
|
2913
|
+
if (existsSync3(consolePath) || existsSync3(jsErrPath)) {
|
|
2572
2914
|
let consoleErrorCount = 0;
|
|
2573
2915
|
let consoleWarnCount = 0;
|
|
2574
2916
|
const recentConsoleErrors = [];
|
|
2575
2917
|
let jsErrorCount = 0;
|
|
2576
2918
|
const recentJsErrors = [];
|
|
2577
|
-
if (
|
|
2919
|
+
if (existsSync3(consolePath)) {
|
|
2578
2920
|
try {
|
|
2579
|
-
const logs = JSON.parse(
|
|
2921
|
+
const logs = JSON.parse(readFileSync2(consolePath, "utf-8"));
|
|
2580
2922
|
if (Array.isArray(logs)) {
|
|
2581
2923
|
for (const entry of logs) {
|
|
2582
2924
|
const lvl = (entry.type ?? entry.level ?? "").toLowerCase();
|
|
@@ -2592,9 +2934,9 @@ function createFailureBundle(flowName, platform, steps, error, artifactDir, atta
|
|
|
2592
2934
|
} catch {
|
|
2593
2935
|
}
|
|
2594
2936
|
}
|
|
2595
|
-
if (
|
|
2937
|
+
if (existsSync3(jsErrPath)) {
|
|
2596
2938
|
try {
|
|
2597
|
-
const errs = JSON.parse(
|
|
2939
|
+
const errs = JSON.parse(readFileSync2(jsErrPath, "utf-8"));
|
|
2598
2940
|
if (Array.isArray(errs)) {
|
|
2599
2941
|
jsErrorCount = errs.length;
|
|
2600
2942
|
for (const e of errs.slice(-5)) {
|
|
@@ -2637,12 +2979,35 @@ function createFailureBundle(flowName, platform, steps, error, artifactDir, atta
|
|
|
2637
2979
|
return bundle;
|
|
2638
2980
|
}
|
|
2639
2981
|
function writeFailureBundle(bundle, artifactDir) {
|
|
2640
|
-
const path =
|
|
2641
|
-
|
|
2982
|
+
const path = join4(artifactDir, "failure-bundle.json");
|
|
2983
|
+
writeFileSync3(path, JSON.stringify(bundle, null, 2), "utf-8");
|
|
2642
2984
|
return path;
|
|
2643
2985
|
}
|
|
2644
2986
|
|
|
2645
2987
|
// src/core/engine.ts
|
|
2988
|
+
function isCdpScreencastCapable(channel) {
|
|
2989
|
+
return Boolean(channel) && typeof channel.sendCommand === "function" && typeof channel.onEvent === "function";
|
|
2990
|
+
}
|
|
2991
|
+
function buildPlaybackStepMarkers(steps) {
|
|
2992
|
+
let cursorMs = 0;
|
|
2993
|
+
return steps.map((step, index) => {
|
|
2994
|
+
const startedAtMs = cursorMs;
|
|
2995
|
+
cursorMs += Math.max(1, step.durationMs);
|
|
2996
|
+
const sel = step.selector;
|
|
2997
|
+
const pt = sel && typeof sel === "object" ? sel["point"] : void 0;
|
|
2998
|
+
const tapPoint = pt && typeof pt["x"] === "number" && typeof pt["y"] === "number" ? { x: pt["x"], y: pt["y"] } : void 0;
|
|
2999
|
+
return {
|
|
3000
|
+
index,
|
|
3001
|
+
command: step.command,
|
|
3002
|
+
selector: step.selector,
|
|
3003
|
+
startedAtMs,
|
|
3004
|
+
durationMs: step.durationMs,
|
|
3005
|
+
status: step.status,
|
|
3006
|
+
error: step.error,
|
|
3007
|
+
...tapPoint ? { tapPoint } : {}
|
|
3008
|
+
};
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
2646
3011
|
async function executeFlow(flow, driver, config) {
|
|
2647
3012
|
const start2 = Date.now();
|
|
2648
3013
|
const { platform, coordinatorConfig, appId } = config;
|
|
@@ -2702,6 +3067,70 @@ async function executeFlow(flow, driver, config) {
|
|
|
2702
3067
|
{ parse: (raw) => parseWebHierarchy(raw) }
|
|
2703
3068
|
);
|
|
2704
3069
|
flowCtx.sessions = sessions;
|
|
3070
|
+
let videoRecorder;
|
|
3071
|
+
let recordingFinalized = false;
|
|
3072
|
+
const wantRecording = artifactConfig.video !== "off" || artifactConfig.playback;
|
|
3073
|
+
const finalizeRecording = async (status, attachments, steps, durationMs) => {
|
|
3074
|
+
if (recordingFinalized || !wantRecording) return;
|
|
3075
|
+
recordingFinalized = true;
|
|
3076
|
+
const keep = artifactConfig.video === "on" || artifactConfig.playback || artifactConfig.video === "retain-on-failure" && status === "failed";
|
|
3077
|
+
const fileStem = safeArtifactName(flow.name);
|
|
3078
|
+
const outputDir = keep ? flowArtifactDir(artifactConfig, flow.name, platform) : artifactConfig.outputDir;
|
|
3079
|
+
let viewport;
|
|
3080
|
+
try {
|
|
3081
|
+
const info = await Effect7.runPromise(Effect7.orDie(driver.getDeviceInfo()));
|
|
3082
|
+
if (info.screenWidth > 0 && info.screenHeight > 0) {
|
|
3083
|
+
viewport = { width: info.screenWidth, height: info.screenHeight };
|
|
3084
|
+
}
|
|
3085
|
+
} catch {
|
|
3086
|
+
}
|
|
3087
|
+
let stopRes;
|
|
3088
|
+
if (videoRecorder) {
|
|
3089
|
+
try {
|
|
3090
|
+
stopRes = await videoRecorder.stop({
|
|
3091
|
+
keep,
|
|
3092
|
+
outputDir,
|
|
3093
|
+
fileStem,
|
|
3094
|
+
steps: buildPlaybackStepMarkers(steps),
|
|
3095
|
+
viewport
|
|
3096
|
+
});
|
|
3097
|
+
} catch {
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
if (!keep) return;
|
|
3101
|
+
if (stopRes?.videoPath) {
|
|
3102
|
+
attachments.push({
|
|
3103
|
+
name: "video",
|
|
3104
|
+
contentType: stopRes.videoPath.endsWith(".webm") ? "video/webm" : "video/mp4",
|
|
3105
|
+
path: stopRes.videoPath
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
if (stopRes?.playbackJsonPath) {
|
|
3109
|
+
attachments.push({
|
|
3110
|
+
name: "playback",
|
|
3111
|
+
contentType: "application/json",
|
|
3112
|
+
path: stopRes.playbackJsonPath
|
|
3113
|
+
});
|
|
3114
|
+
return;
|
|
3115
|
+
}
|
|
3116
|
+
const fallbackTrace = buildPlaybackTraceFromSteps({
|
|
3117
|
+
flowName: flow.name,
|
|
3118
|
+
platform,
|
|
3119
|
+
durationMs,
|
|
3120
|
+
steps,
|
|
3121
|
+
viewport,
|
|
3122
|
+
videoPath: stopRes?.videoPath
|
|
3123
|
+
});
|
|
3124
|
+
if (fallbackTrace) {
|
|
3125
|
+
const playbackPath = join5(outputDir, `${fileStem}-playback.json`);
|
|
3126
|
+
writeFileSync4(playbackPath, JSON.stringify(fallbackTrace), "utf8");
|
|
3127
|
+
attachments.push({
|
|
3128
|
+
name: "playback",
|
|
3129
|
+
contentType: "application/json",
|
|
3130
|
+
path: playbackPath
|
|
3131
|
+
});
|
|
3132
|
+
}
|
|
3133
|
+
};
|
|
2705
3134
|
const buildFailureResult = async (error) => {
|
|
2706
3135
|
const attachments = await captureArtifacts(
|
|
2707
3136
|
driver,
|
|
@@ -2710,15 +3139,18 @@ async function executeFlow(flow, driver, config) {
|
|
|
2710
3139
|
platform,
|
|
2711
3140
|
"failed"
|
|
2712
3141
|
);
|
|
3142
|
+
const steps = stepRecorder.getSteps();
|
|
3143
|
+
const durationMs = Date.now() - start2;
|
|
3144
|
+
await finalizeRecording("failed", attachments, steps, durationMs);
|
|
2713
3145
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
2714
3146
|
return {
|
|
2715
3147
|
name: flow.name,
|
|
2716
3148
|
platform,
|
|
2717
3149
|
status: "failed",
|
|
2718
|
-
durationMs
|
|
3150
|
+
durationMs,
|
|
2719
3151
|
error: classifyError(normalized),
|
|
2720
3152
|
attachments,
|
|
2721
|
-
steps
|
|
3153
|
+
steps,
|
|
2722
3154
|
scenarioSteps: flowCtx.__scenarioSteps
|
|
2723
3155
|
};
|
|
2724
3156
|
};
|
|
@@ -2729,6 +3161,27 @@ async function executeFlow(flow, driver, config) {
|
|
|
2729
3161
|
return buildFailureResult(error);
|
|
2730
3162
|
}
|
|
2731
3163
|
}
|
|
3164
|
+
if (wantRecording) {
|
|
3165
|
+
try {
|
|
3166
|
+
if (isCdpScreencastCapable(driver.domChannel)) {
|
|
3167
|
+
videoRecorder = await startCdpScreencastRecorder(driver.domChannel, {
|
|
3168
|
+
flowName: flow.name,
|
|
3169
|
+
platform,
|
|
3170
|
+
exportMp4: artifactConfig.video !== "off"
|
|
3171
|
+
});
|
|
3172
|
+
} else if (artifactConfig.video !== "off" && (platform === "android" || platform === "ios")) {
|
|
3173
|
+
const info = await Effect7.runPromise(Effect7.orDie(driver.getDeviceInfo())).catch(
|
|
3174
|
+
() => void 0
|
|
3175
|
+
);
|
|
3176
|
+
if (info?.deviceId) {
|
|
3177
|
+
const outDir = flowArtifactDir(artifactConfig, flow.name, platform);
|
|
3178
|
+
const videoOut = join5(outDir, `${safeArtifactName(flow.name)}.mp4`);
|
|
3179
|
+
videoRecorder = platform === "android" ? startAndroidVideoRecorder(info.deviceId, { outputPath: videoOut }) : startIosSimulatorVideoRecorder(info.deviceId, { outputPath: videoOut });
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
} catch {
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
2732
3185
|
if (config.hooks?.beforeEach) {
|
|
2733
3186
|
try {
|
|
2734
3187
|
await config.hooks.beforeEach({ app, platform });
|
|
@@ -2757,13 +3210,16 @@ async function executeFlow(flow, driver, config) {
|
|
|
2757
3210
|
platform,
|
|
2758
3211
|
"passed"
|
|
2759
3212
|
);
|
|
3213
|
+
const steps = stepRecorder.getSteps();
|
|
3214
|
+
const durationMs = Date.now() - start2;
|
|
3215
|
+
await finalizeRecording("passed", attachments, steps, durationMs);
|
|
2760
3216
|
result = {
|
|
2761
3217
|
name: flow.name,
|
|
2762
3218
|
platform,
|
|
2763
3219
|
status: "passed",
|
|
2764
|
-
durationMs
|
|
3220
|
+
durationMs,
|
|
2765
3221
|
attachments,
|
|
2766
|
-
steps
|
|
3222
|
+
steps,
|
|
2767
3223
|
scenarioSteps: flowCtx.__scenarioSteps
|
|
2768
3224
|
};
|
|
2769
3225
|
} catch (error) {
|
|
@@ -2774,20 +3230,23 @@ async function executeFlow(flow, driver, config) {
|
|
|
2774
3230
|
platform,
|
|
2775
3231
|
"failed"
|
|
2776
3232
|
);
|
|
3233
|
+
const steps = stepRecorder.getSteps();
|
|
3234
|
+
const durationMs = Date.now() - start2;
|
|
3235
|
+
await finalizeRecording("failed", attachments, steps, durationMs);
|
|
2777
3236
|
const flowError = error instanceof Error ? error : new Error(String(error));
|
|
2778
3237
|
result = {
|
|
2779
3238
|
name: flow.name,
|
|
2780
3239
|
platform,
|
|
2781
3240
|
status: "failed",
|
|
2782
|
-
durationMs
|
|
3241
|
+
durationMs,
|
|
2783
3242
|
error: classifyError(flowError),
|
|
2784
3243
|
attachments,
|
|
2785
|
-
steps
|
|
3244
|
+
steps,
|
|
2786
3245
|
scenarioSteps: flowCtx.__scenarioSteps
|
|
2787
3246
|
};
|
|
2788
3247
|
if (artifactConfig.captureOnFailure && result.error) {
|
|
2789
3248
|
try {
|
|
2790
|
-
const artDir =
|
|
3249
|
+
const artDir = join5(
|
|
2791
3250
|
artifactConfig.outputDir,
|
|
2792
3251
|
`${flow.name.replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").slice(0, 80) || "artifact"}-${platform}`
|
|
2793
3252
|
);
|
|
@@ -2920,6 +3379,7 @@ async function runParallel(config) {
|
|
|
2920
3379
|
export {
|
|
2921
3380
|
launchDirectCdpBrowser,
|
|
2922
3381
|
makeLightweightCdpDriver,
|
|
3382
|
+
resolveWebEngine,
|
|
2923
3383
|
speculativelyPrelaunchWebBrowser,
|
|
2924
3384
|
buildWebRuntime,
|
|
2925
3385
|
buildWebRuntimePool,
|
|
@@ -2928,8 +3388,13 @@ export {
|
|
|
2928
3388
|
buildLocalAndroidRuntime,
|
|
2929
3389
|
buildLocalIOSRuntime,
|
|
2930
3390
|
classifyError,
|
|
3391
|
+
exportFramesToMp4,
|
|
3392
|
+
startCdpScreencastRecorder,
|
|
3393
|
+
startAndroidVideoRecorder,
|
|
3394
|
+
startIosSimulatorVideoRecorder,
|
|
3395
|
+
buildPlaybackTraceFromSteps,
|
|
2931
3396
|
executeFlow,
|
|
2932
3397
|
orderFlowsLongestFirst,
|
|
2933
3398
|
runParallel
|
|
2934
3399
|
};
|
|
2935
|
-
//# sourceMappingURL=chunk-
|
|
3400
|
+
//# sourceMappingURL=chunk-6B5Y75V4.js.map
|