import { chromium } from '@playwright/test'; async function login() { const browser = await chromium.launch({ headless: false }); const context = await browser.newContext(); const page = await context.newPage(); try { console.log('🚀 开始登录...'); await page.goto('http://localhost:3000/admin/login', { timeout: 120000, waitUntil: 'domcontentloaded' }); console.log('📝 填写登录信息...'); await page.locator('#email').fill('admin@novalon.cn'); await page.locator('#password').fill('admin123456'); console.log('🖱️ 点击登录按钮...'); await page.locator('button[type="submit"]').click(); console.log('⏳ 等待登录成功...'); await page.waitForURL(/\/admin(?!\/login)/, { timeout: 60000 }); console.log('✅ 登录成功!'); console.log('📍 当前URL:', page.url()); console.log('💾 保存认证状态...'); await context.storageState({ path: '../.auth/admin.json' }); console.log('✅ 认证状态已保存到 .auth/admin.json'); } catch (error) { console.error('❌ 登录失败:', error); await page.screenshot({ path: 'login-error.png' }); } finally { await browser.close(); } } login();