import { test, expect } from '@playwright/test'; import { GroupCourseManagementPage } from '../pages/GroupCourseManagementPage'; test.describe.serial('团课管理完整CRUD旅程', () => { let coursePage: GroupCourseManagementPage; const timestamp = Date.now(); const courseName = `自动化测试团课_${timestamp}`; const updatedCourseName = `编辑团课_${timestamp}`; const location = `测试地点_${timestamp}`; test.beforeEach(async ({ page }) => { coursePage = new GroupCourseManagementPage(page); }); test('团课列表显示', async ({ page }) => { await test.step('导航到团课管理页面', async () => { await coursePage.goto(); }); await test.step('验证表格显示', async () => { await expect(coursePage.table).toBeVisible({ timeout: 10000 }); }); await test.step('验证数据加载', async () => { const rowCount = await coursePage.getTableRowCount(); console.log(`团课列表包含 ${rowCount} 条记录`); expect(rowCount).toBeGreaterThanOrEqual(0); }); }); test('创建新团课', async ({ page }) => { await test.step('导航到团课管理页面', async () => { await coursePage.goto(); }); await test.step('点击新增团课按钮', async () => { await coursePage.clickAdd(); }); await test.step('填写团课表单', async () => { // 获取当前时间后2小时作为开始时间 const startDate = new Date(Date.now() + 2 * 60 * 60 * 1000); const startTimeStr = `${startDate.getFullYear()}-${String(startDate.getMonth() + 1).padStart(2, '0')}-${String(startDate.getDate()).padStart(2, '0')} ${String(startDate.getHours()).padStart(2, '0')}:${String(startDate.getMinutes()).padStart(2, '0')}:00`; await coursePage.fillCourseForm({ courseName: courseName, startTime: startTimeStr, duration: 60, maxMembers: 30, location: location, description: `自动化测试创建的团课_${timestamp}`, }); console.log(`团课表单已填写: ${courseName}`); }); await test.step('提交表单', async () => { await coursePage.submitForm(); }); await test.step('验证创建成功', async () => { await coursePage.waitForDialogClose(); console.log(`团课 ${courseName} 创建完成`); }); }); test('编辑团课信息', async ({ page }) => { await test.step('导航到团课管理页面', async () => { await coursePage.goto(); }); await test.step('搜索刚创建的团课', async () => { await coursePage.search(courseName); }); await test.step('等待数据加载', async () => { await expect(coursePage.table).toBeVisible({ timeout: 10000 }); }); await test.step('点击编辑按钮', async () => { const rows = await coursePage.getTableRowCount(); if (rows > 0) { await coursePage.clickEditOnFirstRow(); console.log('编辑弹窗已打开'); } else { console.log('未找到刚创建的团课,跳过编辑测试'); test.skip(); } }); await test.step('修改团课信息', async () => { // 清空并填入新课程名 const nameInput = coursePage.page.locator('.el-dialog').getByPlaceholder('请输入课程名称'); await nameInput.clear(); await nameInput.fill(updatedCourseName); console.log(`团课名称已修改为: ${updatedCourseName}`); }); await test.step('提交表单', async () => { await coursePage.submitForm(); }); await test.step('验证更新成功', async () => { await coursePage.waitForDialogClose(); console.log('团课信息更新完成'); }); }); test('删除团课', async ({ page }) => { await test.step('导航到团课管理页面', async () => { await coursePage.goto(); }); await test.step('搜索编辑后的团课', async () => { await coursePage.search(updatedCourseName); }); await test.step('等待数据加载', async () => { await expect(coursePage.table).toBeVisible({ timeout: 10000 }); }); await test.step('点击删除按钮', async () => { const rows = await coursePage.getTableRowCount(); if (rows > 0) { await coursePage.clickDeleteOnFirstRow(); console.log('删除确认对话框已打开'); } else { // 尝试用原始名称搜索 await coursePage.search(courseName); await page.waitForTimeout(500); const retryRows = await coursePage.getTableRowCount(); if (retryRows > 0) { await coursePage.clickDeleteOnFirstRow(); console.log('删除确认对话框已打开(使用原始名称搜索)'); } else { console.log('未找到可删除的团课,跳过删除测试'); test.skip(); } } }); await test.step('确认删除', async () => { await coursePage.confirmDelete(); console.log('删除确认完成'); }); await test.step('验证删除成功', async () => { const messageBox = page.locator('.el-message-box'); await expect(messageBox).not.toBeVisible({ timeout: 5000 }); console.log('团课已删除'); }); }); });