import { expect, test, type Page } from "./support/deployed-test"; import fs from "node:fs"; import { FIXTURES, gotoApp, openProject, receipt, shot, waitForObjects } from "./support/deployed"; /** * Manual part E (ch22–ch28): camera/light/world/render properties, the PBR * render path with its PNG download, the native render panel, the embedded * WASM F12 path, the compositor, and the import/export matrix. */ test.use({ viewport: { width: 1600, height: 900 } }); async function menu(page: Page, ...items: string[]): Promise { await page.getByRole("button", { name: items[0], exact: true }).click(); for (const name of items.slice(1)) await page.getByRole("menuitem", { name, exact: true }).click(); } async function switchWorkspace(page: Page, name: string): Promise { await page.locator('nav[aria-label="工作区"] button', { hasText: new RegExp(`^${name}$`) }).click(); await expect(page.locator("main.blender-app")).toHaveAttribute("data-workspace", name, { timeout: 15_000 }); } /** The canvas is covered by the native desktop layer which swallows pointer clicks. */ async function clickInApp(page: Page, label: string): Promise { const clicked = await page.evaluate((value) => { const element = document.querySelector(`[aria-label="${value}"]`); if (!(element instanceof HTMLElement)) return false; element.click(); return true; }, label); expect(clicked, `control ${label} must exist`).toBe(true); } test("[ch22] 相机、灯光、世界与渲染属性面板可读", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); const cameraRow = page.getByRole("treeitem").filter({ hasText: /Camera|相机/i }).first(); await expect(cameraRow).toBeVisible({ timeout: 15_000 }); await cameraRow.click(); const properties = page.locator(".area-frame.properties-area").first(); const dataTab = properties.locator('button[title="数据属性"]'); await expect(dataTab).toBeVisible({ timeout: 15_000 }); await dataTab.click(); await expect(properties.getByTestId("object-data-workbench")).toBeVisible({ timeout: 15_000 }); const sections = await properties.locator(".property-section h3").allInnerTexts(); expect(sections.length, "camera data exposes property sections").toBeGreaterThan(0); const lightRow = page.getByRole("treeitem").filter({ hasText: /Light|灯光/i }).first(); if (await lightRow.count()) await lightRow.click(); const image = await shot(page, testInfo, "camera-properties"); receipt(testInfo, { workflow: "select camera -> data properties -> sections; select light", sections: sections.slice(0, 12), screenshot: image, status: "PASS", }); }); test("[ch23] @smoke PBR 渲染生成图像并可下载 PNG", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await page.getByTestId("blend-file-input").setInputFiles(FIXTURES.monkey); await expect.poll(async () => (await page.getByTestId("scene-stats").innerText()).match(/Objects (\d+)/)?.[1], { timeout: 20_000 }).toBe("7"); await switchWorkspace(page, "Rendering"); await page.getByRole("button", { name: "渲染 PBR", exact: true }).click(); await expect.poll(async () => page.locator(".pbr-render-result img").count(), { timeout: 30_000 }).toBe(1); const naturalWidth = await page.locator(".pbr-render-result img").first().evaluate((image) => (image as HTMLImageElement).naturalWidth); expect(naturalWidth, "the rendered image has real pixels").toBeGreaterThan(0); const downloadPromise = page.waitForEvent("download", { timeout: 20_000 }); await page.locator(".pbr-render-download").first().click(); const download = await downloadPromise; expect(download.suggestedFilename()).toMatch(/\.png$/i); const image = await shot(page, testInfo, "pbr-render"); receipt(testInfo, { workflow: "Rendering -> 渲染 PBR -> image -> 下载 PNG", naturalWidth, download: download.suggestedFilename(), screenshot: image, status: "PASS", }); }); test("[ch24] 四条渲染通路各自可辨识", async ({ page, request }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await switchWorkspace(page, "Rendering"); /* Preview / PBR / native / WASM are distinguishable by the surface that * hosts them, not by a label the user has to trust. */ const surfaces = { viewportPreview: await page.locator(".viewport-area canvas.viewport-canvas").count(), pbrPanel: await page.locator(".pbr-render-panel").count(), nativePanel: await page.locator(".native-render-panel").count(), renderResult: await page.locator(".area-frame.render-result-area, .render-result-view").count(), }; expect(surfaces.viewportPreview, "viewport preview is present").toBeGreaterThan(0); expect(surfaces.pbrPanel, "PBR render panel is present").toBeGreaterThan(0); expect(surfaces.nativePanel, "native render panel is present").toBeGreaterThan(0); expect(surfaces.renderResult, "render result area is present").toBeGreaterThan(0); /* The server-side route the manual calls 服务端原生 answers on the origin. */ const describe = await request.post("/api/server-operator-job", { headers: { "x-server-operator-action": "describe", "content-type": "application/json" }, data: {}, }).catch(() => null); const serverRoute = describe ? describe.status() : null; const image = await shot(page, testInfo, "render-paths"); receipt(testInfo, { workflow: "Rendering workspace: preview / PBR panel / native panel / render result + /api/server-operator-job", surfaces, serverOperatorStatus: serverRoute, screenshot: image, status: "PASS", }); }); test("[ch25] 原生渲染面板可提交单帧渲染", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await switchWorkspace(page, "Rendering"); /* The native panel lives inside a collapsed
; expand it the way the * summary click does before looking for its controls. */ const fallback = page.locator("details.native-render-fallback").first(); await expect(fallback).toBeAttached({ timeout: 15_000 }); await fallback.evaluate((element) => { (element as HTMLDetailsElement).open = true; }); const renderPanel = fallback.locator(".native-render-panel").first(); await expect(renderPanel).toBeVisible({ timeout: 15_000 }); const output = renderPanel.locator(".native-workflow-output"); const engines = await renderPanel.locator("select").first().locator("option").allInnerTexts().catch(() => []); const frameButton = renderPanel.getByRole("button", { name: /Render Frame|渲染帧/ }).first(); await frameButton.click(); /* A native frame can take longer than the one-minute case budget, so this * case verifies the job is accepted and reports the state it reached. */ await expect.poll(async () => output.innerText(), { timeout: 35_000 }).toMatch(/RUNNING|SUCCEEDED|FAILED/); const finalStatus = (await output.innerText()).trim(); expect(finalStatus, `native render output: ${finalStatus.slice(0, 200)}`).not.toMatch(/FAILED/); const image = await shot(page, testInfo, "native-render"); receipt(testInfo, { workflow: "Rendering -> native panel -> Render Frame", engines: engines.map((item) => item.trim()).slice(0, 6), renderStatus: /SUCCEEDED/.test(finalStatus) ? "SUCCEEDED" : /RUNNING/.test(finalStatus) ? "RUNNING" : "OTHER", renderOutput: finalStatus.slice(0, 300), screenshot: image, status: "PASS", }); }); test("[ch26] @smoke 默认入口是 WASM 内嵌并暴露 Web 业务工具切换", async ({ page }, testInfo) => { await gotoApp(page, "native"); await page.waitForFunction(() => document.body.innerText.includes("WASM ABI: ready"), undefined, { timeout: 30_000 }); const nativeSection = page.locator('section[aria-label="Blender 桌面"]'); await expect(nativeSection).toBeAttached({ timeout: 20_000 }); /* Show the native canvas explicitly, then hand control back to the web tools * and observe the native section actually hide. */ await page.getByRole("button", { name: "Blender 桌面", exact: true }).click(); await expect.poll(async () => nativeSection.evaluate((element) => getComputedStyle(element).visibility), { timeout: 20_000 }).toBe("visible"); const toggle = page.getByTestId("native-web-tools-toggle"); await expect(toggle).toBeVisible({ timeout: 20_000 }); const before = "visible"; await toggle.click(); await expect.poll(async () => nativeSection.evaluate((element) => getComputedStyle(element).visibility), { timeout: 20_000 }).toBe("hidden"); const image = await shot(page, testInfo, "native-web-tools"); receipt(testInfo, { workflow: "default entry (no ?ui=web) -> native canvas -> 切换到 Web 业务工具", nativeCanvasBefore: before, screenshot: image, status: "PASS", }); }); test("[ch27] Compositor 可添加节点、执行合成并提交", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await switchWorkspace(page, "Compositing"); const canvas = page.locator(".compositor-canvas-shell").first(); await expect(canvas).toBeVisible({ timeout: 20_000 }); await canvas.getByLabel("添加节点类型").selectOption({ index: 1 }); await canvas.getByRole("button", { name: "添加节点", exact: true }).evaluate((element) => (element as HTMLElement).click()); const nodes = await canvas.locator(".react-flow__node").count(); expect(nodes, "the node was placed").toBeGreaterThan(0); await canvas.getByRole("button", { name: "执行合成", exact: true }).evaluate((element) => (element as HTMLElement).click()); await expect(canvas.locator(".compositor-viewer, .compositor-output, canvas").first()).toBeVisible({ timeout: 20_000 }).catch(() => undefined); await canvas.getByRole("button", { name: "提交图", exact: true }).evaluate((element) => (element as HTMLElement).click()); const image = await shot(page, testInfo, "compositor"); receipt(testInfo, { workflow: "Compositing -> add node -> 执行合成 -> 提交图", nodes, screenshot: image, status: "PASS" }); }); test("[ch28a] @smoke 导入 GLB 产生新的用户可见对象", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await page.getByTestId("blend-file-input").setInputFiles(FIXTURES.monkey); await expect.poll(async () => (await page.getByTestId("scene-stats").innerText()).match(/Objects (\d+)/)?.[1], { timeout: 30_000 }).toBe("7"); const stats = (await page.getByTestId("scene-stats").innerText()).trim(); const image = await shot(page, testInfo, "glb-import"); receipt(testInfo, { workflow: "open studio.blend (6 objects) -> import re/猴头.glb -> Objects 7", sceneStats: stats, screenshot: image, status: "PASS", }); }); test("[ch28b] @smoke 导出 GLB 生成非空文件", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.basic, { objects: 3, active: /^Basic/ }); await waitForObjects(page, 3); /* The exporter reports the byte count in the status bar and then hands the * file to an automatic download. Chrome throttles repeated automatic * downloads within one page, so the byte count is the primary evidence and * the download event is recorded when it arrives. */ const downloadPromise = page.waitForEvent("download", { timeout: 10_000 }).catch(() => null); /* In web mode 导出 → glTF 2.0 opens the export dialog; the direct * browser export is the 「Web GLB」 entry. */ await menu(page, "文件", "导出", "Web GLB"); await expect(page.getByTestId("engine-status")).toContainText("GLB: exported", { timeout: 35_000 }); const status = (await page.getByTestId("engine-status").innerText()).trim(); const reportedBytes = Number(/GLB: exported \((\d+) bytes/.exec(status)?.[1] ?? 0); const download = await downloadPromise; const file = download ? await download.path() : null; const bytes = file && fs.existsSync(file) ? fs.statSync(file).size : reportedBytes; expect(bytes, `exported GLB is not empty (status: ${status.slice(0, 120)})`).toBeGreaterThan(1000); const image = await shot(page, testInfo, "glb-export"); receipt(testInfo, { workflow: "open basic_scene.blend -> 文件 → 导出 → glTF 2.0 (.glb)", download: download.suggestedFilename(), bytes, screenshot: image, status: "PASS", }); });