import { createRequire } from "node:module"; import path from "node:path"; const { chromium } = createRequire(import.meta.url)("/home/mes123456/workinf_Blender_Wasm/web/node_modules/playwright"); const browser = await chromium.launch({ headless: true, executablePath: "/usr/bin/google-chrome-stable", args: ["--no-sandbox","--use-gl=swiftshader","--enable-unsafe-swiftshader","--enable-unsafe-webgpu","--enable-dawn-features=allow_unsafe_apis","--use-webgpu-adapter=swiftshader"] }); const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } }); const page = await ctx.newPage(); await page.addInitScript(() => { const reg = []; window.__w = reg; window.Worker = new Proxy(window.Worker, { construct(t, a) { const w = Reflect.construct(t, a); reg.push({ url: String(a[0]), worker: w }); return w; } }); }); await page.goto("http://127.0.0.1:5412/?ui=web", { waitUntil: "domcontentloaded" }); await page.waitForFunction(() => document.body.innerText.includes("WASM ABI: ready"), undefined, { timeout: 120000 }); await page.getByTestId("blend-file-input").setInputFiles(path.resolve("/home/mes123456/workinf_Blender_Wasm/tests/files/web/hierarchy_simplify_combined.blend")); await page.waitForFunction(() => /SceneIR r\d+/.test(document.querySelector('[data-testid="engine-status"]')?.textContent ?? ""), undefined, { timeout: 120000 }); await page.waitForTimeout(3500); const snap = () => page.evaluate(() => new Promise((resolve, reject) => { const worker = window.__w.find(x => /web-engine\.worker/.test(x.url))?.worker; const requestId = 'p-' + Math.random(); const timer = setTimeout(() => reject(new Error('timeout')), 30000); const recv = ({ data }) => { if (data.requestId === requestId) { clearTimeout(timer); resolve(data); } }; worker.addEventListener('message', recv); worker.postMessage({ requestId, command: { type: 'snapshot' } }); })); const parents = async () => { const r = await snap(); const s = r.result?.snapshot; return { rev: s?.revision, p: Object.fromEntries((s?.nodes ?? []).map(n => [n.name, n.parentId ? s.nodes.find(x => x.id === n.parentId)?.name : null])) }; }; for (const name of ['Parts','Mount','RootRig']) { const btn = page.getByRole('button', { name: `展开 ${name}`, exact: true }).first(); if (await btn.count()) { await btn.click(); await page.waitForTimeout(2000); } } const drag = (src, dst, shift) => page.evaluate(({ s: srcName, d: dstName, shiftKey }) => { const find = (n) => [...document.querySelectorAll('[role="treeitem"]')].find(x => (x.getAttribute('aria-label')||'').trim() === n); const s = find(srcName), d = find(dstName); const dt = new DataTransfer(); s.dispatchEvent(new DragEvent('dragstart', { bubbles: true, cancelable: true, dataTransfer: dt })); d.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, dataTransfer: dt, shiftKey })); const handled = !d.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: dt, shiftKey })); return handled; }, { s: src, d: dst, shiftKey: shift }); console.log("BEFORE", JSON.stringify(await parents())); console.log("PLAIN-DROP", await drag('Mount', 'NewParent', false)); await page.waitForTimeout(6000); console.log("AFTER-PLAIN", JSON.stringify(await parents())); console.log("SHIFT-DROP", await drag('Mount', 'NewParent', true)); await page.waitForTimeout(8000); console.log("AFTER-SHIFT", JSON.stringify(await parents())); await browser.close();