import { existsSync } from "node:fs"; import { chromium } from "playwright-core"; const OUT = "/opt/uhd_media_tool-deai2/apps/web/test/screenshots/deai2"; const PAGES = [ ["01-home", "/console"], ["02-inbox", "/console/inbox"], ["03-schedules", "/console/schedules"], ["04-agent-run", "/console/agent/a01dccf0-383f-46a9-acec-c2ca3cf571f8"], ["05-organize-detail", "/console/organize/33000000-0000-4000-8000-000000000903"], ["06-download-detail", "/console/downloads/33000000-0000-4000-8000-000000000802"], ["07-tasks", "/console/tasks"], ["08-settings-interface", "/console/settings#interface"], ]; const exe = ["/usr/bin/chromium", "/usr/bin/google-chrome"].find((p) => existsSync(p)); const browser = await chromium.launch({ executablePath: exe, headless: true, args: ["--no-sandbox"] }); for (const [tag, port] of (process.env.ONLY === "after" ? [["after", 5192]] : [["before", 5191], ["after", 5192]])) { const base = `http://127.0.0.1:${port}`; for (const [mode, vp, theme] of [["desk-light", { width: 1440, height: 900 }, "light"], ["desk-dark", { width: 1440, height: 900 }, "dark"], ["mobile", { width: 390, height: 844 }, "light"]]) { const ctx = await browser.newContext({ viewport: vp, colorScheme: theme, deviceScaleFactor: mode === "mobile" ? 2 : 1 }); await ctx.addInitScript((t) => localStorage.setItem("umt-theme", t), theme); const page = await ctx.newPage(); await page.goto(`${base}/login`, { waitUntil: "networkidle" }); await page.fill("#username", "w31-admin"); await page.fill("#password", "deai2-shots-pass"); await page.click('button[type="submit"]'); await page.waitForURL((u) => u.pathname.startsWith("/console"), { timeout: 20_000 }); for (const [name, path] of PAGES) { if (tag === "before" && name === "08-settings-interface") continue; await page.goto(base + path, { waitUntil: "networkidle" }).catch(() => {}); await page.waitForTimeout(1500); await page.screenshot({ path: `${OUT}/${name}-${mode}-${tag}.png`, fullPage: true }); } await ctx.close(); } } await browser.close(); console.log("done");