| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #!/usr/bin/env node
- import { chromium } from "playwright";
- const BASE = process.env.ZQ_BASE_URL || "https://hxcs.feifan.net";
- async function login(page) {
- await page.goto(`${BASE}/apps/workbench/?errpage=toLogin`);
- await page.fill("#uname", process.env.ZQ_USER || "a");
- await page.evaluate(() => document.getElementById("upwd").removeAttribute("readonly"));
- await page.fill("#upwd", process.env.ZQ_PASS || "111111");
- await page.click(".submit");
- await page.waitForTimeout(3000);
- await page.goto(`${BASE}/apps/workbench/`, { waitUntil: "networkidle" });
- }
- async function articleListUrl(page) {
- return page.evaluate(() => {
- const raw = document.body.innerHTML.match(/var moudulesData = '([^']+)'/);
- const data = JSON.parse(raw[1]);
- const walk = (items) => {
- for (const it of items || []) {
- if ((it.name || "").includes("文章")) return it.url;
- const u = walk(it.menuList);
- if (u) return u;
- }
- return null;
- };
- for (const m of data) {
- const u = walk(m.menuList);
- if (u) return u;
- }
- return null;
- });
- }
- async function main() {
- const browser = await chromium.launch({ headless: true });
- const page = await browser.newPage();
- await login(page);
- const artUrl = await articleListUrl(page);
- await page.goto(`${BASE}${artUrl}`, { waitUntil: "networkidle" });
- await page.locator('button:has-text("录入")').first().click();
- let found = false;
- for (let i = 0; i < 40; i++) {
- await page.waitForTimeout(1000);
- for (const frame of page.frames()) {
- if (!frame.url().includes("apps?token")) continue;
- const title = await frame.title().catch(() => "");
- if (!title.includes("发文章")) continue;
- const ck = await frame.locator(".ck-editor").count();
- const video = await frame.locator("text=上传视频").count();
- const pdf = await frame.locator("text=上传PDF").count();
- const layout = await frame.evaluate(() =>
- [...document.scripts].map((s) => s.src).find((s) => s.includes("layout"))
- );
- console.log("PASS 发文章弹窗", { title, ck, video, pdf, layout });
- found = ck > 0 && video > 0 && pdf > 0;
- if (!found) {
- console.error("FAIL 发文章编辑器不完整", { ck, video, pdf });
- process.exit(1);
- }
- await browser.close();
- return;
- }
- }
- const frames = [];
- for (const f of page.frames()) {
- frames.push(`${await f.title().catch(() => "")} | ${f.url()}`);
- }
- console.error("FAIL 未打开发文章弹窗", frames);
- await browser.close();
- process.exit(1);
- }
- main().catch((e) => {
- console.error(e);
- process.exit(1);
- });
|