57 lines
3.1 KiB
JavaScript
57 lines
3.1 KiB
JavaScript
import { chromium } from 'playwright'
|
|
import { mkdir, copyFile, writeFile } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
|
|
const base = process.env.DEMO_URL || 'http://127.0.0.1:5173'
|
|
const health = await (await fetch(`${base}/api/health`)).json()
|
|
if (!health.demo || health.apiConfigured) throw new Error('Media capture requires isolated offline demo mode.')
|
|
const root = path.resolve('artifacts/media')
|
|
await mkdir(root, { recursive: true })
|
|
await mkdir('docs/images', { recursive: true })
|
|
const browser = await chromium.launch({ args: ['--enable-webgl', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'] })
|
|
try {
|
|
const context = await browser.newContext({ viewport: { width: 1600, height: 900 }, recordVideo: { dir: root, size: { width: 1600, height: 900 } } })
|
|
const page = await context.newPage()
|
|
await page.addInitScript(() => localStorage.setItem('real2sim.locale', 'en'))
|
|
await page.goto(base)
|
|
await page.getByRole('button', { name: 'Load example', exact: true }).click()
|
|
await page.getByRole('heading', { name: 'Material & Simulation Export' }).waitFor()
|
|
await page.waitForTimeout(3000)
|
|
await page.screenshot({ path: 'docs/images/workbench.png' })
|
|
await page.getByRole('button', { name: 'Rotate model' }).click()
|
|
await page.waitForTimeout(8000)
|
|
await page.getByRole('button', { name: 'Rotate model' }).click()
|
|
const gravity = page.getByLabel('Gravity', { exact: true })
|
|
await gravity.focus()
|
|
await gravity.press('Home')
|
|
for (let i = 0; i < 37; i++) await gravity.press('ArrowRight')
|
|
await page.waitForTimeout(2000)
|
|
const downloadPromise = page.waitForEvent('download')
|
|
await page.getByRole('button', { name: 'Export Genesis Package', exact: true }).click()
|
|
await (await downloadPromise).saveAs(path.join(root, 'gravity-3.7-export.tar.gz'))
|
|
await page.screenshot({ path: path.join(root, 'settings.png') })
|
|
await page.waitForTimeout(3000)
|
|
const video = page.video()
|
|
await context.close()
|
|
await video.saveAs(path.join(root, 'workbench.webm'))
|
|
|
|
const mobile = await browser.newContext({ viewport: { width: 540, height: 960 }, recordVideo: { dir: root, size: { width: 540, height: 960 } } })
|
|
const phone = await mobile.newPage()
|
|
await phone.addInitScript(() => localStorage.setItem('real2sim.locale', 'zh'))
|
|
await phone.goto(base)
|
|
await phone.getByRole('button', { name: '加载样例', exact: true }).click()
|
|
await phone.waitForTimeout(3000)
|
|
await phone.getByRole('button', { name: 'Rotate model' }).click()
|
|
await phone.waitForTimeout(6000)
|
|
await phone.getByRole('button', { name: 'Rotate model' }).click()
|
|
await phone.getByLabel('重力', { exact: true }).scrollIntoViewIfNeeded()
|
|
await phone.waitForTimeout(5000)
|
|
const mobileVideo = phone.video()
|
|
await mobile.close()
|
|
await mobileVideo.saveAs(path.join(root, 'mobile.webm'))
|
|
await copyFile('docs/images/workbench.png', path.join(root, 'workbench.png'))
|
|
await writeFile(path.join(root, 'capture.json'), JSON.stringify({ capturedAt: new Date().toISOString(), source: 'isolated local offline example', model: 'examples/soft-puck/model.glb', noPaidGeneration: true }, null, 2))
|
|
} finally {
|
|
await browser.close()
|
|
}
|