perf(web-test): skip 10s server-wait for grid edit buttons in clickElement

When clicking toolbar buttons like "Добавить" that put focus into a grid
INPUT cell, skip the 10-second waitForSelector for modal/balloon since
no server round-trip is expected. Also replace fixed waits with polling
in fillTableRow add/row paths. Total: 121s → 62s on composite test suite.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-03-05 08:44:52 +03:00
co-authored by Claude Opus 4.6
parent a5fa730747
commit 8a286d7191
+39 -16
View File
@@ -1485,18 +1485,27 @@ export async function clickElement(text, { dblclick } = {}) {
// For buttons that trigger server-side operations (post, write, etc.), // For buttons that trigger server-side operations (post, write, etc.),
// the DOM may stabilize BEFORE the server response arrives. // the DOM may stabilize BEFORE the server response arrives.
// Use waitForSelector to detect error modal — this doesn't block the JS event loop. // Use waitForSelector to detect error modal — this doesn't block the JS event loop.
// Skip for grid edit mode (e.g. "Добавить" row) — no server round-trip expected.
if (target.kind === 'button') { if (target.kind === 'button') {
const postForm = await page.evaluate(detectFormScript()); const postForm = await page.evaluate(detectFormScript());
if (postForm === formNum) { if (postForm === formNum) {
// Form didn't change — server might still be processing. const inGridEdit = await page.evaluate(`(() => {
// waitForSelector uses MutationObserver internally — doesn't block event loop. const f = document.activeElement;
try { if (!f || (f.tagName !== 'INPUT' && f.tagName !== 'TEXTAREA')) return false;
await page.waitForSelector( let n = f; while (n) { if (n.classList?.contains('grid')) return true; n = n.parentElement; }
'#modalSurface:not([style*="display: none"]), .balloon', return false;
{ state: 'visible', timeout: 10000 } })()`);
); if (!inGridEdit) {
} catch {} // Form didn't change — server might still be processing.
await waitForStable(); // waitForSelector uses MutationObserver internally — doesn't block event loop.
try {
await page.waitForSelector(
'#modalSurface:not([style*="display: none"]), .balloon',
{ state: 'visible', timeout: 10000 }
);
} catch {}
await waitForStable();
}
} }
} }
@@ -1905,7 +1914,17 @@ export async function fillTableRow(fields, { tab, add, row } = {}) {
// 2. Add new row if requested // 2. Add new row if requested
if (add) { if (add) {
await clickElement('Добавить'); await clickElement('Добавить');
await page.waitForTimeout(1000); // Poll for edit mode (INPUT inside grid) instead of fixed 1000ms wait
for (let aw = 0; aw < 6; aw++) {
await page.waitForTimeout(150);
const ready = await page.evaluate(`(() => {
const f = document.activeElement;
if (!f || (f.tagName !== 'INPUT' && f.tagName !== 'TEXTAREA')) return false;
let n = f; while (n) { if (n.classList?.contains('grid')) return true; n = n.parentElement; }
return false;
})()`);
if (ready) break;
}
} }
// 2b. Enter edit mode on existing row by dblclick // 2b. Enter edit mode on existing row by dblclick
@@ -1953,12 +1972,16 @@ export async function fillTableRow(fields, { tab, add, row } = {}) {
if (cellCoords.error) throw new Error(`fillTableRow: ${cellCoords.error}${cellCoords.total ? ' (total rows: ' + cellCoords.total + ')' : ''}`); if (cellCoords.error) throw new Error(`fillTableRow: ${cellCoords.error}${cellCoords.total ? ' (total rows: ' + cellCoords.total + ')' : ''}`);
await page.mouse.dblclick(cellCoords.x, cellCoords.y); await page.mouse.dblclick(cellCoords.x, cellCoords.y);
await page.waitForTimeout(500); // Poll for edit mode instead of fixed 500ms wait
let inEdit = false;
const inEdit = await page.evaluate(`(() => { for (let dw = 0; dw < 5; dw++) {
const f = document.activeElement; await page.waitForTimeout(150);
return f && f.tagName === 'INPUT'; inEdit = await page.evaluate(`(() => {
})()`); const f = document.activeElement;
return f && f.tagName === 'INPUT';
})()`);
if (inEdit) break;
}
if (!inEdit) throw new Error(`fillTableRow: double-click on row ${row} did not enter edit mode`); if (!inEdit) throw new Error(`fillTableRow: double-click on row ${row} did not enter edit mode`);
} }