test(web): 生产核对脚本自己等节流,别把 429 当成登录坏了
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* 生产只读核对:首页外壳、账号页、工作区页的宽度是否一致。
|
||||
* 生产只读核对:首页、工作区页、账号页是不是同一套外壳,宽度是否一致。
|
||||
*
|
||||
* 这个脚本**不写数据**:不设密码、不改昵称,只用验证码登录看界面。
|
||||
* 生产是内测模式(任意手机号 + 123456),所以用真实账号也能进。
|
||||
* 只读:不设密码、不改昵称,只看界面。生产是内测模式(验证码 123456)。
|
||||
* 注意发码有 60 秒节流:被挡住时要等,别把它当成登录坏了。
|
||||
*/
|
||||
import { chromium } from "playwright-core";
|
||||
|
||||
@@ -18,21 +18,26 @@ const browser = await chromium.launch({
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 960 } });
|
||||
const errors = [];
|
||||
page.on("console", (m) => m.type() === "error" && errors.push(m.text()));
|
||||
page.on("request", (r) => r.url().includes("/api") && console.log("req:", r.method(), r.url()));
|
||||
page.on("response", (r) => r.url().includes("/auth/") && console.log("resp:", r.status(), r.url()));
|
||||
page.on("requestfailed", (r) => r.url().includes("/auth/") && console.log("reqfailed:", r.failure()?.errorText, r.url()));
|
||||
|
||||
await page.goto(`${WEB}/login`);
|
||||
await page.getByLabel("手机号").fill(PHONE);
|
||||
await page.getByRole("button", { name: "获取验证码" }).click();
|
||||
await page.getByLabel("验证码").fill(CODE);
|
||||
await page.getByRole("button", { name: "登录" }).click();
|
||||
await page.waitForTimeout(4000);
|
||||
console.log("url after login:", page.url());
|
||||
console.log("body:", (await page.locator("body").innerText()).replace(/\s+/g, " | ").slice(0, 400));
|
||||
await page.waitForURL(`${WEB}/`, { timeout: 20_000 });
|
||||
await page.waitForSelector("text=我的工作区");
|
||||
|
||||
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" });
|
||||
@@ -41,14 +46,25 @@ 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)));
|
||||
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 bodyText = await page.locator("main").innerText();
|
||||
console.log("账号页文案片段:", bodyText.replace(/\n+/g, " | ").slice(0, 220));
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user