From 69e428fe64d362cfdbcc1267bb3e2ca62983c53b Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 8 Jul 2026 10:52:39 +0200 Subject: [PATCH] test(web-app-dashboard): make dashboard E2E reliable over onion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore Keycloak's third-party-cookie probe (/3p-cookies/, requestStorageAccess) in the console-error assertion — that probe errors by design when 3p cookies are blocked (always over onion) and is Keycloak feature-detection, not a dashboard fault; real dashboard console errors still fail. Fix the iframe-sync race by re-dispatching inside the poll until the CDN-loaded listener is live (over Tor it loads after DOMContentLoaded). Co-Authored-By: Claude Opus 4.8 --- .../files/playwright/_shared.js | 25 +++++++++++++++---- .../files/playwright/test-iframe-sync.js | 20 +++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/roles/web-app-dashboard/files/playwright/_shared.js b/roles/web-app-dashboard/files/playwright/_shared.js index cd1ca7da39..b3f16b5783 100644 --- a/roles/web-app-dashboard/files/playwright/_shared.js +++ b/roles/web-app-dashboard/files/playwright/_shared.js @@ -1,4 +1,5 @@ const { expect } = require("@playwright/test"); +const { resolveTimeout } = require("./timeouts"); const { normalizeBaseUrl } = require("./personas"); const { isServiceEnabled, skipUnlessServiceEnabled } = require("./service-gating"); @@ -76,12 +77,26 @@ function isMatomoConsoleNoise(record) { ); } +function isKeycloak3pCookieNoise(record) { + if (!record) { + return false; + } + const text = typeof record === "string" ? record : record.text || ""; + const url = typeof record === "string" ? "" : record.url || ""; + return ( + /\/3p-cookies\//.test(url) || + /requestStorageAccess/i.test(text) + ); +} + function expectNoUnexpectedDiagnostics( diagnostics, { ignoreMatomoConsoleNoise = false } = {} ) { expect(diagnostics.pageErrors, `Unexpected page errors: ${diagnostics.pageErrors.join("\n")}`).toEqual([]); - let unexpectedConsoleErrors = diagnostics.consoleErrors; + let unexpectedConsoleErrors = diagnostics.consoleErrors.filter( + (record) => !isKeycloak3pCookieNoise(record) + ); if (ignoreMatomoConsoleNoise) { unexpectedConsoleErrors = unexpectedConsoleErrors.filter((record) => !isMatomoConsoleNoise(record)); } @@ -92,9 +107,9 @@ function expectNoUnexpectedDiagnostics( } async function waitForDashboardReady(page) { - await expect(page.locator("main#main")).toBeVisible({ timeout: 60_000 }); - await expect(page.locator("header.header")).toBeVisible({ timeout: 60_000 }); - await expect(page.locator("#navbar_logo img")).toBeVisible({ timeout: 60_000 }); + await expect(page.locator("main#main")).toBeVisible({ timeout: resolveTimeout(60_000) }); + await expect(page.locator("header.header")).toBeVisible({ timeout: resolveTimeout(60_000) }); + await expect(page.locator("#navbar_logo img")).toBeVisible({ timeout: resolveTimeout(60_000) }); } async function waitForResourceResponse(records, partialUrl, label) { @@ -103,7 +118,7 @@ async function waitForResourceResponse(records, partialUrl, label) { () => records.some((record) => record.url.includes(partialUrl) && record.status >= 200 && record.status < 400), { - timeout: 60_000, + timeout: resolveTimeout(60_000), message: `Expected ${label} to load successfully (${partialUrl})`, } ) diff --git a/roles/web-app-dashboard/files/playwright/test-iframe-sync.js b/roles/web-app-dashboard/files/playwright/test-iframe-sync.js index 6a09abaf88..f645cd333a 100644 --- a/roles/web-app-dashboard/files/playwright/test-iframe-sync.js +++ b/roles/web-app-dashboard/files/playwright/test-iframe-sync.js @@ -1,4 +1,5 @@ const { test, expect } = require("@playwright/test"); +const { resolveTimeout } = require("./timeouts"); exports.register = function (shared) { test("dashboard iframe sync JavaScript responds to iframeLocationChange events", async ({ page }) => { @@ -9,16 +10,19 @@ exports.register = function (shared) { await shared.waitForDashboardReady(page); const iframeTargetUrl = `${shared.env.matomoBaseUrl}/?playwright-iframe-sync=1`; - await page.evaluate(({ href, origin }) => { - window.dispatchEvent(new MessageEvent("message", { - origin, - data: { type: "iframeLocationChange", href }, - })); - }, { href: iframeTargetUrl, origin: new URL(iframeTargetUrl).origin }); + const messagePayload = { href: iframeTargetUrl, origin: new URL(iframeTargetUrl).origin }; await expect - .poll(() => page.evaluate(() => new URL(window.location.href).searchParams.get("iframe")), { - timeout: 10_000, + .poll(async () => { + await page.evaluate(({ href, origin }) => { + window.dispatchEvent(new MessageEvent("message", { + origin, + data: { type: "iframeLocationChange", href }, + })); + }, messagePayload); + return page.evaluate(() => new URL(window.location.href).searchParams.get("iframe")); + }, { + timeout: resolveTimeout(15_000), message: "Expected dashboard iframe sync JavaScript to update the iframe query parameter", }) .toBe(iframeTargetUrl);