feat: 添加异常日志功能并优化UI样式
refactor: 重构后端查询逻辑和API响应处理 fix: 修复用户角色更新和文件上传问题 test: 添加前端性能测试脚本和E2E测试用例 chore: 更新依赖版本和配置文件 docs: 添加环境检查脚本和测试文档 style: 统一表格标签样式和路由命名 perf: 优化前端页面加载速度和响应时间
This commit is contained in:
@@ -31,7 +31,7 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToUserManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
|
||||
const systemMenu = this.page.locator('text=系统管理');
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.userManagementLink.click();
|
||||
@@ -39,7 +39,7 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToRoleManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
|
||||
const systemMenu = this.page.locator('text=系统管理');
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.roleManagementLink.click();
|
||||
@@ -47,7 +47,7 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToMenuManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
|
||||
const systemMenu = this.page.locator('text=系统管理');
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.menuManagementLink.click();
|
||||
@@ -55,7 +55,7 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToSystemConfig() {
|
||||
const configMenu = this.page.locator('.el-sub-menu').filter({ hasText: '系统配置' });
|
||||
const configMenu = this.page.locator('text=系统配置');
|
||||
await configMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.systemConfigLink.click();
|
||||
@@ -63,7 +63,7 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToNoticeManagement() {
|
||||
const notifyMenu = this.page.locator('.el-sub-menu').filter({ hasText: '通知中心' });
|
||||
const notifyMenu = this.page.locator('text=通知中心');
|
||||
await notifyMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
await this.noticeManagementLink.click();
|
||||
@@ -71,25 +71,27 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToFileManagement() {
|
||||
const fileMenu = this.page.locator('.el-sub-menu').filter({ hasText: '文件管理' });
|
||||
const fileMenu = this.page.locator('text=文件管理');
|
||||
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: '审计中心' });
|
||||
async navigateToAudit() {
|
||||
const auditMenu = this.page.locator('text=审计中心');
|
||||
await auditMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async navigateToOperationLog() {
|
||||
await this.navigateToAudit();
|
||||
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.navigateToAudit();
|
||||
await this.loginLogLink.click();
|
||||
await this.page.waitForURL('**/loginlog');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export class DictionaryManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly editButton;
|
||||
readonly deleteButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly dictNameInput;
|
||||
readonly dictTypeInput;
|
||||
readonly dictStatusSelect;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.addButton = page.getByRole('button', { name: '新增字典' });
|
||||
this.editButton = page.getByRole('button', { name: '编辑' });
|
||||
this.deleteButton = page.getByRole('button', { name: '删除' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.searchInput = page.getByPlaceholder('搜索字典名称');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.dictNameInput = page.getByPlaceholder('请输入字典名称');
|
||||
this.dictTypeInput = page.getByPlaceholder('请输入字典类型');
|
||||
this.dictStatusSelect = page.locator('.el-select');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/system/dict');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async addDictionary(dictName: string, dictType: string, status: string = '0') {
|
||||
await this.addButton.click();
|
||||
|
||||
await this.dictNameInput.fill(dictName);
|
||||
await this.dictTypeInput.fill(dictType);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async editDictionary(dictType: string, newName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: dictType }).first();
|
||||
await row.locator('.el-button--primary').click();
|
||||
|
||||
await this.dictNameInput.clear();
|
||||
await this.dictNameInput.fill(newName);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async deleteDictionary(dictType: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: dictType }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchDictionary(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export class FileManagementPage {
|
||||
readonly page: Page;
|
||||
readonly uploadButton;
|
||||
readonly fileInput;
|
||||
readonly table;
|
||||
readonly deleteButton;
|
||||
readonly downloadButton;
|
||||
readonly searchInput;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.uploadButton = page.locator('.el-upload--text').first();
|
||||
this.fileInput = page.locator('input[type="file"]');
|
||||
this.table = page.locator('.el-table');
|
||||
this.deleteButton = page.getByRole('button', { name: '删除' });
|
||||
this.downloadButton = page.getByRole('button', { name: '下载' });
|
||||
this.searchInput = page.locator('.search-bar .el-input__inner');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/files');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.page.waitForTimeout(3000);
|
||||
}
|
||||
|
||||
async uploadFile(filePath: string) {
|
||||
await this.uploadButton.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await this.uploadButton.click();
|
||||
|
||||
const fileInput = this.page.locator('input[type="file"]');
|
||||
await fileInput.setInputFiles(filePath);
|
||||
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async deleteFile(fileName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: fileName }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
|
||||
const confirmButton = this.page.getByRole('button', { name: '确定' });
|
||||
await confirmButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async downloadFile(fileName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: fileName }).first();
|
||||
const downloadButton = row.locator('.el-button--primary').first();
|
||||
await downloadButton.click();
|
||||
}
|
||||
|
||||
async searchFile(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export class LoginLogPage {
|
||||
readonly page: Page;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly table;
|
||||
readonly exportButton;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.searchInput = page.getByPlaceholder('搜索用户名或IP地址');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.table = page.locator('.el-table');
|
||||
this.exportButton = page.getByRole('button', { name: '导出' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/loginlog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchByKeyword(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
|
||||
async exportData() {
|
||||
await this.exportButton.click();
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ export class LoginPage {
|
||||
|
||||
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.usernameInput = page.locator('input[placeholder="请输入用户名"]');
|
||||
this.passwordInput = page.locator('input[placeholder="请输入密码"]');
|
||||
this.loginButton = page.locator('button:has-text("登录")');
|
||||
this.errorMessage = page.locator('.el-message--error .el-message__content');
|
||||
this.logoutButton = page.getByRole('button', { name: '退出登录' });
|
||||
}
|
||||
|
||||
@@ -23,25 +23,45 @@ export class LoginPage {
|
||||
}
|
||||
|
||||
async login(username: string, password: string) {
|
||||
console.log('Starting login process...');
|
||||
await this.usernameInput.fill(username);
|
||||
await this.passwordInput.fill(password);
|
||||
console.log('Filled username and password');
|
||||
await this.loginButton.click();
|
||||
|
||||
console.log('Clicked login button');
|
||||
|
||||
try {
|
||||
await this.page.waitForURL('**/dashboard', { timeout: 10000 });
|
||||
} catch {
|
||||
console.log('Successfully navigated to dashboard');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
console.log('Network idle achieved');
|
||||
await this.page.waitForTimeout(2000);
|
||||
console.log('Wait completed');
|
||||
} catch (error) {
|
||||
console.log('Login failed or timeout:', error);
|
||||
const currentUrl = this.page.url();
|
||||
console.log('Current URL:', currentUrl);
|
||||
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();
|
||||
await this.page.waitForSelector('.el-message--error', { timeout: 10000 });
|
||||
await this.page.waitForTimeout(500);
|
||||
const messageElement = await this.page.locator('.el-message--error .el-message__content').first();
|
||||
const text = await messageElement.textContent();
|
||||
return text;
|
||||
} catch {
|
||||
return null;
|
||||
try {
|
||||
await this.page.waitForSelector('.el-message', { timeout: 5000 });
|
||||
await this.page.waitForTimeout(500);
|
||||
const messageElement = await this.page.locator('.el-message .el-message__content').first();
|
||||
const text = await messageElement.textContent();
|
||||
return text;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +69,7 @@ export class LoginPage {
|
||||
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 });
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export class NotificationPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly editButton;
|
||||
readonly deleteButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly titleInput;
|
||||
readonly contentInput;
|
||||
readonly typeSelect;
|
||||
readonly statusSelect;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.addButton = page.getByRole('button', { name: '新增' });
|
||||
this.editButton = page.getByRole('button', { name: '修改' });
|
||||
this.deleteButton = page.getByRole('button', { name: '删除' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.searchInput = page.getByPlaceholder('搜索通知标题');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.titleInput = page.getByPlaceholder('请输入通知标题');
|
||||
this.contentInput = page.getByPlaceholder('请输入通知内容');
|
||||
this.typeSelect = page.locator('.el-select');
|
||||
this.statusSelect = page.locator('.el-select');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/system/notice');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async addNotification(title: string, content: string, type: string = '1', status: string = '0') {
|
||||
await this.addButton.click();
|
||||
|
||||
await this.titleInput.fill(title);
|
||||
await this.contentInput.fill(content);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async editNotification(title: string, newContent: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: title }).first();
|
||||
await row.locator('.el-button--primary').click();
|
||||
|
||||
await this.contentInput.clear();
|
||||
await this.contentInput.fill(newContent);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async deleteNotification(title: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: title }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchNotification(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export class OperationLogPage {
|
||||
readonly page: Page;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly table;
|
||||
readonly exportButton;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.searchInput = page.getByPlaceholder('搜索操作人或操作模块');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.table = page.locator('.el-table');
|
||||
this.exportButton = page.getByRole('button', { name: '导出' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/oplog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchByKeyword(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
|
||||
async exportData() {
|
||||
await this.exportButton.click();
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ export class RoleManagementPage {
|
||||
|
||||
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.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"]'));
|
||||
@@ -44,29 +44,23 @@ export class RoleManagementPage {
|
||||
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);
|
||||
}
|
||||
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.remarkInput.fill(roleData.remark);
|
||||
await this.page.locator('.el-dialog').locator('textarea').fill(roleData.remark);
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(page.locator('button:has-text("确定")')).click();
|
||||
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(page.locator(`tbody tr:nth-child(${rowNumber}) .edit-button`)).click();
|
||||
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(page.locator(`tbody tr:nth-child(${rowNumber}) .delete-button`)).click();
|
||||
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() {
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export class SystemConfigPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly editButton;
|
||||
readonly deleteButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly configNameInput;
|
||||
readonly configKeyInput;
|
||||
readonly configValueInput;
|
||||
readonly configTypeSelect;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.addButton = page.getByRole('button', { name: '新增配置' });
|
||||
this.editButton = page.getByRole('button', { name: '编辑' });
|
||||
this.deleteButton = page.getByRole('button', { name: '删除' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.searchInput = page.getByPlaceholder('搜索配置名称');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.configNameInput = page.getByPlaceholder('请输入配置名称');
|
||||
this.configKeyInput = page.getByPlaceholder('请输入配置键名');
|
||||
this.configValueInput = page.getByPlaceholder('请输入配置键值');
|
||||
this.configTypeSelect = page.locator('.el-select');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/sys/config');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async addConfig(configName: string, configKey: string, configValue: string, configType: string = 'Y') {
|
||||
await this.addButton.click();
|
||||
|
||||
await this.configNameInput.fill(configName);
|
||||
await this.configKeyInput.fill(configKey);
|
||||
await this.configValueInput.fill(configValue);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async editConfig(configKey: string, newValue: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: configKey }).first();
|
||||
await row.locator('.el-button--primary').click();
|
||||
|
||||
await this.configValueInput.clear();
|
||||
await this.configValueInput.fill(newValue);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async deleteConfig(configKey: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: configKey }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchConfig(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ export class UserManagementPage {
|
||||
|
||||
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.table = page.locator('.el-table').first();
|
||||
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'));
|
||||
@@ -35,34 +35,53 @@ export class UserManagementPage {
|
||||
|
||||
async fillUserForm(userData: {
|
||||
username: string;
|
||||
nickname?: string;
|
||||
email: string;
|
||||
phone?: string;
|
||||
password: string;
|
||||
confirmPassword: 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);
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
await dialog.locator('input').first().fill(userData.username);
|
||||
if (userData.nickname) {
|
||||
await dialog.locator('input').nth(1).fill(userData.nickname);
|
||||
}
|
||||
await dialog.locator('input[type="password"]').fill(userData.password);
|
||||
await dialog.locator('input').nth(3).fill(userData.email);
|
||||
if (userData.phone) {
|
||||
const phoneInput = dialog.locator('input[placeholder*="手机号"]');
|
||||
if (await phoneInput.count() > 0) {
|
||||
await phoneInput.fill(userData.phone);
|
||||
} else {
|
||||
const phoneSelect = dialog.locator('.el-select');
|
||||
if (await phoneSelect.count() > 0) {
|
||||
await phoneSelect.first().click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const selectInput = this.page.locator('.el-select-dropdown__input');
|
||||
if (await selectInput.count() > 0) {
|
||||
await selectInput.fill(userData.phone);
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
await this.page.keyboard.press('Enter');
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.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();
|
||||
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 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();
|
||||
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(page.locator('.confirm-dialog .confirm-button')).click();
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
@@ -79,7 +98,7 @@ export class UserManagementPage {
|
||||
}
|
||||
|
||||
async getCurrentPage(): Promise<string> {
|
||||
return await this.page.locator('.el-pagination .el-pager li.active').or(page.locator('.pagination .current-page')).textContent() || '1';
|
||||
return await this.page.locator('.el-pagination .el-pager li.active').or(this.page.locator('.pagination .current-page')).textContent() || '1';
|
||||
}
|
||||
|
||||
async getUserCount(): Promise<number> {
|
||||
|
||||
Reference in New Issue
Block a user