const path = require("path"); const fs = require("fs"); const root = process.env.PLAYWRIGHT_REQUIRE_FROM; if (!root) throw new Error("PLAYWRIGHT_REQUIRE_FROM is required"); const { chromium } = require(path.join(root, "playwright")); const chromePath = process.env.CHROME_PATH || "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"; const outputDir = path.resolve(process.env.UI_SCREENSHOT_DIR || "test/e2e/screenshots/operations"); fs.mkdirSync(outputDir, { recursive: true }); (async () => { const browser = await chromium.launch({ executablePath: chromePath, headless: true }); const page = await browser.newPage({ viewport: { width: 1440, height: 1200 } }); const failures = []; page.on("pageerror", (error) => failures.push(`pageerror: ${error.message}`)); page.on("console", (message) => { if (message.type() === "error") failures.push(`console: ${message.text()}`); }); page.on("response", (response) => { if (response.status() >= 400) failures.push(`http ${response.status()}: ${response.url()}`); }); await page.goto("http://localhost:3100", { waitUntil: "networkidle" }); const login = page.getByRole("button", { name: "登录研发环境" }); if (await login.isVisible()) { await login.click(); await page.locator("#username").fill("owner"); await page.locator("#password").fill("LocalOnly123!"); await page.locator("#kc-login").click(); } await page.waitForURL("http://localhost:3100/**", { timeout: 15000 }); const alertNavigation = page.getByRole("navigation", { name: "业务工作台导航" }).getByRole("button", { name: /告警处置/ }); await alertNavigation.waitFor({ state: "visible", timeout: 15000 }); await alertNavigation.click(); const workspace = page.getByRole("region", { name: "告警处置工作台" }); await workspace.getByRole("heading", { name: "告警监测与处置闭环" }).waitFor({ state: "visible", timeout: 10000 }); await workspace.scrollIntoViewIfNeeded(); const overflow = await workspace.evaluate((element) => element.scrollWidth > element.clientWidth + 1); if (overflow) failures.push("alert workspace has horizontal overflow"); const summaryCards = await workspace.locator(".alert-summary-grid article").count(); if (summaryCards !== 4) failures.push(`alert summary cards mismatch: ${summaryCards}`); const controls = await workspace.locator("input, select, button").count(); if (controls < 15) failures.push(`alert workspace controls were not rendered: ${controls}`); await workspace.screenshot({ path: path.join(outputDir, "ops-alert-workspace.png") }); await browser.close(); if (failures.length) throw new Error(failures.join("\n")); process.stdout.write(`Alert UI browser smoke passed. Screenshot: ${outputDir}\n`); })().catch((error) => { process.stderr.write(`${error.stack || error}\n`); process.exitCode = 1; });