feat: extend operation log service and repository with pagination support
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
|
||||
export class DashboardPage {
|
||||
readonly page: Page;
|
||||
readonly userInfo: Locator;
|
||||
readonly userManagementLink: Locator;
|
||||
readonly roleManagementLink: Locator;
|
||||
readonly menuManagementLink: Locator;
|
||||
readonly systemConfigLink: Locator;
|
||||
readonly noticeManagementLink: Locator;
|
||||
readonly fileManagementLink: Locator;
|
||||
readonly operationLogLink: Locator;
|
||||
readonly loginLogLink: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.userInfo = page.locator('.el-avatar');
|
||||
this.userManagementLink = page.getByRole('menuitem', { name: '用户管理' });
|
||||
this.roleManagementLink = page.getByRole('menuitem', { name: '角色管理' });
|
||||
this.menuManagementLink = page.getByRole('menuitem', { name: '菜单管理' });
|
||||
this.systemConfigLink = page.getByRole('menuitem', { name: '参数配置' });
|
||||
this.noticeManagementLink = page.getByRole('menuitem', { name: '通知公告' });
|
||||
this.fileManagementLink = page.getByRole('menuitem', { name: '文件列表' });
|
||||
this.operationLogLink = page.getByRole('menuitem', { name: '操作日志' });
|
||||
this.loginLogLink = page.getByRole('menuitem', { name: '登录日志' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/dashboard');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToUserManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.userManagementLink.click();
|
||||
await this.page.waitForURL('**/users');
|
||||
}
|
||||
|
||||
async navigateToRoleManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.roleManagementLink.click();
|
||||
await this.page.waitForURL('**/roles');
|
||||
}
|
||||
|
||||
async navigateToMenuManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.menuManagementLink.click();
|
||||
await this.page.waitForURL('**/menus');
|
||||
}
|
||||
|
||||
async navigateToSystemConfig() {
|
||||
const configMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统配置' });
|
||||
await configMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.systemConfigLink.click();
|
||||
await this.page.waitForURL('**/sysconfig');
|
||||
}
|
||||
|
||||
async navigateToNoticeManagement() {
|
||||
const notifyMenu = this.page.locator('.el-sub-menu').filter({ hasText: '通知中心' });
|
||||
await notifyMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.noticeManagementLink.click();
|
||||
await this.page.waitForURL('**/notice');
|
||||
}
|
||||
|
||||
async navigateToFileManagement() {
|
||||
const fileMenu = this.page.locator('.el-sub-menu').filter({ hasText: '文件管理' });
|
||||
await fileMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.fileManagementLink.click();
|
||||
await this.page.waitForURL('**/files');
|
||||
}
|
||||
|
||||
async navigateToOperationLog() {
|
||||
const auditMenu = this.page.locator('.el-sub-menu').filter({ hasText: '审计中心' });
|
||||
await auditMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.operationLogLink.click();
|
||||
await this.page.waitForURL('**/oplog');
|
||||
}
|
||||
|
||||
async navigateToLoginLog() {
|
||||
const auditMenu = this.page.locator('.el-sub-menu').filter({ hasText: '审计中心' });
|
||||
await auditMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.loginLogLink.click();
|
||||
await this.page.waitForURL('**/loginlog');
|
||||
}
|
||||
|
||||
async getUsername(): Promise<string | null> {
|
||||
return await this.userInfo.textContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
|
||||
export class LoginPage {
|
||||
readonly page: Page;
|
||||
readonly usernameInput: Locator;
|
||||
readonly passwordInput: Locator;
|
||||
readonly loginButton: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
readonly logoutButton: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.usernameInput = page.locator('input[placeholder*="用户名"]').or(page.locator('.el-input__inner[placeholder*="用户名"]'));
|
||||
this.passwordInput = page.locator('input[type="password"]').or(page.locator('.el-input__inner[type="password"]'));
|
||||
this.loginButton = page.locator('button[type="submit"]').or(page.locator('button:has-text("登录")'));
|
||||
this.errorMessage = page.locator('.el-message--error').or(page.locator('.error-message'));
|
||||
this.logoutButton = page.getByRole('button', { name: '退出登录' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/login');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async login(username: string, password: string) {
|
||||
await this.usernameInput.fill(username);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.loginButton.click();
|
||||
|
||||
try {
|
||||
await this.page.waitForURL('**/dashboard', { timeout: 10000 });
|
||||
} catch {
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
}
|
||||
|
||||
async getErrorMessage(): Promise<string | null> {
|
||||
try {
|
||||
await this.page.waitForSelector('.el-message', { timeout: 3000 });
|
||||
const messageElement = await this.page.locator('.el-message').first();
|
||||
const text = await messageElement.textContent();
|
||||
return text;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async logout() {
|
||||
const avatar = this.page.locator('.el-avatar');
|
||||
await avatar.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
|
||||
const logoutButton = this.page.locator('.el-dropdown-menu').getByText('退出登录');
|
||||
await logoutButton.click();
|
||||
await this.page.waitForURL('**/login', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async isLoggedIn(): Promise<boolean> {
|
||||
return this.page.url().includes('/dashboard');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
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').or(page.locator('table'));
|
||||
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.roleNameInput.fill(roleData.roleName);
|
||||
await this.roleKeyInput.fill(roleData.roleKey);
|
||||
if (roleData.roleSort) {
|
||||
await this.roleSortInput.fill(roleData.roleSort);
|
||||
}
|
||||
if (roleData.status) {
|
||||
await this.statusSelect.selectOption(roleData.status);
|
||||
}
|
||||
if (roleData.remark) {
|
||||
await this.remarkInput.fill(roleData.remark);
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(page.locator('button:has-text("确定")')).click();
|
||||
}
|
||||
|
||||
async editRole(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).or(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(page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(page.locator('.confirm-dialog .confirm-button')).click();
|
||||
}
|
||||
|
||||
async openPermissionDialog(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '权限' }).or(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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
|
||||
export class UserManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createUserButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly pagination: Locator;
|
||||
readonly nextPageButton: Locator;
|
||||
readonly prevPageButton: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').or(page.locator('table'));
|
||||
this.createUserButton = page.getByRole('button', { name: '创建用户' }).or(page.locator('button:has-text("创建用户")'));
|
||||
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
this.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
|
||||
this.nextPageButton = page.locator('.el-pagination .btn-next').or(page.locator('.pagination .next-page'));
|
||||
this.prevPageButton = page.locator('.el-pagination .btn-prev').or(page.locator('.pagination .prev-page'));
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/users');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clickCreateUser() {
|
||||
await this.createUserButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async fillUserForm(userData: {
|
||||
username: string;
|
||||
email: string;
|
||||
phone?: string;
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}) {
|
||||
await this.page.locator('input[placeholder*="用户名"]').or(page.locator('input[name*="username"]')).fill(userData.username);
|
||||
await this.page.locator('input[placeholder*="邮箱"]').or(page.locator('input[name*="email"]')).fill(userData.email);
|
||||
if (userData.phone) {
|
||||
await this.page.locator('input[placeholder*="手机号"]').or(page.locator('input[name*="phone"]')).fill(userData.phone);
|
||||
}
|
||||
await this.page.locator('input[placeholder*="密码"]').or(page.locator('input[name*="password"]')).first().fill(userData.password);
|
||||
await this.page.locator('input[placeholder*="确认密码"]').or(page.locator('input[name*="confirmPassword"]')).fill(userData.confirmPassword);
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(page.locator('button:has-text("确定")')).click();
|
||||
}
|
||||
|
||||
async editUser(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '编辑' }).or(page.locator(`tbody tr:nth-child(${rowNumber}) .edit-button`)).click();
|
||||
}
|
||||
|
||||
async deleteUser(rowNumber: number) {
|
||||
await this.table.locator(`tbody tr:nth-child(${rowNumber})`).getByRole('button', { name: '删除' }).or(page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(page.locator('.confirm-dialog .confirm-button')).click();
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async nextPage() {
|
||||
await this.nextPageButton.click();
|
||||
}
|
||||
|
||||
async prevPage() {
|
||||
await this.prevPageButton.click();
|
||||
}
|
||||
|
||||
async getCurrentPage(): Promise<string> {
|
||||
return await this.page.locator('.el-pagination .el-pager li.active').or(page.locator('.pagination .current-page')).textContent() || '1';
|
||||
}
|
||||
|
||||
async getUserCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async getUserName(rowNumber: number): Promise<string | null> {
|
||||
return await this.table.locator(`tbody tr:nth-child(${rowNumber}) td:first-child`).textContent();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user