test(e2e): look for a hittable channel link until one is, not once on a fresh load

This commit is contained in:
2026-10-29 22:37:14 +01:00
parent 41ad538edc
commit 6986eb1937
+16 -4
View File
@@ -34,9 +34,14 @@ export async function gotoPage(page: Page, id: string): Promise<void> {
* can sit under the page chrome above the scroller (the update banner, the toolbar band), and the * can sit under the page chrome above the scroller (the update banner, the toolbar band), and the
* covered click makes Playwright scroll and retry — the same move (webkit failed 3 in 24). * covered click makes Playwright scroll and retry — the same move (webkit failed 3 in 24).
* So the link must be the element hit at its own centre. Returns false if none found. * So the link must be the element hit at its own centre. Returns false if none found.
* Looked for again until one is, not once: a fresh load is still settling when the first card shows
* (the links move down ~55px), and webkit can answer the hit test at a link's new centre with the
* card under it — every link missed in 1 of 30 runs.
*/ */
export async function clickVisibleChannelLink(page: Page): Promise<boolean> { export async function clickVisibleChannelLink(page: Page): Promise<boolean> {
const links = page.getByTestId("video-card-channel").filter({ visible: true }); const links = page.getByTestId("video-card-channel").filter({ visible: true });
let index = -1;
const findHittable = async () => {
const count = await links.count(); const count = await links.count();
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
const hittable = await links.nth(i).evaluate((el) => { const hittable = await links.nth(i).evaluate((el) => {
@@ -44,12 +49,19 @@ export async function clickVisibleChannelLink(page: Page): Promise<boolean> {
const hit = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); const hit = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
return hit !== null && el.contains(hit); return hit !== null && el.contains(hit);
}); });
if (hittable) { if (hittable) return i;
await links.nth(i).click();
return true;
}
} }
return -1;
};
try {
await expect
.poll(async () => (index = await findHittable()), { timeout: 5000 })
.toBeGreaterThan(-1);
} catch {
return false; return false;
}
await links.nth(index).click();
return true;
} }
/** /**