Files
novalon-manage-system/novalon-manage-web/e2e/pages/RoleManagementPage.ts
T
张翔 e2ad1331cc feat: 添加测试框架和覆盖率报告功能
feat(测试): 新增Playwright和Vitest测试配置
feat(测试): 添加测试覆盖率报告生成功能
feat(测试): 实现前后端测试脚本集成

fix(测试): 修复测试密码不匹配问题
fix(测试): 修正URL等待策略
fix(测试): 调整错误消息选择器

refactor(测试): 重构测试目录结构
refactor(测试): 优化测试用例组织方式

docs: 更新测试报告文档
docs: 添加测试覆盖率报告模板

ci: 添加Docker测试环境配置
ci: 实现测试自动化脚本

chore: 更新依赖版本
chore: 添加测试相关配置文件
2026-03-25 09:03:37 +08:00

102 lines
3.9 KiB
TypeScript

import { Page, Locator } from '@playwright/test';
export class RoleManagementPage {
readonly page: Page;
readonly table: Locator;
readonly createRoleButton: Locator;
readonly successMessage: Locator;
readonly roleNameInput: Locator;
readonly roleKeyInput: Locator;
readonly roleSortInput: Locator;
readonly statusSelect: Locator;
readonly remarkInput: Locator;
readonly permissionDialog: Locator;
readonly savePermissionButton: Locator;
constructor(page: Page) {
this.page = page;
this.table = page.locator('.el-table').first();
this.createRoleButton = page.getByRole('button', { name: '新增角色' }).or(page.locator('button:has-text("新增角色")'));
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
this.roleNameInput = page.locator('input[placeholder*="角色名称"]').or(page.locator('input[name*="roleName"]'));
this.roleKeyInput = page.locator('input[placeholder*="角色权限字符串"]').or(page.locator('input[name*="roleKey"]'));
this.roleSortInput = page.locator('input[placeholder*="显示顺序"]').or(page.locator('input[name*="roleSort"]'));
this.statusSelect = page.locator('select[name*="status"]').or(page.locator('.el-select'));
this.remarkInput = page.locator('textarea[placeholder*="备注"]').or(page.locator('textarea[name*="remark"]'));
this.permissionDialog = page.locator('.permission-dialog').or(page.locator('.el-dialog'));
this.savePermissionButton = page.getByRole('button', { name: '保存' }).or(page.locator('.permission-dialog .save-button'));
}
async goto() {
await this.page.goto('/roles');
await this.page.waitForLoadState('networkidle');
}
async clickCreateRole() {
await this.createRoleButton.click();
await this.page.waitForTimeout(500);
}
async fillRoleForm(roleData: {
roleName: string;
roleKey: string;
roleSort?: string;
status?: string;
remark?: string;
}) {
await this.page.locator('.el-dialog').locator('input').first().fill(roleData.roleName);
await this.page.locator('.el-dialog').locator('input').nth(1).fill(roleData.roleKey);
if (roleData.remark) {
await this.page.locator('.el-dialog').locator('textarea').fill(roleData.remark);
}
}
async submitForm() {
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('button:has-text("确定")')).click();
}
async editRole(rowNumber: number) {
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .edit-button`)).click();
}
async deleteRole(rowNumber: number) {
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '删除' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
}
async confirmDelete() {
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
}
async openPermissionDialog(rowNumber: number) {
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '权限' }).or(this.page.locator(`tbody tr:nth-child(${rowNumber}) .permission-button`)).click();
}
async selectPermission(permissionValue: string) {
await this.page.click(`input[type="checkbox"][value="${permissionValue}"]`);
}
async savePermissions() {
await this.savePermissionButton.click();
}
async containsText(text: string): Promise<boolean> {
return await this.table.getByText(text).count() > 0;
}
async isSuccessMessageVisible(): Promise<boolean> {
try {
return await this.successMessage.isVisible({ timeout: 3000 });
} catch {
return false;
}
}
async reload() {
await this.page.reload();
}
async getRoleName(rowNumber: number): Promise<string | null> {
return await this.table.locator(`tbody tr:nth-child(${rowNumber}) td:first-child`).textContent();
}
}