import { chromium } from 'playwright'
const errors = []
const browser = await chromium.launch()
const ctx = await browser.newContext()
const page = await ctx.newPage()
page.on('pageerror', e => errors.push('PAGEERROR: ' + e.message))
page.on('console', m => { if (m.type() === 'error') errors.push('CONSOLE: ' + m.text()) })
await page.goto('http://localhost:8080/', { waitUntil: 'networkidle', timeout: 15000 })
await page.waitForTimeout(1000)
const title = await page.title()
const url = page.url()
const loginVisible = await page.locator('.login-box').count()
console.log('TITLE:', title)
console.log('URL:', url)
console.log('LOGIN_BOX_COUNT:', loginVisible)
console.log('ERRORS:', errors.length)
errors.forEach(e => console.log('  -', e))
// Try login
if (loginVisible > 0) {
  await page.fill('input[placeholder="请输入账号"]', 'admin')
  await page.fill('input[placeholder="请输入密码"]', '123456')
  await page.click('button.login-btn')
  await page.waitForTimeout(2000)
  console.log('AFTER_LOGIN_URL:', page.url())
  const sidebar = await page.locator('.sidebar').count()
  console.log('SIDEBAR_COUNT:', sidebar)
  const contentText = await page.locator('.content').innerText().catch(() => '')
  console.log('CONTENT_PREVIEW:', contentText.slice(0, 200))
}
console.log('FINAL_ERRORS:', errors.length)
errors.forEach(e => console.log('  -', e))
await browser.close()
