const { chromium } = require('playwright'); let browser = null; let page = null; async function init() { browser = await chromium.launch({ headless: true, args: ['--disable-setuid-sandbox', '--no-sandbox'] }); page = await browser.newPage(); await page.setViewportSize({ width: 1920, height: 1080 }); // 登录 await page.goto('http://localhost:5173'); await page.waitForTimeout(3000); await page.fill('input[placeholder="请输入用户名"]', 'admin'); await page.fill('input[placeholder="请输入密码"]', 'admin'); await page.click('button[type="submit"]'); await page.waitForTimeout(3000); console.log('登录完成'); } async function screenshot(route, filename) { if (!page) await init(); await page.goto('http://localhost:5173/#/' + route); await page.waitForTimeout(3000); await page.screenshot({ path: '/Users/notyclaw/Desktop/' + filename, fullPage: true }); console.log(filename + ' 完成'); } module.exports = { init, screenshot };