From 2543fb2c18cc7329a6d2c4a87b40b589680baad9 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 21 Oct 2026 02:30:52 +0800 Subject: [PATCH] gui tests: routing-bodies and routing-request-metrics wheel to a row like a reader before clicking it (#2559, #2658) routing-bodies has been red since it was added (af601541e, 10-16): its pick(1)/pick(2) never pressed the body choice. routing-request-metrics' 480px tap was flaky the same way. Cause: both brought the row into view from code (locator.scrollIntoViewIfNeeded, element.scrollIntoView in an evaluate). The app puts back any scroll that isn't the reader's (app.js, "where the reader is"), so by the click the row was back under the footer or out of the window, and the click landed on the footer, a .rt-steps li.why or a .rt-cap instead. Both taps now use reader.cjs's reach, which wheels like a reader until the control is clear in its view, then click its center. The page is unchanged. Red before: with an injected 300ms wait between the scroll and the click, the old routing-bodies is 10 of 10 red (at pick(1)) and the old routing-request-metrics 4 of 4 red (waiting for the Cost menuitemcheckbox); the new ones 10 of 10 and 4 of 4 green under the same wait. Without injection, the old routing-bodies was 10 of 10 red on this machine. Run (macOS, Playwright 1.62.0, chromium and webkit, every language and width the files run, load average 60-190 from other sessions): - alone: routing-bodies 10 of 10, routing-request-metrics 4 of 4 green. - under --test-concurrency=6 with every GUI file that uses reach or wheelTo (37 files, 590 tests): 590 of 590 green. --- internal/gui/tests/routing-bodies.test.cjs | 9 +++++++-- internal/gui/tests/routing-request-metrics.test.cjs | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/gui/tests/routing-bodies.test.cjs b/internal/gui/tests/routing-bodies.test.cjs index 556bf0c1a..a8b87a464 100644 --- a/internal/gui/tests/routing-bodies.test.cjs +++ b/internal/gui/tests/routing-bodies.test.cjs @@ -12,6 +12,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { reach } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const now = new Date(); @@ -105,9 +106,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }); // a click at the middle of what is shown: with the page scrolled down // to the story, Playwright's WebKit places what sits in a scroller - // ~700px lower than it shows, and clicks the footer instead + // ~700px lower than it shows, and clicks the footer instead. The + // reader wheels it into sight first (reach): the page puts back any + // scroll that isn't the reader's, and Playwright's + // scrollIntoViewIfNeeded is code, so the row it scrolled to was put + // back under the footer or out of the window before the click (#2559). const tap = async (loc) => { - await loc.scrollIntoViewIfNeeded(); + await reach(page, loc); const [x, y] = await loc.evaluate((e) => { const r = e.getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; }); await page.mouse.click(x, y); }; diff --git a/internal/gui/tests/routing-request-metrics.test.cjs b/internal/gui/tests/routing-request-metrics.test.cjs index 02dd375d7..4773d0fe4 100644 --- a/internal/gui/tests/routing-request-metrics.test.cjs +++ b/internal/gui/tests/routing-request-metrics.test.cjs @@ -5,6 +5,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { reach } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const now = new Date(); @@ -144,9 +145,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // clicks where the page shows the picker and its menu: once the // story's head wraps at this width (its "Request and response" // button) the page is scrolled, and Playwright's WebKit then - // places them hundreds of pixels lower, under the footer + // places them hundreds of pixels lower, under the footer. The + // reader wheels to them first (reach): the page puts back a + // scroll that isn't the reader's, as scrollIntoView from here + // is, and the click landed on whatever the put-back left there + // (#2658) const tap = async (loc) => { - const [x, y] = await loc.evaluate((e) => { e.scrollIntoView({ block: "center" }); const r = e.getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; }); + await reach(page, loc); + const [x, y] = await loc.evaluate((e) => { const r = e.getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; }); await page.mouse.click(x, y); }; await tap(page.locator("#rtMetrics"));