From 68fd9bb4a7a436fee7f2dc9b2d7aa1d9e7e0190c Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Sat, 28 Feb 2026 15:06:19 +0300 Subject: [PATCH] feat(web-test): closeForm({ save }) auto-handles confirmation dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closeForm now accepts { save: true/false } option: - save: false → clicks "Нет" on "Save changes?" dialog - save: true → clicks "Да" to save and close - undefined → returns confirmation as hint (previous behavior) Co-Authored-By: Claude Opus 4.6 --- .claude/skills/web-test/scripts/browser.mjs | 25 +++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.claude/skills/web-test/scripts/browser.mjs b/.claude/skills/web-test/scripts/browser.mjs index c1d5806c..212bb4fd 100644 --- a/.claude/skills/web-test/scripts/browser.mjs +++ b/.claude/skills/web-test/scripts/browser.mjs @@ -1015,8 +1015,15 @@ export async function clickElement(text, { dblclick } = {}) { return state; } -/** Close the current form/dialog via Escape. Returns new form state. If confirmation dialog appears — returns it in `confirmation` field. */ -export async function closeForm() { +/** + * Close the current form/dialog via Escape. + * @param {Object} [opts] + * @param {boolean} [opts.save] - Handle "Save changes?" confirmation automatically: + * true → click "Да" (save and close) + * false → click "Нет" (discard and close) + * undefined → return confirmation as hint for caller to decide + */ +export async function closeForm({ save } = {}) { ensureConnected(); await dismissPendingErrors(); await page.keyboard.press('Escape'); @@ -1024,6 +1031,20 @@ export async function closeForm() { const state = await getFormState(); const err = await checkForErrors(); if (err?.confirmation) { + if (save === true || save === false) { + const label = save ? 'Да' : 'Нет'; + const btnSel = `#form${err.confirmation.formNum}_container a.press.pressButton`; + const btns = await page.$$(btnSel); + for (const b of btns) { + const txt = (await b.textContent()).trim(); + if (txt === label) { + await b.click({ force: true }); + await waitForStable(); + break; + } + } + return await getFormState(); + } state.confirmation = err.confirmation; state.hint = 'Confirmation dialog shown. Click "Да" to confirm or "Нет" to cancel'; }