kindergarten_java/lesingle-edu-reading-platform-frontend/tests/e2e/teacher/03-classes.spec.ts

113 lines
3.5 KiB
TypeScript
Raw Normal View History

2026-03-17 10:38:51 +08:00
/**
* E2E -
*/
import { test, expect } from '@playwright/test';
import { loginAsTeacher, clickSubMenu, waitForTable } from './helpers';
test.describe('教师端班级管理功能', () => {
test.beforeEach(async ({ page }) => {
await loginAsTeacher(page);
});
test('验证班级列表页面加载', async ({ page }) => {
// 导航到班级管理页面
await clickSubMenu(page, '', '我的班级');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(2000);
// 验证页面标题
const hasTitle = await page.getByText(/班级 | 我的班级/).count() > 0;
test.info().annotations.push({
type: hasTitle ? 'success' : 'warning',
description: `班级标题:${hasTitle ? '存在' : '不存在'}`,
});
});
test('验证班级数据加载', async ({ page }) => {
// 导航到班级管理页面
await clickSubMenu(page, '', '我的班级');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(3000);
// 检查是否有班级数据
const hasClassList = await page.locator('[class*="class"], [class*="card"], table').count() > 0;
const hasEmpty = await page.getByText(/暂无数据 | 暂无班级/).count() > 0;
test.info().annotations.push({
type: 'info',
description: `班级数据:${hasClassList ? '存在' : hasEmpty ? '空状态' : '未知'}`,
});
});
test('验证班级学生列表', async ({ page }) => {
// 导航到班级管理页面
await clickSubMenu(page, '', '我的班级');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(2000);
// 查找第一个班级并点击进入
const firstClass = page.locator('[class*="class-card"], [class*="class-item"], table tbody tr').first();
const hasClass = await firstClass.count() > 0;
if (hasClass) {
// 尝试点击进入班级详情
await firstClass.click();
await page.waitForTimeout(2000);
// 验证是否进入班级详情页
const hasStudentList = await page.locator('[class*="student"], table').count() > 0;
test.info().annotations.push({
type: 'info',
description: `学生列表:${hasStudentList ? '存在' : '不存在'}`,
});
} else {
test.info().annotations.push({
type: 'warning',
description: '没有找到班级数据',
});
}
});
test('验证班级教师列表', async ({ page }) => {
// 导航到班级管理页面
await clickSubMenu(page, '', '我的班级');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(2000);
// 查找第一个班级并查看教师
const firstClass = page.locator('[class*="class-card"], [class*="class-item"], table tbody tr').first();
const hasClass = await firstClass.count() > 0;
if (hasClass) {
// 查找查看教师按钮
const viewTeachersBtn = page.getByRole('button', { name: /教师 | 老师/ }).first();
const hasBtn = await viewTeachersBtn.count() > 0;
test.info().annotations.push({
type: 'info',
description: `查看教师按钮:${hasBtn ? '存在' : '不存在'}`,
});
}
});
test('截图保存班级列表状态', async ({ page }) => {
// 导航到班级管理页面(教师端菜单为"我的班级"
await clickSubMenu(page, '', '我的班级');
2026-03-17 10:38:51 +08:00
// 等待页面完全加载
await page.waitForTimeout(3000);
// 截图
await page.screenshot({ path: 'test-results/teacher-classes.png' });
test.info().annotations.push({
type: 'success',
description: '班级列表截图已保存',
});
});
});