134 lines
4.7 KiB
TypeScript
134 lines
4.7 KiB
TypeScript
|
|
/**
|
||
|
|
* 调试课程创建 API
|
||
|
|
*/
|
||
|
|
import { test, expect } from '@playwright/test';
|
||
|
|
import { loginAsAdmin } from './helpers';
|
||
|
|
|
||
|
|
test.describe('API 调试测试 - 课程创建', () => {
|
||
|
|
test('调试课程创建 API', async ({ page }) => {
|
||
|
|
test.setTimeout(180000);
|
||
|
|
|
||
|
|
const courseName = '调试测试课程包-' + Date.now();
|
||
|
|
console.log('测试课程名称:', courseName);
|
||
|
|
|
||
|
|
// 步骤 1: 登录
|
||
|
|
console.log('步骤 1: 开始登录...');
|
||
|
|
await loginAsAdmin(page);
|
||
|
|
await page.waitForTimeout(2000);
|
||
|
|
|
||
|
|
// 步骤 2: 进入课程列表页面
|
||
|
|
console.log('步骤 2: 导航到课程列表页面...');
|
||
|
|
await page.goto('/admin/courses', { timeout: 30000, waitUntil: 'networkidle' });
|
||
|
|
await page.waitForTimeout(5000);
|
||
|
|
|
||
|
|
// 截图确认页面状态
|
||
|
|
await page.screenshot({ path: 'test-results/debug-after-login.png' });
|
||
|
|
console.log('已保存登录后截图');
|
||
|
|
|
||
|
|
// 记录创建前的课程数量
|
||
|
|
let table = page.locator('.ant-table').first();
|
||
|
|
|
||
|
|
// 等待表格加载
|
||
|
|
const isTableVisible = await table.isVisible({ timeout: 10000 }).catch(() => false);
|
||
|
|
console.log('表格是否可见:', isTableVisible);
|
||
|
|
|
||
|
|
let rows = table.locator('tbody tr');
|
||
|
|
const beforeCount = await rows.count();
|
||
|
|
console.log('创建前的课程数量:', beforeCount);
|
||
|
|
|
||
|
|
// 步骤 3: 点击新建课程包按钮
|
||
|
|
console.log('步骤 3: 点击新建课程包按钮...');
|
||
|
|
// 尝试多种选择器
|
||
|
|
let createButton = page.getByRole('button', { name: '新建课程包' });
|
||
|
|
|
||
|
|
// 如果找不到,尝试其他选择器
|
||
|
|
const isVisible = await createButton.isVisible().catch(() => false);
|
||
|
|
console.log('新建课程包按钮是否可见:', isVisible);
|
||
|
|
|
||
|
|
if (!isVisible) {
|
||
|
|
// 尝试使用文本查找
|
||
|
|
createButton = page.getByText('新建课程包').first();
|
||
|
|
console.log('使用文本选择器查找按钮...');
|
||
|
|
}
|
||
|
|
|
||
|
|
await createButton.click();
|
||
|
|
await page.waitForTimeout(2000);
|
||
|
|
|
||
|
|
// 验证进入创建页面
|
||
|
|
const isCreatePage = await page.getByText('创建课程包').isVisible().catch(() => false);
|
||
|
|
console.log('是否进入创建页面:', isCreatePage);
|
||
|
|
|
||
|
|
if (!isCreatePage) {
|
||
|
|
console.log('未进入创建页面,测试结束');
|
||
|
|
await page.screenshot({ path: 'test-results/debug-create-error.png' });
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 步骤 4: 填写基本信息(只填必填项)
|
||
|
|
console.log('步骤 4: 填写基本信息...');
|
||
|
|
await page.getByPlaceholder('请输入课程包名称').fill(courseName);
|
||
|
|
|
||
|
|
// 选择关联主题
|
||
|
|
await page.locator('.ant-select-selector').first().click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
await page.getByText('社会认知', { exact: true }).first().click();
|
||
|
|
await page.waitForTimeout(300);
|
||
|
|
|
||
|
|
// 选择适用年级
|
||
|
|
await page.getByRole('checkbox', { name: '小班' }).click();
|
||
|
|
await page.waitForTimeout(300);
|
||
|
|
|
||
|
|
// 填写核心内容
|
||
|
|
await page.getByPlaceholder('请输入课程包核心内容').fill('调试测试课程内容');
|
||
|
|
|
||
|
|
// 步骤 5: 直接点击创建按钮(跳过其他可选步骤)
|
||
|
|
console.log('步骤 5: 跳过可选步骤,直接提交...');
|
||
|
|
for (let i = 0; i < 6; i++) {
|
||
|
|
const nextButton = page.getByRole('button', { name: '下一步' });
|
||
|
|
if (await nextButton.isVisible().catch(() => false)) {
|
||
|
|
await nextButton.click();
|
||
|
|
await page.waitForTimeout(1000);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 步骤 6: 点击创建按钮
|
||
|
|
console.log('步骤 6: 点击创建按钮...');
|
||
|
|
const submitButton = page.getByRole('button', { name: '创建' });
|
||
|
|
await submitButton.click();
|
||
|
|
|
||
|
|
// 步骤 7: 等待创建结果
|
||
|
|
console.log('步骤 7: 等待创建结果...');
|
||
|
|
|
||
|
|
// 等待成功提示
|
||
|
|
const hasSuccessMessage = await page.waitForSelector('.ant-message-success', { timeout: 10000 }).catch(() => null);
|
||
|
|
console.log('是否有成功提示:', hasSuccessMessage !== null);
|
||
|
|
|
||
|
|
// 等待页面跳转
|
||
|
|
await page.waitForURL('**/admin/courses**', { timeout: 15000 });
|
||
|
|
await page.waitForTimeout(5000);
|
||
|
|
|
||
|
|
// 步骤 8: 验证课程列表
|
||
|
|
console.log('步骤 8: 验证课程列表...');
|
||
|
|
table = page.locator('.ant-table').first();
|
||
|
|
rows = table.locator('tbody tr');
|
||
|
|
const afterCount = await rows.count();
|
||
|
|
console.log('创建后的课程数量:', afterCount);
|
||
|
|
|
||
|
|
// 查找新课程
|
||
|
|
const newCourseRow = table.getByText(courseName);
|
||
|
|
const isCourseExists = await newCourseRow.isVisible().catch(() => false);
|
||
|
|
console.log('新课程是否在列表中:', isCourseExists);
|
||
|
|
|
||
|
|
// 截图
|
||
|
|
await page.screenshot({ path: 'test-results/debug-create-result.png' });
|
||
|
|
console.log('截图已保存');
|
||
|
|
|
||
|
|
// 输出结论
|
||
|
|
if (isCourseExists) {
|
||
|
|
console.log('✅ 课程创建成功!');
|
||
|
|
} else {
|
||
|
|
console.log('❌ 课程创建失败或列表未更新');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|