const path = require("path"); const fs = require("fs"); const playwrightRoot = process.env.PLAYWRIGHT_REQUIRE_FROM; if (!playwrightRoot) throw new Error("PLAYWRIGHT_REQUIRE_FROM is required"); const { chromium } = require(path.join(playwrightRoot, "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/sharing"); fs.mkdirSync(outputDir, { recursive: true }); (async () => { const browser = await chromium.launch({ executablePath: chromePath, headless: true }); const page = await browser.newPage({ viewport: { width: 1280, height: 900 } }); 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 }); await page.getByRole("button", { name: "资源分享" }).click(); await page.getByText("创建具体资源分享", { exact: true }).waitFor({ state: "visible", timeout: 10000 }); const overflow = await page.evaluate(() => document.documentElement.scrollWidth > document.documentElement.clientWidth + 1); if (overflow) failures.push("sharing workspace has horizontal overflow"); await page.screenshot({ path: path.join(outputDir, "sharing-management.png"), fullPage: true }); await browser.close(); if (failures.length) throw new Error(failures.join("\n")); process.stdout.write(`Sharing UI browser smoke passed. Screenshot: ${outputDir}\n`); })().catch((error) => { process.stderr.write(`${error.stack || error}\n`); process.exitCode = 1; });