#!/usr/bin/env node /** * Focused case: 场景 -> 新建场景 in the ?ui=web entry (desktop operator route). * * node tools/web/complete/probe-scene-new.mjs --base-url http://127.0.0.1:5176 */ import { ASSETS, parseArgs, launchBrowser, newPage, openFile, waitScene } from "../course/lib/lesson-recorder.mjs"; const args = parseArgs(); const BASE = args.baseUrl || "http://127.0.0.1:5176"; const browser = await launchBrowser(args.gpu); const { context, page, consoleErrors } = await newPage(browser, { baseUrl: BASE }); page.setDefaultTimeout(60_000); const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts); const state = async () => page.evaluate(() => ({ stats: document.querySelector('[data-testid="scene-stats"]')?.textContent ?? "", status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "", alerts: Array.from(document.querySelectorAll('[role="alert"]')).map((node) => node.textContent).slice(0, 3), topbar: Array.from(document.querySelectorAll('.topbar-context')).map((node) => node.textContent), sceneSelect: document.querySelector('select[aria-label="当前场景"]')?.value ?? null, })); try { await openFile(page, ASSETS.studio); await waitScene(page, { objects: 6, timeout: 240_000 }); log("start", JSON.stringify(await state())); await page.getByRole("button", { name: "场景", exact: true }).click(); await page.getByRole("menuitem", { name: "新建场景", exact: true }).click(); for (let index = 0; index < 20; index++) { await page.waitForTimeout(500); const current = await state(); if (/已执行|失败|错误|NOT_|FAILED|UNAVAILABLE/.test(current.status) || current.alerts.length) { log("result", JSON.stringify(current)); break; } if (index === 19) log("final", JSON.stringify(current)); } await page.getByRole("button", { name: "场景", exact: true }).click(); await page.getByRole("menuitem", { name: "删除场景", exact: true }).click(); for (let index = 0; index < 20; index++) { await page.waitForTimeout(500); const current = await state(); if (/已执行|失败|错误|NOT_|FAILED|UNAVAILABLE/.test(current.status) || current.alerts.length) { log("delete", JSON.stringify(current)); break; } if (index === 19) log("delete final", JSON.stringify(current)); } } catch (error) { log("probe error", error instanceof Error ? error.message : String(error)); log("state", JSON.stringify(await state().catch(() => null))); } finally { log("consoleErrors", JSON.stringify(consoleErrors.slice(-10))); await context.close(); await browser.close(); }