import fs from "node:fs"; import { parseArgs, waitForServer, launchBrowser, newPage, openFile, waitScene, switchWorkspace } from "../course/lib/lesson-recorder.mjs"; const args = parseArgs(); const BASE = `http://127.0.0.1:${args.port}`; await waitForServer(`${BASE}/?ui=web`); const browser = await launchBrowser(args.gpu); const { context, page } = await newPage(browser, { baseUrl: BASE }); page.setDefaultTimeout(15000); await openFile(page, "/home/mes123456/workinf_Blender_Wasm/web/app/public/tutorial/pbr/studio.blend"); await waitScene(page, { objects: 6, timeout: 240000 }); await openFile(page, "/home/mes123456/workinf_Blender_Wasm/re/猴头.glb"); await waitScene(page, { objects: 7, active: "Suzanne", timeout: 240000 }); await switchWorkspace(page, "Shading"); await page.locator(".pbr-asset-library").waitFor({ timeout: 60000 }); await page.locator('select[aria-label="资产来源"]').selectOption("library:re-pbr-v1"); await page.waitForFunction(() => document.querySelectorAll('[data-library="library:re-pbr-v1"]').length === 6, null, { timeout: 60000 }); const dump = async (label) => { const data = await page.evaluate(() => ({ engine: document.querySelector('[data-testid="engine-status"]')?.textContent, engineTitle: document.querySelector('[data-testid="engine-status"]')?.getAttribute("title"), alerts: Array.from(document.querySelectorAll('[role="alert"], [role="status"]')).map((e) => e.textContent).filter(Boolean).slice(0, 20), libraryText: document.querySelector(".pbr-asset-library")?.textContent?.slice(0, 800), slots: Array.from(document.querySelectorAll('select[aria-label^="材质槽"]')).map((s) => ({ value: s.value, options: Array.from(s.options).map((o) => o.textContent).slice(0, 12) })), images: document.querySelectorAll('.pbr-asset-card img').length, })); console.log(`=== ${label} ===`); console.log(JSON.stringify(data, null, 1)); }; await dump("before"); const card = page.locator('[data-library="library:re-pbr-v1"]', { hasText: "black_tiles_wall" }).first(); console.log("card count", await card.count()); await card.evaluate((element) => element.dispatchEvent(new MouseEvent("dblclick", { bubbles: true, cancelable: true, view: window }))); await page.waitForTimeout(8000); await dump("after-dblclick"); await page.screenshot({ path: "/tmp/probe-library.png", fullPage: true }); await context.close(); await browser.close();