42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
const { chromium } = require('playwright');
|
|
|
|
(async () => {
|
|
console.log('启动浏览器...');
|
|
const browser = await chromium.launch({ headless: true });
|
|
const page = await browser.newPage();
|
|
|
|
console.log('打开页面...');
|
|
await page.goto('http://localhost:5173', { timeout: 10000 });
|
|
|
|
console.log('等待页面加载...');
|
|
await page.waitForLoadState('domcontentloaded');
|
|
await page.waitForTimeout(3000);
|
|
|
|
// 检查是否有登录表单
|
|
const usernameInput = await page.$('input[placeholder="请输入用户名"]');
|
|
console.log('找到用户名输入框:', !!usernameInput);
|
|
|
|
if (usernameInput) {
|
|
console.log('填写账号...');
|
|
await usernameInput.fill('admin');
|
|
|
|
const passwordInput = await page.$('input[placeholder="请输入密码"]');
|
|
await passwordInput.fill('admin');
|
|
|
|
console.log('点击登录...');
|
|
await page.click('button[type="submit"]');
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log('截图...');
|
|
await page.screenshot({ path: '/Users/notyclaw/Desktop/admin_home.png', fullPage: true });
|
|
console.log('首页截好了');
|
|
}
|
|
|
|
await browser.close();
|
|
console.log('完成');
|
|
})().catch(e => {
|
|
console.error('错误:', e.message);
|
|
process.exit(1);
|
|
});
|