Files
workinf_Blender_Wasm/tools/web/complete/probe-theme.mjs
mes123456 258dcf0098
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
test(web): record high-contrast theme and keyframe dope sheet evidence
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-14 10:00:10 +08:00

68 lines
3.8 KiB
JavaScript

#!/usr/bin/env node
/**
* Focused case: switch the theme preset in Preferences and observe the shell.
*
* node tools/web/complete/probe-theme.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 themeState = async () => page.evaluate(() => ({
theme: document.documentElement.dataset.theme ?? null,
background: getComputedStyle(document.body).backgroundColor,
status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "",
}));
try {
await openFile(page, ASSETS.studio);
await waitScene(page, { objects: 6, timeout: 240_000 });
log("before", JSON.stringify(await themeState()));
await page.getByRole("button", { name: "编辑", exact: true }).click();
await page.getByRole("menuitem", { name: "偏好设置", exact: true }).click();
await page.getByRole("dialog", { name: "Web Blender 偏好设置" }).waitFor({ timeout: 30_000 });
await page.getByRole("button", { name: "主题", exact: true }).click();
const select = page.getByRole("combobox", { name: "主题预设", exact: true });
await select.waitFor({ timeout: 30_000 });
log("theme options", JSON.stringify(await select.locator("option").evaluateAll((nodes) => nodes.map((node) => node.value))));
await select.selectOption("LIGHT");
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(800);
log("light", JSON.stringify(await themeState()));
await page.getByRole("button", { name: "编辑", exact: true }).click();
await page.getByRole("menuitem", { name: "偏好设置", exact: true }).click();
await page.getByRole("button", { name: "主题", exact: true }).click();
await page.getByRole("combobox", { name: "主题预设", exact: true }).selectOption("DARK");
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(800);
log("dark", JSON.stringify(await themeState()));
await page.getByRole("button", { name: "编辑", exact: true }).click();
await page.getByRole("menuitem", { name: "偏好设置", exact: true }).click();
await page.getByRole("button", { name: "主题", exact: true }).click();
await page.getByRole("combobox", { name: "主题预设", exact: true }).selectOption("HIGH_CONTRAST");
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(800);
const high = await page.evaluate(() => {
const frame = document.querySelector('.area-frame');
const style = frame ? getComputedStyle(frame) : null;
return { theme: document.documentElement.dataset.theme ?? null, outline: style ? `${style.outlineStyle} ${style.outlineWidth} ${style.outlineColor}` : null };
});
log("high-contrast", JSON.stringify(high));
await page.getByRole("button", { name: "编辑", exact: true }).click();
await page.getByRole("menuitem", { name: "偏好设置", exact: true }).click();
await page.getByRole("button", { name: "主题", exact: true }).click();
await page.getByRole("combobox", { name: "主题预设", exact: true }).selectOption("DARK");
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(500);
} catch (error) {
log("probe error", error instanceof Error ? error.message : String(error));
log("state", JSON.stringify(await themeState().catch(() => null)));
} finally {
log("consoleErrors", JSON.stringify(consoleErrors.slice(-8)));
await context.close();
await browser.close();
}