// 前端截图验证脚本:登录 → 仪表盘 → 密钥页 const { chromium } = require('playwright') async function main() { const browser = await chromium.launch() const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }) const shots = process.argv[2] || '/tmp/shots' const fs = require('fs') fs.mkdirSync(shots, { recursive: true }) // 1. Landing await page.goto('http://localhost:5173/', { waitUntil: 'networkidle' }) await page.screenshot({ path: `${shots}/01-landing.png` }) // 2. 注册 await page.goto('http://localhost:5173/register', { waitUntil: 'networkidle' }) const uname = 'dave' + Date.now().toString().slice(-6) await page.fill('input[autocomplete="username"]', uname) await page.fill('input[autocomplete="email"]', uname + '@test.com') await page.fill('input[autocomplete="new-password"]', 'password123') await page.locator('input[autocomplete="new-password"]').nth(1).fill('password123') await page.screenshot({ path: `${shots}/02-register.png` }) await page.click('button[type="submit"]') await page.waitForURL('**/console/dashboard', { timeout: 10000 }) await page.waitForTimeout(1200) // 3. 跳过登录(注册后已自动登录)—— 直接看仪表盘 await page.goto('http://localhost:5173/console/dashboard', { waitUntil: 'networkidle' }) await page.waitForTimeout(1500) await page.screenshot({ path: `${shots}/03-dashboard.png` }) // 4. 密钥页 await page.goto('http://localhost:5173/console/keys', { waitUntil: 'networkidle' }) await page.screenshot({ path: `${shots}/04-keys.png` }) await page.click('text=新建密钥') await page.waitForTimeout(400) await page.fill('input[placeholder*="本地开发"]', 'playwright-test') await page.screenshot({ path: `${shots}/05-key-modal.png` }) await page.click('button:has-text("创建")') await page.waitForTimeout(600) await page.screenshot({ path: `${shots}/06-key-created.png` }) // 5. 用量页 await page.goto('http://localhost:5173/console/usage', { waitUntil: 'networkidle' }) await page.waitForTimeout(800) await page.screenshot({ path: `${shots}/07-usage.png` }) await browser.close() console.log('done') } main().catch((e) => { console.error(e); process.exit(1) })