72 lines
3.0 KiB
JavaScript
72 lines
3.0 KiB
JavaScript
// 二期第6段验收抓图:自由创作「引用平台素材」弹窗(资产库 / 模特库 / 商品库三 tab)
|
|
import { chromium } from "playwright";
|
|
import { mkdirSync } from "node:fs";
|
|
|
|
const BASE = process.env.BASE || "http://127.0.0.1:5173";
|
|
const API = process.env.API || "http://127.0.0.1:8010";
|
|
const OUT = process.argv[2] || "shots-seg6";
|
|
mkdirSync(OUT, { recursive: true });
|
|
|
|
const login = await (await fetch(`${API}/api/auth/login/`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ username: "airshelf", password: "Restraint2026" })
|
|
})).json();
|
|
const tok = login.token;
|
|
|
|
const browser = await chromium.launch();
|
|
const ctx = await browser.newContext({ viewport: { width: 1440, height: 940 }, deviceScaleFactor: 2 });
|
|
await ctx.addInitScript((t) => localStorage.setItem("airshelf_token", t), tok);
|
|
const page = await ctx.newPage();
|
|
page.on("pageerror", (e) => console.error(" pageerror:", e.message));
|
|
|
|
async function shot(name, locator) {
|
|
const box = locator ? await locator.boundingBox() : null;
|
|
await page.screenshot({ path: `${OUT}/${name}.png`, ...(box ? { clip: box } : {}) });
|
|
console.log("shot", name);
|
|
}
|
|
|
|
await page.goto(`${BASE}/free-create`, { waitUntil: "networkidle", timeout: 40000 });
|
|
await page.waitForTimeout(1500);
|
|
await shot("0-page");
|
|
|
|
await page.getByRole("button", { name: "引用平台素材", exact: true }).click();
|
|
await page.waitForTimeout(1200);
|
|
const modal = page.locator(".fc-lib-modal");
|
|
await shot("1-assets-tab", modal);
|
|
|
|
const cards = await page.locator(".fc-lib-asset").count();
|
|
const pickable = await page.locator(".fc-lib-asset.pickable").count();
|
|
const pills = await page.locator(".fc-lib-status").allTextContents();
|
|
console.log(`资产库:${cards} 张,可引用 ${pickable} 张,拦截徽标:`, [...new Set(pills)]);
|
|
|
|
// 4.2 拦截态:上传来源且没审过的卡应当有「待送审」徽标 + 送审按钮,且不可点选
|
|
const pending = page.locator(".fc-lib-asset", { has: page.locator(".fc-lib-status") }).first();
|
|
if (await pending.count()) {
|
|
await pending.scrollIntoViewIfNeeded();
|
|
await page.waitForTimeout(300);
|
|
await shot("1b-review-gate", pending);
|
|
console.log("拦截卡有送审按钮:", await pending.locator(".fc-lib-review-btn").count() > 0);
|
|
console.log("拦截卡可点选:", await pending.evaluate((el) => el.classList.contains("pickable")));
|
|
}
|
|
|
|
await page.locator(".fc-lib-tabs .tab", { hasText: "模特库" }).click();
|
|
await page.waitForTimeout(1200);
|
|
await shot("2-models-tab", modal);
|
|
console.log("模特卡:", await page.locator(".fc-lib-asset").count());
|
|
|
|
await page.locator(".fc-lib-tabs .tab", { hasText: "商品库" }).click();
|
|
await page.waitForTimeout(1200);
|
|
await shot("3-products-tab", modal);
|
|
const products = await page.locator(".fc-lib-asset").count();
|
|
console.log("商品卡:", products);
|
|
|
|
if (products > 0) {
|
|
await page.locator(".fc-lib-asset").first().click();
|
|
await page.waitForTimeout(1500);
|
|
await shot("4-product-drilldown", modal);
|
|
}
|
|
|
|
await browser.close();
|
|
console.log("DONE ->", OUT);
|