/** * 调试课程列表 API */ import { test, expect } from '@playwright/test'; import { loginAsAdmin } from './helpers'; test.describe('API 调试测试', () => { test('调试课程列表 API', async ({ page }) => { test.setTimeout(60000); // 步骤 1: 登录 console.log('步骤 1: 开始登录...'); await loginAsAdmin(page); await page.waitForTimeout(2000); // 验证登录成功 const currentUrl = page.url(); console.log('登录后的 URL:', currentUrl); // 步骤 2: 强制导航到课程列表页面 console.log('导航到课程列表页面...'); await page.goto('/admin/courses', { timeout: 30000, waitUntil: 'networkidle' }); await page.waitForTimeout(5000); // 验证 URL const courseListUrl = page.url(); console.log('课程列表页面 URL:', courseListUrl); // 步骤 3: 检查表格状态 const table = page.locator('.ant-table').first(); const isTableAttached = await table.isVisible().catch(() => false); console.log('表格是否已附加到 DOM:', isTableAttached); // 检查是否有课程数据 const rows = table.locator('tbody tr'); const rowCount = await rows.count(); console.log('表格行数:', rowCount); if (rowCount > 0) { // 输出第一行的内容 const firstRowText = await rows.first().textContent(); console.log('第一行内容:', firstRowText); } else { // 检查是否是空表 const emptyText = await table.locator('.ant-empty').textContent(); console.log('空表提示:', emptyText); } // 步骤 4: 截图 await page.screenshot({ path: 'test-results/debug-course-list.png' }); console.log('调试完成,截图已保存'); }); });