diff --git a/frontend/e2e/helpers.ts b/frontend/e2e/helpers.ts index e4ddef32..b9407f91 100644 --- a/frontend/e2e/helpers.ts +++ b/frontend/e2e/helpers.ts @@ -34,22 +34,34 @@ export async function gotoPage(page: Page, id: string): Promise { * 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). * 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 { const links = page.getByTestId("video-card-channel").filter({ visible: true }); - const count = await links.count(); - for (let i = 0; i < count; i++) { - const hittable = await links.nth(i).evaluate((el) => { - const r = el.getBoundingClientRect(); - const hit = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); - return hit !== null && el.contains(hit); - }); - if (hittable) { - await links.nth(i).click(); - return true; + let index = -1; + const findHittable = async () => { + const count = await links.count(); + for (let i = 0; i < count; i++) { + const hittable = await links.nth(i).evaluate((el) => { + const r = el.getBoundingClientRect(); + const hit = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); + return hit !== null && el.contains(hit); + }); + if (hittable) return i; } + 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; } /**