gui tests: plugin-page waits for the glance's text instead of throwing before it is drawn (#4180)

In Chromium, frameReady can hand back the glance frame before its #cost
element exists. getElementById("cost").textContent then throws inside
waitForFunction, and Playwright fails on a predicate's throw instead of
polling it again. It was red about 4 runs in 5 on the Windows box, on
origin/main f463a8aaf too. The four predicates that read an element's
text (the cost, and the nav label in ja and en) now read it with ?., so
a missing element is "not yet".

Run: win-run BROWSER=chromium node --test plugin-page.test.cjs, 5 of 5
green (3/3 each). Before: 1 of 5.

Fixes #4180
This commit is contained in:
yetone
2026-10-29 14:28:24 +08:00
parent 5eab14a8cc
commit dbdc6b87bb
+4 -4
View File
@@ -165,9 +165,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
if (lang === "de") {
// a new language retitles the tab, and back
await page.evaluate(() => setLocale("ja"));
await page.waitForFunction(() => document.querySelector("#nav button[data-plugin-page] span").textContent === "使用量の概要");
await page.waitForFunction(() => document.querySelector("#nav button[data-plugin-page] span")?.textContent === "使用量の概要");
await page.evaluate(() => setLocale("de"));
await page.waitForFunction(() => document.querySelector("#nav button[data-plugin-page] span").textContent === "Usage glance");
await page.waitForFunction(() => document.querySelector("#nav button[data-plugin-page] span")?.textContent === "Usage glance");
}
// no frame until the page is looked at
assert.equal(await page.locator("iframe.plugin-frame").count(), 0, `${where}: nothing loaded unseen`);
@@ -176,7 +176,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.evaluate(() => show("plugin-glance"));
const glance = await frameReady(page, GLANCE);
assert.equal(await page.locator("#view-plugin-glance iframe").getAttribute("sandbox"), "allow-scripts", where);
await glance.waitForFunction(() => document.getElementById("cost").textContent === "$0.50");
await glance.waitForFunction(() => document.getElementById("cost")?.textContent === "$0.50");
assert.equal(await glance.locator("#calls").textContent(), "12 calls, 1234 tokens", where);
assert.deepEqual(seen.reads.map((r) => [r.spec, r.read]), [["/x/glance", "usage:summary"]], where);
assert.equal(await glance.evaluate(() => document.documentElement.lang), lang, `${where}: the window's language`);
@@ -185,7 +185,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await glance.waitForFunction(() => document.documentElement.dataset.theme === "dark");
assert.ok((await glance.evaluate(() => document.documentElement.style.getPropertyValue("--magpie-bg"))).length > 0, `${where}: the tokens`);
await glance.locator("#hide").click();
await glance.waitForFunction(() => document.getElementById("cost").textContent === "");
await glance.waitForFunction(() => document.getElementById("cost")?.textContent === "");
assert.deepEqual(seen.options.map((o) => [o.spec, o.options.hideCost]), [["/x/glance", true]], `${where}: its own options`);
// the frame fits the window
assert.ok(await page.evaluate(() => { const v = document.querySelector("#view-plugin-glance"); const f = v.querySelector("iframe"); return f.getBoundingClientRect().width <= v.clientWidth + 1 && v.scrollWidth <= v.clientWidth + 1 && f.getBoundingClientRect().height > 200; }), `${where}: fits`);