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 for id:", 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); // Go to preview await page.goto(`${BASE}/courseware/${cwId}/preview`, { waitUntil: "networkidle", timeout: 20000 }); await page.waitForTimeout(3000); // Check rendering const iframes = await page.$$("iframe"); console.log("iframes:", iframes.length); const bodyText = await page.evaluate(() => document.body.innerText.substring(0, 200)); console.log("body text preview:", bodyText.substring(0, 120)); // Check for slide/navigation elements const allDivs = await page.$$("#app div"); console.log("total divs:", allDivs.length); // Check for specific preview elements const slideEls = await page.$$("[class*='slide'], [class*='preview'], [class*='page-nav'], [class*='cw-']"); console.log("slide/preview elements:", slideEls.length); // Look for iframe content for (let i = 0; i < Math.min(iframes.length, 3); i++) { try { const frame = iframes[i].contentFrame(); if (frame) { const content = await frame.evaluate(() => document.body ? document.body.innerText.substring(0, 60) : "empty"); console.log(`iframe[${i}] content:`, content); } } catch(e) { console.log(`iframe[${i}] error:`, e.message.substring(0, 60)); } } // Screenshot await page.screenshot({ path: "_cw_preview.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(); })();