import {test,expect} from '@playwright/test' import {readFileSync,mkdirSync} from 'node:fs' const env=Object.fromEntries(readFileSync('../.local/live/.env','utf8').trim().split(/\r?\n/).map(line=>{ const i=line.indexOf('='); return [line.slice(0,i),line.slice(i+1)] })) function required(key: string) { const value=env[key]; if (!value) throw new Error(`Missing live configuration: ${key}`); return value } test('现场真实资源、设备在线、日志采集与下载',async({page,request})=>{ const health=await request.get('/healthz'); expect((await health.json()).mode).toBe('production') await page.goto('/login') await expect(page.getByText(/演示账号/)).toHaveCount(0) await page.getByRole('textbox',{name:'用户名',exact:true}).fill(required('VDI_ADMIN_USERNAME')) await page.getByRole('textbox',{name:'密码',exact:true}).fill(required('VDI_ADMIN_PASSWORD')) await page.getByRole('button',{name:'登录',exact:true}).click() await expect(page.getByRole('heading',{name:'运行总览'})).toBeVisible() await expect(page.getByText('starhe',{exact:true})).toBeVisible() mkdirSync('../.local/live/screenshots',{recursive:true}) await page.screenshot({path:'../.local/live/screenshots/overview.png',fullPage:true,animations:'disabled'}) await page.getByRole('navigation').getByRole('link',{name:'桌面管理'}).click() await expect(page.getByRole('heading',{name:'桌面管理',exact:true})).toBeVisible() await page.getByRole('button',{name:'列表视图'}).click() for(const name of ['Windows 10','Ubuntu','麒麟']) await expect(page.getByRole('row').filter({hasText:name})).toBeVisible() await page.screenshot({path:'../.local/live/screenshots/desktops.png',fullPage:true,animations:'disabled'}) await page.getByRole('navigation').getByRole('link',{name:'终端管理'}).click() const row=page.getByRole('row').filter({hasText:'ee621cae7199a2e9'}) await expect(row.getByText('在线',{exact:true})).toBeVisible() await row.getByRole('button',{name:'详情',exact:true}).click() await expect(page.getByText('qt-platform/0.2.0',{exact:true})).toBeVisible() await page.getByRole('button',{name:'收集日志',exact:true}).click() await page.getByRole('button',{name:'确认提交',exact:true}).click() await page.getByRole('dialog',{name:'终端详情'}).locator('button.el-drawer__close-btn').click() await page.getByRole('navigation').getByRole('link',{name:'任务与审计'}).click() const task=page.getByRole('row').filter({hasText:'收集日志'}).first() await expect(task.getByText('成功',{exact:true})).toBeVisible() await task.getByRole('button').click() const download=page.waitForEvent('download') await page.getByRole('button',{name:'下载诊断日志'}).click() const artifact=await download const path='../.local/live/device-diagnostics.json'; await artifact.saveAs(path) const diagnostic=JSON.parse(readFileSync(path,'utf8')) expect(diagnostic.agentVersion).toBe('qt-platform/0.2.0'); expect(diagnostic.bootId).toBeTruthy(); expect(diagnostic.uptimeSeconds).toBeGreaterThan(0) await page.screenshot({path:'../.local/live/screenshots/diagnostics.png',fullPage:true,animations:'disabled'}) })