- 添加 target/ 到 .gitignore - 从 git 暂存区移除已追踪的 target 目录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
230 lines
8.0 KiB
TypeScript
230 lines
8.0 KiB
TypeScript
/**
|
|
* 学校端 E2E 测试 - 班级管理功能
|
|
*/
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
import { loginAsSchool, clickSubMenu } from './helpers';
|
|
import { SCHOOL_CONFIG } from './fixtures';
|
|
|
|
test.describe('学校端班级管理功能', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await loginAsSchool(page);
|
|
});
|
|
|
|
test('测试 1: 访问班级管理页面', async ({ page }) => {
|
|
// 1. 点击人员管理 → 班级管理
|
|
await clickSubMenu(page, '人员管理', '班级管理');
|
|
await page.waitForURL('**/school/classes*', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 2. 验证页面标题
|
|
await expect(page.locator('text=班级管理').or(page.locator('text=我的班级')).first()).toBeVisible({ timeout: 5000 });
|
|
|
|
// 3. 验证表格加载
|
|
const tableExists = await page.locator('table, .ant-table').count() > 0;
|
|
test.info().annotations.push({
|
|
type: 'info',
|
|
description: `班级表格:${tableExists ? '存在' : '不存在'}`,
|
|
});
|
|
|
|
// 截图
|
|
await page.screenshot({ path: 'test-results/school-classes-list.png' });
|
|
});
|
|
|
|
test('测试 2: 创建班级', async ({ page }) => {
|
|
test.slow();
|
|
|
|
// 1. 进入班级管理页面
|
|
await clickSubMenu(page, '人员管理', '班级管理');
|
|
await page.waitForURL('**/school/classes*', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 2. 点击新建按钮
|
|
const createBtn = page.locator('button:has-text("新建")').or(page.locator('button:has-text("创建")')).or(page.locator('button:has-text("新增")'));
|
|
if (await createBtn.count() > 0) {
|
|
await createBtn.first().click();
|
|
await page.waitForTimeout(500);
|
|
|
|
// 3. 验证弹窗显示
|
|
await expect(page.locator('.ant-modal')).toBeVisible({ timeout: 5000 });
|
|
|
|
// 4. 填写班级信息
|
|
const className = `测试班级_${Date.now()}`;
|
|
const nameInput = page.getByPlaceholder('请输入班级名称').or(page.locator('input[formitemlabel*="班级名称"]'));
|
|
if (await nameInput.count() > 0) {
|
|
await nameInput.first().fill(className);
|
|
}
|
|
|
|
// 选择年级 - 使用更宽松的选择器
|
|
const gradeSelect = page.locator('.ant-select').first();
|
|
if (await gradeSelect.count() > 0) {
|
|
await gradeSelect.click();
|
|
await page.waitForTimeout(300);
|
|
const gradeOption = page.locator('.ant-select-item-option').filter({ hasText: /小|中|大|托/ }).first();
|
|
if (await gradeOption.count() > 0) {
|
|
await gradeOption.click();
|
|
await page.waitForTimeout(300);
|
|
}
|
|
}
|
|
|
|
// 5. 点击确定按钮
|
|
const okBtn = page.locator('button:has-text("确定")').or(page.locator('button:has-text("确认")')).or(page.locator('button:has-text("保存")'));
|
|
if (await okBtn.count() > 0) {
|
|
await okBtn.first().click();
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 6. 验证创建成功
|
|
const successMsg = await page.locator('.ant-message-success').count() > 0;
|
|
test.info().annotations.push({
|
|
type: successMsg ? 'success' : 'error',
|
|
description: `创建班级:${successMsg ? '成功' : '失败'}`,
|
|
});
|
|
}
|
|
} else {
|
|
test.info().annotations.push({
|
|
type: 'warning',
|
|
description: '未找到新建班级按钮',
|
|
});
|
|
}
|
|
});
|
|
|
|
test('测试 3: 查看班级详情', async ({ page }) => {
|
|
// 1. 进入班级管理页面
|
|
await clickSubMenu(page, '人员管理', '班级管理');
|
|
await page.waitForURL('**/school/classes*', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 2. 查找查看按钮
|
|
const viewBtn = page.locator('button:has-text("查看")').or(page.locator('a:has-text("查看")')).first();
|
|
if (await viewBtn.count() > 0) {
|
|
await viewBtn.click();
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 3. 验证进入详情页面或弹窗
|
|
const modalExists = await page.locator('.ant-modal').count() > 0;
|
|
const pageExists = await page.locator('text=班级详情').count() > 0;
|
|
|
|
test.info().annotations.push({
|
|
type: 'info',
|
|
description: `班级详情:${modalExists ? '弹窗显示' : pageExists ? '页面显示' : '未找到'}`,
|
|
});
|
|
} else {
|
|
test.info().annotations.push({
|
|
type: 'warning',
|
|
description: '未找到查看按钮',
|
|
});
|
|
}
|
|
});
|
|
|
|
test('测试 4: 编辑班级', async ({ page }) => {
|
|
test.slow();
|
|
|
|
// 1. 进入班级管理页面
|
|
await clickSubMenu(page, '人员管理', '班级管理');
|
|
await page.waitForURL('**/school/classes*', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 2. 查找编辑按钮
|
|
const editBtn = page.locator('button:has-text("编辑")').first();
|
|
if (await editBtn.count() > 0) {
|
|
await editBtn.click();
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 3. 验证弹窗显示
|
|
await expect(page.locator('.ant-modal')).toBeVisible({ timeout: 5000 });
|
|
|
|
// 4. 修改班级名称
|
|
const nameInput = page.locator('input[placeholder*="班级名称"]').first();
|
|
if (await nameInput.count() > 0) {
|
|
const originalValue = await nameInput.inputValue();
|
|
await nameInput.fill(`${originalValue}_已编辑`);
|
|
}
|
|
|
|
// 5. 保存修改
|
|
const saveBtn = page.locator('button:has-text("确定")').or(page.locator('button:has-text("保存")'));
|
|
if (await saveBtn.count() > 0) {
|
|
await saveBtn.first().click();
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 6. 验证保存成功
|
|
const successMsg = await page.locator('.ant-message-success').count() > 0;
|
|
test.info().annotations.push({
|
|
type: successMsg ? 'success' : 'info',
|
|
description: `编辑班级:${successMsg ? '成功' : '完成'}`,
|
|
});
|
|
}
|
|
} else {
|
|
test.info().annotations.push({
|
|
type: 'warning',
|
|
description: '未找到编辑按钮',
|
|
});
|
|
}
|
|
});
|
|
|
|
test('测试 5: 班级筛选功能', async ({ page }) => {
|
|
// 1. 进入班级管理页面
|
|
await clickSubMenu(page, '人员管理', '班级管理');
|
|
await page.waitForURL('**/school/classes*', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 2. 查找筛选器
|
|
const searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[placeholder*="班级名称"]'));
|
|
if (await searchInput.count() > 0) {
|
|
await searchInput.first().fill('测试');
|
|
await page.waitForTimeout(1000);
|
|
|
|
test.info().annotations.push({
|
|
type: 'success',
|
|
description: '筛选功能:可用',
|
|
});
|
|
} else {
|
|
test.info().annotations.push({
|
|
type: 'warning',
|
|
description: '未找到筛选器',
|
|
});
|
|
}
|
|
|
|
// 截图
|
|
await page.screenshot({ path: 'test-results/school-classes-filter.png' });
|
|
});
|
|
|
|
test('测试 6: 删除班级', async ({ page }) => {
|
|
test.slow();
|
|
|
|
// 1. 进入班级管理页面
|
|
await clickSubMenu(page, '人员管理', '班级管理');
|
|
await page.waitForURL('**/school/classes*', { timeout: 10000 });
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 2. 记录删除前的班级数量
|
|
const rows = page.locator('.ant-table-tbody tr');
|
|
const beforeCount = await rows.count();
|
|
|
|
// 3. 查找删除按钮
|
|
const deleteBtn = page.locator('button:has-text("删除")').first();
|
|
if (await deleteBtn.count() > 0) {
|
|
await deleteBtn.click();
|
|
await page.waitForTimeout(500);
|
|
|
|
// 4. 确认删除
|
|
const confirmBtn = page.locator('button:has-text("确定")').or(page.locator('button:has-text("确认")'));
|
|
if (await confirmBtn.count() > 0) {
|
|
await confirmBtn.first().click();
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 5. 验证删除成功
|
|
const afterCount = await rows.count();
|
|
test.info().annotations.push({
|
|
type: 'info',
|
|
description: `删除前:${beforeCount}, 删除后:${afterCount}`,
|
|
});
|
|
}
|
|
} else {
|
|
test.info().annotations.push({
|
|
type: 'warning',
|
|
description: '未找到删除按钮',
|
|
});
|
|
}
|
|
});
|
|
});
|