import { chromium } from 'playwright';

(async () => {
  const browser = await chromium.launch({ headless: false });
  const page = await browser.newPage();
  
  // 监听控制台消息
  page.on('console', msg => {
    if (msg.type() === 'error') {
      console.log('Console Error:', msg.text());
    }
  });
  
  page.on('pageerror', error => {
    console.log('Page Error:', error.message);
  });
  
  try {
    console.log('访问登录页面...');
    await page.goto('http://localhost:5173/login');
    await page.waitForTimeout(2000);
    
    console.log('尝试登录...');
    await page.fill('input[type="text"]', 'teacher1');
    await page.fill('input[type="password"]', '123456');
    await page.click('button[type="submit"]');
    await page.waitForTimeout(3000);
    
    console.log('当前URL:', page.url());
    
    console.log('访问课程中心...');
    await page.click('text=课程中心');
    await page.waitForTimeout(2000);
    
    console.log('点击第一个课程...');
    const firstCourse = page.locator('.course-card, [class*="course"]').first();
    await firstCourse.click();
    await page.waitForTimeout(2000);
    
    console.log('点击开始备课...');
    await page.click('button:has-text("开始备课")');
    await page.waitForTimeout(3000);
    
    console.log('当前URL:', page.url());
    console.log('页面加载完成，检查控制台错误...');
    
    await page.waitForTimeout(5000);
  } catch (error) {
    console.error('发生错误:', error.message);
  }
  
  await browser.close();
})();
