import { chromium } from 'playwright'; const base = 'http://localhost:4200'; const b = await chromium.launch({ channel: 'msedge' }); const ctx = await b.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true, userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148 Safari/604.1' }); const p = await ctx.newPage(); const errs = []; p.on('pageerror', e => errs.push(e.message)); p.on('console', m => { if (m.type() === 'error') errs.push(m.text().slice(0, 140)); }); const r = {}; await p.goto(base + '/login'); await p.waitForTimeout(900); await p.locator('input').nth(0).fill('13800000000'); await p.getByRole('button', { name: /获取验证码/ }).first().click(); await p.waitForTimeout(400); await p.locator('input').nth(1).fill('123456'); await p.getByRole('button', { name: /^登\s*录$/ }).first().click(); await p.waitForTimeout(3500); r.landing = p.url().replace(base, ''); // 新建对话 await p.getByRole('button', { name: '新建对话' }).first().click(); await p.waitForTimeout(700); r.pick = await p.locator('.pick-row').count(); await p.locator('.pick-row').first().click(); await p.waitForTimeout(2500); r.afterNew = p.url().replace(base, '').slice(0, 60); // 发消息 const ta = p.locator('textarea').first(); await ta.fill('你好,做个测试'); await ta.press('Enter'); await p.waitForTimeout(2500); r.sent = (await p.evaluate(() => document.body.innerText)).includes('你好,做个测试'); await p.screenshot({ path: '.tmp-shots/chat.png' }); // 抽屉(会话列表页顶栏 ☰) await p.goto(base + '/mobile/chat-index'); await p.waitForTimeout(1800); await p.getByRole('button', { name: '打开会话抽屉' }).click(); await p.waitForTimeout(800); r.drawer = (await p.evaluate(() => document.body.innerText)).includes('新建对话') && (await p.evaluate(() => document.body.innerText)).includes('更多'); await p.locator('button:has-text("更多")').first().click(); await p.waitForTimeout(400); r.moreList = (await p.evaluate(() => document.body.innerText)).includes('成果'); await p.screenshot({ path: '.tmp-shots/drawer.png' }); await p.keyboard.press('Escape'); // 详情页 for (const [route, name] of [['projects/pr-0', 'project-detail'], ['tasks/t-0', 'task-detail']]) { await p.goto(`${base}/mobile/${route}`); await p.waitForTimeout(1500); await p.screenshot({ path: `.tmp-shots/${name}.png` }); } // 配色切换 await p.goto(base + '/mobile/mine'); await p.waitForTimeout(1200); await p.locator('.pal').nth(1).click(); await p.waitForTimeout(500); r.palette = await p.evaluate(() => document.documentElement.dataset.palette); await p.screenshot({ path: '.tmp-shots/mine-ice.png' }); console.log(JSON.stringify({ r, errs: [...new Set(errs)].slice(0, 6) }, null, 1)); await b.close();