72 lines
2.9 KiB
JavaScript
72 lines
2.9 KiB
JavaScript
/**
|
|
* 生产只读核对:首页、工作区页、账号页是不是同一套外壳,宽度是否一致。
|
|
*
|
|
* 只读:不设密码、不改昵称,只看界面。生产是内测模式(验证码 123456)。
|
|
* 注意发码有 60 秒节流:被挡住时要等,别把它当成登录坏了。
|
|
*/
|
|
import { chromium } from "playwright-core";
|
|
|
|
const WEB = process.env.WEB ?? "http://192.168.8.188:8200";
|
|
const PHONE = process.env.PHONE ?? "13605513683";
|
|
const CODE = process.env.CODE ?? "123456";
|
|
|
|
const browser = await chromium.launch({
|
|
executablePath:
|
|
process.env.CHROME ??
|
|
`${process.env.LOCALAPPDATA}\\ms-playwright\\chromium-1223\\chrome-win64\\chrome.exe`,
|
|
});
|
|
const page = await browser.newPage({ viewport: { width: 1440, height: 960 } });
|
|
const errors = [];
|
|
page.on("console", (m) => m.type() === "error" && errors.push(m.text()));
|
|
|
|
await page.goto(`${WEB}/login`);
|
|
await page.getByLabel("手机号").fill(PHONE);
|
|
|
|
for (let attempt = 1; attempt <= 3 && new URL(page.url()).pathname === "/login"; attempt += 1) {
|
|
await page.getByRole("button", { name: /获取验证码|重新获取|秒/ }).click();
|
|
await page.waitForTimeout(1500);
|
|
const text = await page.locator("body").innerText();
|
|
if (/秒后再试|太频繁/.test(text)) {
|
|
console.log(`发码被节流,等 61 秒(第 ${attempt} 次)`);
|
|
await page.waitForTimeout(61_000);
|
|
continue;
|
|
}
|
|
await page.getByLabel("验证码").fill(CODE);
|
|
await page.getByRole("button", { name: "登录" }).click();
|
|
await page.waitForTimeout(2500);
|
|
}
|
|
|
|
await page.waitForURL(`${WEB}/`, { timeout: 15_000 });
|
|
await page.waitForSelector("text=我的工作区");
|
|
const homeRail = await page.locator("aside").first().boundingBox();
|
|
console.log("首页侧栏宽度:", homeRail?.width);
|
|
await page.screenshot({ path: "e2e/artifacts/prod-home.png" });
|
|
|
|
await page.getByRole("button", { name: /我的备忘/ }).first().click();
|
|
await page.waitForURL(/\/w\//);
|
|
await page.waitForSelector("aside");
|
|
const wsRail = await page.locator("aside").first().boundingBox();
|
|
console.log(
|
|
"工作区侧栏宽度:",
|
|
wsRail?.width,
|
|
"与首页差值:",
|
|
Math.abs((wsRail?.width ?? 0) - (homeRail?.width ?? 0)),
|
|
);
|
|
await page.screenshot({ path: "e2e/artifacts/prod-workspace.png" });
|
|
|
|
await page.goto(`${WEB}/account`);
|
|
await page.waitForSelector("text=登录密码");
|
|
await page.waitForFunction(
|
|
() => document.querySelector('input[aria-label="昵称"]')?.value?.length > 0,
|
|
null,
|
|
{ timeout: 10_000 },
|
|
);
|
|
const accountRail = await page.locator("aside").first().boundingBox();
|
|
console.log("账号页侧栏宽度:", accountRail?.width);
|
|
const accountText = await page.locator("main").innerText();
|
|
console.log("账号页:", accountText.replace(/\s+/g, " | ").slice(0, 260));
|
|
await page.screenshot({ path: "e2e/artifacts/prod-account.png" });
|
|
|
|
console.log("控制台报错:", errors.length === 0 ? "无" : errors.slice(0, 3));
|
|
await browser.close();
|