test(web-app-dashboard): make dashboard E2E reliable over onion

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 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 4.8 committed 2026-07-08 10:52:39 +02:00
1 parent f2cb8bfacb
commit 69e428fe64
2 files changed
+32 -13

No files matched your search

@@ -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})`,
}
)
@@ -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);