fix(web-test): take error screenshot before fetchErrorStack closes modal

Move screenshot capture to before fetchErrorStack call in the ACTION_FNS
wrapper, so the error modal is still visible on the screenshot. Skip the
duplicate screenshot in catch block when one was already taken.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-03-21 19:32:00 +03:00
co-authored by Claude Opus 4.6
parent 4cfcaaaa1c
commit 9bc0240e95
+17 -8
View File
@@ -145,6 +145,13 @@ async function executeScript(code, { noRecord } = {}) {
const result = await orig(...args); const result = await orig(...args);
const errors = result?.errors; const errors = result?.errors;
if (errors?.modal || errors?.balloon) { if (errors?.modal || errors?.balloon) {
// Screenshot while the error modal is still visible (before fetchErrorStack closes it)
let errorShot;
try {
const png = await exports.screenshot();
errorShot = resolve(__dirname, '..', 'error-shot.png');
writeFileSync(errorShot, png);
} catch {}
// Try to fetch call stack for modal errors before throwing // Try to fetch call stack for modal errors before throwing
let stack = null; let stack = null;
if (errors?.modal && typeof exports.fetchErrorStack === 'function') { if (errors?.modal && typeof exports.fetchErrorStack === 'function') {
@@ -154,7 +161,7 @@ async function executeScript(code, { noRecord } = {}) {
} }
const msg = errors.modal?.message || errors.balloon?.message || 'Unknown 1C error'; const msg = errors.modal?.message || errors.balloon?.message || 'Unknown 1C error';
const err = new Error(msg); const err = new Error(msg);
err.onecError = { step: name, args, errors, formState: result, stack }; err.onecError = { step: name, args, errors, formState: result, stack, screenshot: errorShot };
throw err; throw err;
} }
return result; return result;
@@ -177,13 +184,15 @@ async function executeScript(code, { noRecord } = {}) {
try { await browser.stopRecording(); } catch {} try { await browser.stopRecording(); } catch {}
} }
// Error screenshot // Error screenshot (skip if already taken before fetchErrorStack closed the modal)
let shotFile; let shotFile = e.onecError?.screenshot;
try { if (!shotFile) {
const png = await browser.screenshot(); try {
shotFile = resolve(__dirname, '..', 'error-shot.png'); const png = await browser.screenshot();
writeFileSync(shotFile, png); shotFile = resolve(__dirname, '..', 'error-shot.png');
} catch {} writeFileSync(shotFile, png);
} catch {}
}
const result = { ok: false, error: e.message, output: output.join('\n'), screenshot: shotFile, elapsed: elapsed(t0) }; const result = { ok: false, error: e.message, output: output.join('\n'), screenshot: shotFile, elapsed: elapsed(t0) };