44 lines
2.2 KiB
JavaScript
44 lines
2.2 KiB
JavaScript
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/events");
|
||
|
|
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 });
|
||
|
|
const liveStatus = page.getByText("状态实时更新", { exact: true });
|
||
|
|
await liveStatus.waitFor({ state: "visible", timeout: 10000 });
|
||
|
|
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > document.documentElement.clientWidth + 1);
|
||
|
|
if (overflow) failures.push("workspace has horizontal overflow");
|
||
|
|
await liveStatus.scrollIntoViewIfNeeded();
|
||
|
|
await page.screenshot({ path: path.join(outputDir, "event-stream-connected.png"), fullPage: false });
|
||
|
|
|
||
|
|
await browser.close();
|
||
|
|
if (failures.length) throw new Error(failures.join("\n"));
|
||
|
|
process.stdout.write(`Event stream browser smoke passed. Screenshot: ${outputDir}\n`);
|
||
|
|
})().catch((error) => {
|
||
|
|
process.stderr.write(`${error.stack || error}\n`);
|
||
|
|
process.exitCode = 1;
|
||
|
|
});
|