/** * UI review evidence capture. Credentials via env only; never log password. * WATCHMAN_UI_USER / WATCHMAN_UI_PASSWORD */ import { chromium } from "@playwright/test"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const user = process.env.WATCHMAN_UI_USER; const password = process.env.WATCHMAN_UI_PASSWORD; if (!user || !password) { console.error("Missing WATCHMAN_UI_USER or WATCHMAN_UI_PASSWORD"); process.exit(1); } const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../"); const outDir = path.join(root, "docs/evidence/ui-review/2026-11-19-console-full/screenshots"); fs.mkdirSync(outDir, { recursive: true }); const routes = [ { key: "home", path: "/#/" }, { key: "datasources", path: "/#/datasources" }, { key: "queries", path: "/#/queries" }, { key: "mappings", path: "/#/mappings" }, { key: "alarms", path: "/#/alarms" }, ]; const viewports = [ { name: "1440x900", width: 1440, height: 900 }, { name: "1280x800", width: 1280, height: 800 }, ]; async function login(page) { await page.goto("http://127.0.0.1:5173/", { waitUntil: "networkidle" }); await page.getByTestId("login-username").locator("input").fill(user); await page.getByTestId("login-password").locator("input").fill(password); await page.getByTestId("login-submit").click(); await page.getByTestId("logout").waitFor({ timeout: 20000 }); } async function shot(page, name) { await page.waitForTimeout(400); await page.screenshot({ path: path.join(outDir, name), fullPage: false }); } const browser = await chromium.launch({ headless: true }); const context = await browser.newContext(); const page = await context.newPage(); await page.setViewportSize(viewports[0]); await login(page); await shot(page, "home-1440x900-data-01.png"); // keyboard focus on home then datasources filter await page.goto("http://127.0.0.1:5173/#/datasources", { waitUntil: "networkidle" }); await page.waitForTimeout(600); await shot(page, "datasources-1440x900-data-02.png"); const nameFilter = page.getByTestId("datasource-filter-name").locator("input"); if (await nameFilter.count()) { await page.keyboard.press("Tab"); await page.keyboard.press("Tab"); await page.keyboard.press("Tab"); await page.keyboard.press("Tab"); await page.keyboard.press("Tab"); // focus name filter explicitly via real Tab from a known start await page.locator("body").click({ position: { x: 5, y: 5 } }); for (let i = 0; i < 12; i++) { await page.keyboard.press("Tab"); const active = await page.evaluate(() => { const el = document.activeElement; return { tag: el?.tagName, testid: el?.closest("[data-testid]")?.getAttribute("data-testid") || null, placeholder: el?.getAttribute("placeholder"), }; }); if (active.testid === "datasource-filter-name" || active.placeholder === "名称") { await shot(page, "datasources-1440x900-keyboard-focus-03.png"); const styles = await page.evaluate(() => { const el = document.activeElement; const wrap = el?.closest(".el-input__wrapper") || el; const cs = getComputedStyle(wrap); return { outline: cs.outline, boxShadow: cs.boxShadow, borderColor: cs.borderColor }; }); fs.writeFileSync( path.join(outDir, "..", "focus-styles.json"), JSON.stringify(styles, null, 2), "utf8", ); break; } } await nameFilter.fill("__no_match_ui_review__"); await page.getByRole("button", { name: "查询" }).click(); await page.waitForTimeout(500); await shot(page, "datasources-1440x900-empty-filter-04.png"); await page.getByRole("button", { name: "重置" }).click(); await page.waitForTimeout(500); } await page.goto("http://127.0.0.1:5173/#/queries", { waitUntil: "networkidle" }); await page.waitForTimeout(600); await shot(page, "queries-1440x900-data-05.png"); await page.goto("http://127.0.0.1:5173/#/mappings", { waitUntil: "networkidle" }); await page.waitForTimeout(600); await shot(page, "mappings-1440x900-data-06.png"); await page.goto("http://127.0.0.1:5173/#/alarms", { waitUntil: "networkidle" }); await page.waitForTimeout(600); await shot(page, "alarms-1440x900-data-07.png"); // second viewport sweep await page.setViewportSize(viewports[1]); for (const r of routes) { await page.goto(`http://127.0.0.1:5173${r.path}`, { waitUntil: "networkidle" }); await page.waitForTimeout(500); await shot(page, `${r.key}-1280x800-data-08.png`.replace("data-08", `data-${r.key}-08`)); } // open first datasource detail if row exists await page.setViewportSize(viewports[0]); await page.goto("http://127.0.0.1:5173/#/datasources", { waitUntil: "networkidle" }); await page.waitForTimeout(500); const openBtn = page.getByRole("button", { name: "打开" }).first(); if (await openBtn.count()) { await openBtn.click(); await page.waitForTimeout(700); await shot(page, "datasource-detail-1440x900-data-09.png"); } const alarmOpen = page.locator("a, button").filter({ hasText: /打开|详情/ }).first(); await page.goto("http://127.0.0.1:5173/#/alarms", { waitUntil: "networkidle" }); await page.waitForTimeout(500); const alarmRowOpen = page.getByRole("button", { name: "打开" }).first(); if (await alarmRowOpen.count()) { await alarmRowOpen.click(); await page.waitForTimeout(700); await shot(page, "alarm-detail-1440x900-data-10.png"); } // scroll metrics const metrics = {}; for (const r of routes) { await page.goto(`http://127.0.0.1:5173${r.path}`, { waitUntil: "networkidle" }); await page.waitForTimeout(300); metrics[r.key] = await page.evaluate(() => ({ innerWidth: window.innerWidth, innerHeight: window.innerHeight, scrollHeight: document.documentElement.scrollHeight, clientHeight: document.documentElement.clientHeight, bodyScroll: document.body.scrollHeight === document.body.clientHeight, })); } fs.writeFileSync(path.join(outDir, "..", "viewport-metrics.json"), JSON.stringify(metrics, null, 2), "utf8"); await browser.close(); console.log("capture complete");