const { chromium } = require("playwright-core"); const fs = require("fs"); (async () => { const cwId = fs.readFileSync("D:/AI/jiaoyu/_cw_id.txt","utf8").trim(); console.log("testing courseware preview at /preview/" + cwId); const browser = await chromium.launch({ executablePath: "C:/Program Files/Google/Chrome/Application/chrome.exe", args: ["--disable-blink-features=AutomationControlled"], }); const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }); const errors = []; page.on("console", msg => { if (msg.type() === "error") errors.push(msg.text()); }); page.on("pageerror", err => errors.push(err.message)); const BASE = "http://127.0.0.1:5175"; const loginResp = await page.request.post("http://127.0.0.1:8010/api/auth/login", { data: { phone: "13943441149", password: "Test1234" }, }); const token = (await loginResp.json()).access_token; await page.goto(BASE + "/login", { waitUntil: "networkidle" }); await page.evaluate(t => { localStorage.setItem("token", t); localStorage.setItem("access_token", t); localStorage.setItem("zj_token", t); }, token); // Correct URL: /preview/:id await page.goto(`${BASE}/preview/${cwId}`, { waitUntil: "networkidle", timeout: 20000 }); await page.waitForTimeout(4000); const iframes = await page.$$("iframe"); console.log("iframes:", iframes.length); // Check iframe content for (let i = 0; i < Math.min(iframes.length, 2); i++) { try { const frame = iframes[i].contentFrame(); if (frame) { const html = await frame.evaluate(() => document.documentElement.outerHTML.substring(0, 200)); console.log(`iframe[${i}] html:`, html.substring(0, 150)); } } catch(e) { console.log(`iframe[${i}] error:`, e.message.substring(0, 80)); } } // Check page navigation const navBtns = await page.$$("button"); const navTexts = []; for (const btn of navBtns) { const text = await btn.textContent(); if (text.trim()) navTexts.push(text.trim().substring(0, 20)); } console.log("buttons:", navTexts.slice(0, 10)); // Page counter const bodyText = await page.evaluate(() => document.body.innerText); const pageMatch = bodyText.match(/(\d+)\s*\/\s*(\d+)/); if (pageMatch) console.log("page counter:", pageMatch[0]); await page.screenshot({ path: "_cw_preview2.png" }); console.log("screenshot saved"); const realErrors = errors.filter(e => !e.includes("401") && !e.includes("403") && !e.includes("Failed to fetch")); console.log("\nerrors (filtered):", realErrors.length); realErrors.slice(0, 3).forEach(e => console.log(" ", e.substring(0,120))); await browser.close(); })();