test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名 - 新增 UAT 测试套件与 journey 测试用例 - 优化测试辅助工具与数据工厂 - 更新 playwright 认证状态
This commit is contained in:
@@ -15,16 +15,16 @@ export class DashboardPage {
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.userInfo = page.locator('.el-avatar');
|
||||
this.userManagementLink = page.locator('.el-menu-item:has-text("用户管理")');
|
||||
this.roleManagementLink = page.locator('.el-menu-item:has-text("角色管理")');
|
||||
this.menuManagementLink = page.locator('.el-menu-item:has-text("菜单管理")');
|
||||
this.systemConfigLink = page.locator('.el-menu-item:has-text("参数配置")');
|
||||
this.noticeManagementLink = page.locator('.el-menu-item:has-text("通知公告")');
|
||||
this.fileManagementLink = page.locator('.el-menu-item:has-text("文件列表")');
|
||||
this.operationLogLink = page.locator('.el-menu-item:has-text("操作日志")');
|
||||
this.loginLogLink = page.locator('.el-menu-item:has-text("登录日志")');
|
||||
this.dictionaryLink = page.locator('.el-menu-item:has-text("字典管理")');
|
||||
this.userInfo = page.locator('.ant-avatar');
|
||||
this.userManagementLink = page.locator('.ant-menu-item:has-text("用户管理")');
|
||||
this.roleManagementLink = page.locator('.ant-menu-item:has-text("角色管理")');
|
||||
this.menuManagementLink = page.locator('.ant-menu-item:has-text("菜单管理")');
|
||||
this.systemConfigLink = page.locator('.ant-menu-item:has-text("参数配置")');
|
||||
this.noticeManagementLink = page.locator('.ant-menu-item:has-text("通知公告")');
|
||||
this.fileManagementLink = page.locator('.ant-menu-item:has-text("文件列表")');
|
||||
this.operationLogLink = page.locator('.ant-menu-item:has-text("操作日志")');
|
||||
this.loginLogLink = page.locator('.ant-menu-item:has-text("登录日志")');
|
||||
this.dictionaryLink = page.locator('.ant-menu-item:has-text("字典管理")');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
@@ -33,97 +33,76 @@ export class DashboardPage {
|
||||
}
|
||||
|
||||
async navigateToUserManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu__title:has-text("系统管理")');
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('系统管理');
|
||||
await this.userManagementLink.click();
|
||||
await this.page.waitForURL('**/users', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToRoleManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu__title:has-text("系统管理")');
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('系统管理');
|
||||
await this.roleManagementLink.click();
|
||||
await this.page.waitForURL('**/roles', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToMenuManagement() {
|
||||
const systemMenu = this.page.locator('.el-sub-menu__title:has-text("系统管理")');
|
||||
await systemMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('系统管理');
|
||||
await this.menuManagementLink.click();
|
||||
await this.page.waitForURL('**/menus', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToSystemConfig() {
|
||||
const configMenu = this.page.locator('.el-sub-menu__title:has-text("系统配置")');
|
||||
await configMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('系统配置');
|
||||
await this.systemConfigLink.click();
|
||||
await this.page.waitForURL('**/sys/config', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToNoticeManagement() {
|
||||
const notifyMenu = this.page.locator('.el-sub-menu__title:has-text("通知中心")');
|
||||
await notifyMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('通知中心');
|
||||
await this.noticeManagementLink.click();
|
||||
await this.page.waitForURL('**/notice', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToFileManagement() {
|
||||
const fileMenu = this.page.locator('.el-sub-menu__title:has-text("文件管理")');
|
||||
await fileMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('文件管理');
|
||||
await this.fileManagementLink.click();
|
||||
await this.page.waitForURL('**/files', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToAudit() {
|
||||
const auditMenu = this.page.locator('.el-sub-menu__title:has-text("审计中心")');
|
||||
await auditMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async navigateToOperationLog() {
|
||||
await this.navigateToAudit();
|
||||
await this.clickSubMenu('审计中心');
|
||||
await this.operationLogLink.click();
|
||||
await this.page.waitForURL('**/oplog', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToLoginLog() {
|
||||
await this.navigateToAudit();
|
||||
await this.clickSubMenu('审计中心');
|
||||
await this.loginLogLink.click();
|
||||
await this.page.waitForURL('**/loginlog', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToNotification() {
|
||||
const notifyMenu = this.page.locator('.el-sub-menu__title:has-text("通知中心")');
|
||||
await notifyMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.noticeManagementLink.click();
|
||||
await this.page.waitForURL('**/notification', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async navigateToDictionary() {
|
||||
const configMenu = this.page.locator('.el-sub-menu__title:has-text("系统配置")');
|
||||
await configMenu.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
await this.clickSubMenu('系统配置');
|
||||
await this.dictionaryLink.click();
|
||||
await this.page.waitForURL('**/dict', { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
private async clickSubMenu(label: string) {
|
||||
const subMenu = this.page.locator(`.ant-menu-submenu-title:has-text("${label}")`);
|
||||
if (await subMenu.isVisible()) {
|
||||
await subMenu.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
}
|
||||
|
||||
async getUsername(): Promise<string | null> {
|
||||
return await this.userInfo.textContent();
|
||||
}
|
||||
|
||||
@@ -2,95 +2,109 @@ import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class DictionaryManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createDictButton: Locator;
|
||||
readonly saveButton: Locator;
|
||||
readonly dialog: Locator;
|
||||
readonly dictNameInput: Locator;
|
||||
readonly dictTypeInput: Locator;
|
||||
readonly statusSelect: Locator;
|
||||
readonly remarkInput: Locator;
|
||||
readonly typeTable: Locator;
|
||||
readonly dataTable: Locator;
|
||||
readonly addTypeButton: Locator;
|
||||
readonly addDataButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.createDictButton = page.getByRole('button', { name: '新增字典' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.dialog = page.locator('.el-dialog');
|
||||
this.dictNameInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典名称' });
|
||||
this.dictTypeInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典类型' });
|
||||
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
|
||||
this.remarkInput = page.locator('.el-dialog').getByRole('textbox', { name: '备注' });
|
||||
this.typeTable = page.locator('.ant-card').filter({ hasText: '字典类型' }).locator('.ant-table').first();
|
||||
this.dataTable = page.locator('.ant-card').filter({ hasText: '字典数据' }).locator('.ant-table').first();
|
||||
this.addTypeButton = page.locator('.ant-card').filter({ hasText: '字典类型' }).getByRole('button', { name: '新增' });
|
||||
this.addDataButton = page.locator('.ant-card').filter({ hasText: '字典数据' }).getByRole('button', { name: '新增' });
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到字典管理页面...');
|
||||
await this.page.goto('/dict');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*dict/);
|
||||
|
||||
console.log('字典管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/dict-management-error-${Date.now()}.png` });
|
||||
console.error('导航到字典管理页面失败:', error);
|
||||
throw new Error(`导航到字典管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/dict');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.typeTable.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*dict/);
|
||||
}
|
||||
|
||||
async createDict(dictName: string, dictType: string, status: string = '0', remark?: string) {
|
||||
await this.createDictButton.click();
|
||||
async createDictType(dictName: string, dictType: string, status: number = 1, remark?: string) {
|
||||
await this.addTypeButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.dictNameInput.fill(dictName);
|
||||
await this.dictTypeInput.fill(dictType);
|
||||
|
||||
if (status) {
|
||||
await this.statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.getByRole('option', { name: status === '0' ? '正常' : '停用' }).click();
|
||||
}
|
||||
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典类型|编辑字典类型/ });
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '字典名称' }).locator('input').fill(dictName);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '字典类型' }).locator('input').fill(dictType);
|
||||
|
||||
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const statusText = status === 1 ? '正常' : '停用';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
|
||||
|
||||
if (remark) {
|
||||
await this.remarkInput.fill(remark);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '备注' }).locator('textarea').fill(remark);
|
||||
}
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async editDict(dictName: string, newDictName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
|
||||
const editBtn = row.getByRole('button', { name: '编辑' });
|
||||
await editBtn.click();
|
||||
async editDictType(dictName: string, newDictName: string) {
|
||||
const row = this.typeTable.locator('tbody tr').filter({ hasText: dictName }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.dictNameInput.clear();
|
||||
await this.dictNameInput.fill(newDictName);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典类型|编辑字典类型/ });
|
||||
const nameInput = modal.locator('.ant-form-item').filter({ hasText: '字典名称' }).locator('input');
|
||||
await nameInput.clear();
|
||||
await nameInput.fill(newDictName);
|
||||
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async deleteDict(dictName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
|
||||
const deleteBtn = row.getByRole('button', { name: '删除' });
|
||||
await deleteBtn.click();
|
||||
async deleteDictType(dictName: string) {
|
||||
const row = this.typeTable.locator('tbody tr').filter({ hasText: dictName }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async selectDictType(dictType: string) {
|
||||
const link = this.typeTable.locator('a').filter({ hasText: dictType });
|
||||
await link.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
await confirmBtn.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async getDictCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
async createDictData(dictLabel: string, dictValue: string, sort: number = 0, status: number = 1) {
|
||||
await this.addDataButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典数据|编辑字典数据/ });
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '字典标签' }).locator('input').fill(dictLabel);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '字典值' }).locator('input').fill(dictValue);
|
||||
|
||||
if (sort > 0) {
|
||||
const sortInput = modal.locator('.ant-form-item').filter({ hasText: '排序' }).locator('.ant-input-number input');
|
||||
await sortInput.clear();
|
||||
await sortInput.fill(String(sort));
|
||||
}
|
||||
|
||||
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const statusText = status === 1 ? '正常' : '停用';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
|
||||
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
async typeContainsText(text: string): Promise<boolean> {
|
||||
return this.typeTable.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async dataContainsText(text: string): Promise<boolean> {
|
||||
return this.dataTable.getByText(text).count() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,98 +4,44 @@ export class ExceptionLogPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly exportButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly detailButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').or(page.locator('.exception-log-table'));
|
||||
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.exportButton = page.getByRole('button', { name: '导出' }).or(page.locator('button:has-text("导出")'));
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' }).or(page.locator('button:has-text("刷新")'));
|
||||
this.detailButton = page.getByRole('button', { name: '详情' }).or(page.locator('.detail-button'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.searchInput = page.getByPlaceholder('搜索路径/异常信息');
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到异常日志页面...');
|
||||
await this.page.goto('/exceptionlog');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*exceptionlog/);
|
||||
|
||||
console.log('异常日志页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/exception-log-error-${Date.now()}.png` });
|
||||
console.error('导航到异常日志页面失败:', error);
|
||||
throw new Error(`导航到异常日志页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/exceptionlog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*exceptionlog/);
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.fill('');
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async exportData() {
|
||||
await this.exportButton.click();
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
await this.refreshButton.click();
|
||||
await this.searchInput.press('Enter');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async viewDetail(exceptionId: string) {
|
||||
const exceptionRow = this.table.locator('tbody tr').filter({ hasText: exceptionId });
|
||||
await exceptionRow.locator('.detail-button').or(this.page.getByRole('button', { name: '详情' })).click();
|
||||
}
|
||||
|
||||
async closeDetailDialog() {
|
||||
await this.page.getByRole('button', { name: '关闭' }).or(this.page.locator('.el-dialog .close-button')).click();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchInput.press('Enter');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async isSuccessMessageVisible(): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.page.reload();
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string): Promise<void> {
|
||||
const contains = await this.containsText(text);
|
||||
if (!contains) {
|
||||
throw new Error(`Table does not contain text: ${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
async getLogCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,106 +1,65 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class FileManagementPage {
|
||||
readonly page: Page;
|
||||
readonly uploadButton;
|
||||
readonly fileInput;
|
||||
readonly table;
|
||||
readonly deleteButton;
|
||||
readonly downloadButton;
|
||||
readonly searchInput;
|
||||
readonly uploadButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly table: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
|
||||
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');
|
||||
this.uploadButton = page.getByRole('button', { name: '上传文件' });
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到文件管理页面...');
|
||||
await this.page.goto('/files');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*files/);
|
||||
|
||||
console.log('文件管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/file-management-error-${Date.now()}.png` });
|
||||
console.error('导航到文件管理页面失败:', error);
|
||||
throw new Error(`导航到文件管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/files');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*files/);
|
||||
}
|
||||
|
||||
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);
|
||||
await this.page.waitForTimeout(2000);
|
||||
}
|
||||
|
||||
async deleteFile(fileName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: fileName }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: fileName }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
const confirmButton = this.page.getByRole('button', { name: '确定' });
|
||||
await confirmButton.click();
|
||||
async previewFile(fileName: string) {
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: fileName }).first();
|
||||
await row.getByRole('button', { name: '预览' }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async closePreview() {
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /预览/ });
|
||||
await modal.getByRole('button', { name: '关闭' }).click();
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.refreshButton.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;
|
||||
}
|
||||
|
||||
async clickUploadButton() {
|
||||
await this.uploadButton.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await this.uploadButton.click();
|
||||
}
|
||||
|
||||
async submitUpload() {
|
||||
const confirmButton = this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.el-dialog .el-button--primary'));
|
||||
await confirmButton.click();
|
||||
}
|
||||
|
||||
async clickDeleteButton(rowNumber: number) {
|
||||
const row = this.table.locator(`tbody tr:nth-child(${rowNumber})`);
|
||||
await row.locator('.el-button--danger').click();
|
||||
}
|
||||
|
||||
async clickDownloadButton(rowNumber: number) {
|
||||
const row = this.table.locator(`tbody tr:nth-child(${rowNumber})`);
|
||||
await row.locator('.el-button--primary').first().click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,47 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class LoginLogPage {
|
||||
readonly page: Page;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly table;
|
||||
readonly exportButton;
|
||||
readonly searchInput: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly table: Locator;
|
||||
|
||||
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: '导出' });
|
||||
this.searchInput = page.getByPlaceholder('搜索用户名/IP');
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.table = page.locator('.ant-table').first();
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到登录日志页面...');
|
||||
await this.page.goto('/loginlog');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*loginlog/);
|
||||
|
||||
console.log('登录日志页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/login-log-error-${Date.now()}.png` });
|
||||
console.error('导航到登录日志页面失败:', error);
|
||||
throw new Error(`导航到登录日志页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/loginlog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*loginlog/);
|
||||
}
|
||||
|
||||
async searchByKeyword(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.searchInput.press('Enter');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.searchInput.press('Enter');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
async reload() {
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async exportData() {
|
||||
await this.exportButton.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ export class LoginPage {
|
||||
readonly passwordInput: Locator;
|
||||
readonly loginButton: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
readonly logoutButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
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: '退出登录' });
|
||||
this.usernameInput = page.locator('input[placeholder="用户名"]');
|
||||
this.passwordInput = page.locator('input[placeholder="密码"]');
|
||||
this.loginButton = page.getByRole('button', { name: /登\s*录/ });
|
||||
this.errorMessage = page.locator('.ant-message-error .ant-message-notice-content');
|
||||
this.successMessage = page.locator('.ant-message-success .ant-message-notice-content');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
@@ -22,87 +22,39 @@ export class LoginPage {
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async login(username: string, password: string, maxRetries: number = 3) {
|
||||
let lastError: Error | null = null;
|
||||
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
console.log(`Login attempt ${attempt}/${maxRetries}`);
|
||||
|
||||
try {
|
||||
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');
|
||||
async login(username: string, password: string) {
|
||||
await this.usernameInput.fill(username);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.loginButton.click();
|
||||
await this.page.waitForURL(/\/(dashboard)/, { timeout: 30000 });
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
await this.page.waitForURL(/\/(dashboard|\/)$/, { timeout: 30000 });
|
||||
console.log('Successfully navigated to dashboard or home');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
console.log('Network idle achieved');
|
||||
await this.page.waitForTimeout(2000);
|
||||
console.log('Login completed successfully');
|
||||
return;
|
||||
} catch (error) {
|
||||
lastError = error as Error;
|
||||
console.log(`Login attempt ${attempt} failed:`, error);
|
||||
|
||||
const currentUrl = this.page.url();
|
||||
console.log('Current URL:', currentUrl);
|
||||
|
||||
const errorMessage = await this.getErrorMessage();
|
||||
if (errorMessage) {
|
||||
console.log('Login error message:', errorMessage);
|
||||
}
|
||||
|
||||
const token = await this.page.evaluate(() => localStorage.getItem('token'));
|
||||
console.log('Token in localStorage:', token ? 'exists' : 'not found');
|
||||
|
||||
if (attempt < maxRetries) {
|
||||
console.log(`Waiting 2 seconds before retry...`);
|
||||
await this.page.waitForTimeout(2000);
|
||||
|
||||
await this.goto();
|
||||
console.log('Navigated back to login page for retry');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`All ${maxRetries} login attempts failed`);
|
||||
throw lastError || new Error('Login failed after all retries');
|
||||
async loginAndExpectError(username: string, password: string) {
|
||||
await this.usernameInput.fill(username);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.loginButton.click();
|
||||
}
|
||||
|
||||
async getErrorMessage(): Promise<string | null> {
|
||||
try {
|
||||
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;
|
||||
await this.errorMessage.waitFor({ state: 'visible', timeout: 5000 });
|
||||
return await this.errorMessage.textContent();
|
||||
} catch {
|
||||
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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async logout() {
|
||||
const avatar = this.page.locator('.el-avatar');
|
||||
const avatar = this.page.locator('.ant-avatar').first();
|
||||
await avatar.click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
|
||||
const logoutButton = this.page.locator('.el-dropdown-menu').getByText('退出登录');
|
||||
await logoutButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
const logoutItem = this.page.locator('.ant-dropdown-menu-item:has-text("退出登录")');
|
||||
await logoutItem.click();
|
||||
await this.page.waitForURL('**/login', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async isLoggedIn(): Promise<boolean> {
|
||||
return this.page.url().includes('/dashboard') || this.page.url() === this.page.url().split('?')[0].split('#')[0];
|
||||
return this.page.url().includes('/dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,44 +4,24 @@ export class MenuManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createMenuButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly treeContainer: Locator;
|
||||
readonly expandAllButton: Locator;
|
||||
readonly collapseAllButton: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').or(page.locator('.menu-table'));
|
||||
this.createMenuButton = 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.treeContainer = page.locator('.el-tree').or(page.locator('.menu-tree'));
|
||||
this.expandAllButton = page.getByRole('button', { name: '展开全部' }).or(page.locator('button:has-text("展开全部")'));
|
||||
this.collapseAllButton = page.getByRole('button', { name: '折叠全部' }).or(page.locator('button:has-text("折叠全部")'));
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.createMenuButton = page.getByRole('button', { name: '新增菜单' });
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到菜单管理页面...');
|
||||
await this.page.goto('/menus');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.page.waitForSelector('.el-tree', { timeout: 10000 }).catch(() => {
|
||||
return this.page.waitForSelector('.el-table', { timeout: 5000 });
|
||||
});
|
||||
|
||||
await expect(this.page).toHaveURL(/.*menus/);
|
||||
|
||||
console.log('菜单管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/menu-management-error-${Date.now()}.png` });
|
||||
console.error('导航到菜单管理页面失败:', error);
|
||||
throw new Error(`导航到菜单管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/menus');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*menus/);
|
||||
}
|
||||
|
||||
async clickCreateMenu() {
|
||||
@@ -49,120 +29,110 @@ export class MenuManagementPage {
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async clickAddChildMenu(parentMenuName: string) {
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: parentMenuName });
|
||||
await row.getByRole('button', { name: '新增子菜单' }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async fillMenuForm(menuData: {
|
||||
menuName: string;
|
||||
menuType?: string;
|
||||
name: string;
|
||||
type?: string;
|
||||
path?: string;
|
||||
icon?: string;
|
||||
component?: string;
|
||||
permission?: string;
|
||||
sort?: number;
|
||||
visible?: string;
|
||||
status?: string;
|
||||
visible?: boolean;
|
||||
}) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
|
||||
await dialog.locator('input').first().fill(menuData.menuName);
|
||||
|
||||
if (menuData.menuType) {
|
||||
const menuTypeSelect = dialog.locator('.el-select').first();
|
||||
await menuTypeSelect.click();
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增菜单|编辑菜单/ });
|
||||
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '菜单名称' }).locator('input').fill(menuData.name);
|
||||
|
||||
if (menuData.type) {
|
||||
const typeSelect = modal.locator('.ant-form-item').filter({ hasText: '类型' }).locator('.ant-select');
|
||||
await typeSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.getByRole('option', { name: menuData.menuType }).click();
|
||||
const typeMap: Record<string, string> = { directory: '目录', menu: '菜单', button: '按钮' };
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: typeMap[menuData.type] || menuData.type }).first().click();
|
||||
}
|
||||
|
||||
|
||||
if (menuData.path) {
|
||||
const pathInput = dialog.locator('input[placeholder*="路径"]');
|
||||
if (await pathInput.count() > 0) {
|
||||
await pathInput.fill(menuData.path);
|
||||
}
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '路径' }).locator('input').fill(menuData.path);
|
||||
}
|
||||
if (menuData.icon) {
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '图标' }).locator('input').fill(menuData.icon);
|
||||
}
|
||||
|
||||
if (menuData.component) {
|
||||
const componentInput = dialog.locator('input[placeholder*="组件"]');
|
||||
if (await componentInput.count() > 0) {
|
||||
await componentInput.fill(menuData.component);
|
||||
}
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '组件路径' }).locator('input').fill(menuData.component);
|
||||
}
|
||||
|
||||
if (menuData.permission) {
|
||||
const permissionInput = dialog.locator('input[placeholder*="权限"]');
|
||||
if (await permissionInput.count() > 0) {
|
||||
await permissionInput.fill(menuData.permission);
|
||||
}
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '权限标识' }).locator('input').fill(menuData.permission);
|
||||
}
|
||||
|
||||
if (menuData.sort !== undefined) {
|
||||
const sortInput = dialog.locator('input[type="number"]');
|
||||
if (await sortInput.count() > 0) {
|
||||
await sortInput.fill(String(menuData.sort));
|
||||
}
|
||||
const sortInput = modal.locator('.ant-form-item').filter({ hasText: '排序' }).locator('.ant-input-number input');
|
||||
await sortInput.clear();
|
||||
await sortInput.fill(String(menuData.sort));
|
||||
}
|
||||
|
||||
if (menuData.visible) {
|
||||
const visibleRadio = dialog.locator(`input[value="${menuData.visible}"]`);
|
||||
if (await visibleRadio.count() > 0) {
|
||||
await visibleRadio.check();
|
||||
}
|
||||
}
|
||||
|
||||
if (menuData.status) {
|
||||
const statusRadio = dialog.locator(`input[value="${menuData.status}"]`);
|
||||
if (await statusRadio.count() > 0) {
|
||||
await statusRadio.check();
|
||||
}
|
||||
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const statusText = menuData.status === 'ACTIVE' ? '正常' : '停用';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
|
||||
}
|
||||
if (menuData.visible !== undefined) {
|
||||
const visibleSelect = modal.locator('.ant-form-item').filter({ hasText: '可见' }).locator('.ant-select');
|
||||
await visibleSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const visibleText = menuData.visible ? '显示' : '隐藏';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: visibleText }).first().click();
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('button:has-text("确定")')).click();
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增菜单|编辑菜单/ });
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async cancelForm() {
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增菜单|编辑菜单/ });
|
||||
await modal.getByRole('button', { name: /取\s*消/ }).click();
|
||||
}
|
||||
|
||||
async editMenu(menuName: string) {
|
||||
const menuRow = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await menuRow.getByRole('button', { name: '编辑' }).or(this.page.locator('.edit-button')).click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async deleteMenu(menuName: string) {
|
||||
const menuRow = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await menuRow.getByRole('button', { name: '删除' }).or(this.page.locator('.delete-button')).click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async expandAll() {
|
||||
await this.expandAllButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async collapseAll() {
|
||||
await this.collapseAllButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
async cancelDelete() {
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /取\s*消/ }).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;
|
||||
}
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async getMenuCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.page.reload();
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,81 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class NotificationPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly dialog;
|
||||
readonly titleInput;
|
||||
readonly contentInput;
|
||||
readonly noticeTypeSelect;
|
||||
readonly statusSelect;
|
||||
readonly table: Locator;
|
||||
readonly addButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.addButton = page.getByRole('button', { name: '新增公告' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.dialog = page.locator('.el-dialog');
|
||||
this.titleInput = page.locator('.el-dialog').getByRole('textbox', { name: '公告标题' });
|
||||
this.contentInput = page.locator('.el-dialog').getByRole('textbox', { name: '公告内容' });
|
||||
this.noticeTypeSelect = page.locator('.el-dialog').getByRole('combobox', { name: '公告类型' });
|
||||
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.addButton = page.getByRole('button', { name: '新增通知' });
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到通知管理页面...');
|
||||
await this.page.goto('/notice');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*notice/);
|
||||
|
||||
console.log('通知管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/notification-error-${Date.now()}.png` });
|
||||
console.error('导航到通知管理页面失败:', error);
|
||||
throw new Error(`导航到通知管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/notice');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*notice/);
|
||||
}
|
||||
|
||||
async addNotification(title: string, content: string) {
|
||||
async addNotification(title: string, content: string, type?: string) {
|
||||
await this.addButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.titleInput.fill(title);
|
||||
await this.contentInput.fill(content);
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增通知|编辑通知/ });
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '标题' }).locator('input').fill(title);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
if (type) {
|
||||
const typeSelect = modal.locator('.ant-form-item').filter({ hasText: '类型' }).locator('.ant-select');
|
||||
await typeSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: type }).first().click();
|
||||
}
|
||||
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '内容' }).locator('textarea').fill(content);
|
||||
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async editNotification(title: string, newContent: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: title }).first();
|
||||
const editBtn = row.getByRole('button', { name: '编辑' });
|
||||
await editBtn.click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: title }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.contentInput.clear();
|
||||
await this.contentInput.fill(newContent);
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增通知|编辑通知/ });
|
||||
const contentTextarea = modal.locator('.ant-form-item').filter({ hasText: '内容' }).locator('textarea');
|
||||
await contentTextarea.clear();
|
||||
await contentTextarea.fill(newContent);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async deleteNotification(title: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: title }).first();
|
||||
const deleteBtn = row.getByRole('button', { name: '删除' });
|
||||
await deleteBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: title }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
await confirmBtn.click();
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,47 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class OperationLogPage {
|
||||
readonly page: Page;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly table;
|
||||
readonly exportButton;
|
||||
readonly searchInput: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly table: Locator;
|
||||
|
||||
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: '导出' });
|
||||
this.searchInput = page.getByPlaceholder('搜索操作人/描述');
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.table = page.locator('.ant-table').first();
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到操作日志页面...');
|
||||
await this.page.goto('/oplog');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*oplog/);
|
||||
|
||||
console.log('操作日志页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/operation-log-error-${Date.now()}.png` });
|
||||
console.error('导航到操作日志页面失败:', error);
|
||||
throw new Error(`导航到操作日志页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/oplog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*oplog/);
|
||||
}
|
||||
|
||||
async searchByKeyword(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.searchInput.press('Enter');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.searchInput.press('Enter');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
async reload() {
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async exportData() {
|
||||
await this.exportButton.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,68 +4,34 @@ export class RoleManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createRoleButton: Locator;
|
||||
readonly refreshButton: 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;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
readonly pagination: Locator;
|
||||
readonly nextPageButton: Locator;
|
||||
readonly prevPageButton: 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'));
|
||||
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.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'));
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.createRoleButton = page.getByRole('button', { name: '新增角色' });
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
this.pagination = page.locator('.ant-pagination');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到角色管理页面...');
|
||||
await this.page.goto('/roles');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*roles/);
|
||||
|
||||
console.log('角色管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/role-management-error-${Date.now()}.png` });
|
||||
console.error('导航到角色管理页面失败:', error);
|
||||
throw new Error(`导航到角色管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/roles');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*roles/);
|
||||
}
|
||||
|
||||
async waitForTableReady() {
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
() => document.querySelectorAll('.ant-table-tbody > tr').length > 0,
|
||||
{ timeout: 5000 }
|
||||
).catch(() => {
|
||||
console.log('表格没有数据,继续执行');
|
||||
});
|
||||
).catch(() => {});
|
||||
}
|
||||
|
||||
async clickCreateRole() {
|
||||
@@ -76,176 +42,94 @@ export class RoleManagementPage {
|
||||
async fillRoleForm(roleData: {
|
||||
roleName: string;
|
||||
roleKey: string;
|
||||
roleSort?: string;
|
||||
roleSort?: number;
|
||||
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.roleSort) {
|
||||
const sortInput = this.page.locator('.el-dialog').locator('.el-input-number');
|
||||
if (await sortInput.count() > 0) {
|
||||
const input = sortInput.locator('input');
|
||||
await input.fill(roleData.roleSort);
|
||||
}
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增角色|编辑角色/ });
|
||||
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '角色名称' }).locator('input').fill(roleData.roleName);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '角色标识' }).locator('input').fill(roleData.roleKey);
|
||||
|
||||
if (roleData.roleSort !== undefined) {
|
||||
const sortInput = modal.locator('.ant-form-item').filter({ hasText: '排序' }).locator('.ant-input-number input');
|
||||
await sortInput.clear();
|
||||
await sortInput.fill(String(roleData.roleSort));
|
||||
}
|
||||
|
||||
|
||||
if (roleData.status) {
|
||||
const statusSelect = this.page.locator('.el-dialog').locator('.el-form-item').filter({ hasText: '状态' }).locator('.el-select');
|
||||
if (await statusSelect.count() > 0) {
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const statusText = roleData.status === 'ACTIVE' ? '正常' : '禁用';
|
||||
const dropdown = this.page.locator('.el-select-dropdown');
|
||||
if (await dropdown.count() > 0) {
|
||||
const options = dropdown.locator('.el-select-dropdown__item');
|
||||
const optionCount = await options.count();
|
||||
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await options.nth(i).textContent();
|
||||
if (optionText && optionText.includes(statusText)) {
|
||||
await options.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const statusText = roleData.status === 'ACTIVE' ? '正常' : '禁用';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
|
||||
}
|
||||
|
||||
if (roleData.remark) {
|
||||
await this.page.locator('.el-dialog').locator('textarea').fill(roleData.remark);
|
||||
}
|
||||
|
||||
async selectPermissions(permissionLabels: string[]) {
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增角色|编辑角色/ });
|
||||
const treeSelect = modal.locator('.ant-form-item').filter({ hasText: '权限' }).locator('.ant-tree-select');
|
||||
await treeSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
|
||||
for (const label of permissionLabels) {
|
||||
const checkbox = this.page.locator('.ant-tree-select-dropdown .ant-tree-treenode').filter({ hasText: label }).locator('.ant-tree-checkbox');
|
||||
if (await checkbox.count() > 0 && !(await checkbox.isChecked())) {
|
||||
await checkbox.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const submitButton = dialog.getByRole('button', { name: '确定' }).or(dialog.locator('button:has-text("确定")'));
|
||||
|
||||
await submitButton.click();
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增角色|编辑角色/ });
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async waitForSuccessMessage(timeout: number = 10000): Promise<boolean> {
|
||||
try {
|
||||
const message = this.page.locator('.el-message--success').or(this.page.locator('.el-message'));
|
||||
await message.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log('等待成功消息超时,检查是否有错误消息');
|
||||
|
||||
try {
|
||||
const errorMessage = this.page.locator('.el-message--error').or(this.page.locator('.el-message--warning'));
|
||||
if (await errorMessage.count() > 0) {
|
||||
const errorText = await errorMessage.first().textContent();
|
||||
console.log('发现错误消息:', errorText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('没有发现错误消息');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
async cancelForm() {
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增角色|编辑角色/ });
|
||||
await modal.getByRole('button', { name: /取\s*消/ }).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();
|
||||
const row = this.table.locator('tbody tr').nth(rowNumber - 1);
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
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();
|
||||
const row = this.table.locator('tbody tr').nth(rowNumber - 1);
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
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 cancelDelete() {
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /取\s*消/ }).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> {
|
||||
async waitForSuccessMessage(timeout = 10000): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
await this.successMessage.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getRoleCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
async clickPermissionButton(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 deselectPermission(permissionValue: string) {
|
||||
const checkbox = this.page.locator(`input[type="checkbox"][value="${permissionValue}"]`);
|
||||
if (await checkbox.isChecked()) {
|
||||
await checkbox.click();
|
||||
}
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.fill('');
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async clickStatusButton(rowNumber: number) {
|
||||
const row = this.table.locator(`tbody tr:nth-child(${rowNumber})`);
|
||||
await row.locator('.el-button--text').filter({ hasText: /状态|启用|禁用/ }).first().click();
|
||||
}
|
||||
|
||||
async getCurrentPage(): Promise<string> {
|
||||
try {
|
||||
const activePage = this.page.locator('.el-pager li.is-active');
|
||||
if (await activePage.count() > 0) {
|
||||
return await activePage.textContent() || '1';
|
||||
}
|
||||
|
||||
const currentPage = this.page.locator('.el-pagination__current');
|
||||
if (await currentPage.count() > 0) {
|
||||
return await currentPage.textContent() || '1';
|
||||
}
|
||||
|
||||
return '1';
|
||||
} catch (error) {
|
||||
console.log('获取当前页码失败,返回默认值');
|
||||
return '1';
|
||||
}
|
||||
}
|
||||
|
||||
async nextPage() {
|
||||
await this.nextPageButton.click();
|
||||
}
|
||||
|
||||
async prevPage() {
|
||||
await this.prevPageButton.click();
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +1,81 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class SystemConfigPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly dialog;
|
||||
readonly configNameInput;
|
||||
readonly configKeyInput;
|
||||
readonly configValueInput;
|
||||
readonly table: Locator;
|
||||
readonly addButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.addButton = page.getByRole('button', { name: '新增配置' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.dialog = page.locator('.el-dialog');
|
||||
this.configNameInput = page.locator('.el-dialog').getByRole('textbox', { name: '参数名称' });
|
||||
this.configKeyInput = page.locator('.el-dialog').getByRole('textbox', { name: '参数键名' });
|
||||
this.configValueInput = page.locator('.el-dialog').getByRole('textbox', { name: '参数值' });
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到系统配置页面...');
|
||||
await this.page.goto('/sys/config');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*config/);
|
||||
|
||||
console.log('系统配置页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/system-config-error-${Date.now()}.png` });
|
||||
console.error('导航到系统配置页面失败:', error);
|
||||
throw new Error(`导航到系统配置页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/sys/config');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*config/);
|
||||
}
|
||||
|
||||
async addConfig(configName: string, configKey: string, configValue: string) {
|
||||
async addConfig(configName: string, configKey: string, configValue: string, configType?: string, remark?: string) {
|
||||
await this.addButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.configNameInput.fill(configName);
|
||||
await this.configKeyInput.fill(configKey);
|
||||
await this.configValueInput.fill(configValue);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增配置|编辑配置/ });
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '配置名称' }).locator('input').fill(configName);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '配置键' }).locator('input').fill(configKey);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '配置值' }).locator('input').fill(configValue);
|
||||
|
||||
if (configType) {
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '类型' }).locator('input').fill(configType);
|
||||
}
|
||||
if (remark) {
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '备注' }).locator('textarea').fill(remark);
|
||||
}
|
||||
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async editConfig(configKey: string, newValue: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: configKey }).first();
|
||||
const editBtn = row.getByRole('button', { name: '编辑' });
|
||||
await editBtn.click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: configKey }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.configValueInput.clear();
|
||||
await this.configValueInput.fill(newValue);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增配置|编辑配置/ });
|
||||
const valueInput = modal.locator('.ant-form-item').filter({ hasText: '配置值' }).locator('input');
|
||||
await valueInput.clear();
|
||||
await valueInput.fill(newValue);
|
||||
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async deleteConfig(configKey: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: configKey }).first();
|
||||
const deleteBtn = row.getByRole('button', { name: '删除' });
|
||||
await deleteBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
await confirmBtn.click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: configKey }).first();
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,58 +4,34 @@ export class UserManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createUserButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
readonly pagination: Locator;
|
||||
readonly nextPageButton: Locator;
|
||||
readonly prevPageButton: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
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'));
|
||||
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'));
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.createUserButton = page.getByRole('button', { name: '新增用户' });
|
||||
this.refreshButton = page.getByRole('button', { name: '刷新' });
|
||||
this.successMessage = page.locator('.ant-message-success');
|
||||
this.errorMessage = page.locator('.ant-message-error');
|
||||
this.pagination = page.locator('.ant-pagination');
|
||||
}
|
||||
|
||||
async goto() {
|
||||
try {
|
||||
console.log('导航到用户管理页面...');
|
||||
await this.page.goto('/users');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await expect(this.page).toHaveURL(/.*users/);
|
||||
|
||||
console.log('用户管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/user-management-error-${Date.now()}.png` });
|
||||
|
||||
console.error('导航到用户管理页面失败:', error);
|
||||
|
||||
throw new Error(`导航到用户管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/users');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*users/);
|
||||
}
|
||||
|
||||
async waitForTableReady() {
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
|
||||
await this.page.waitForFunction(
|
||||
() => {
|
||||
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
||||
return rows.length > 0;
|
||||
},
|
||||
() => document.querySelectorAll('.ant-table-tbody > tr').length > 0,
|
||||
{ timeout: 5000 }
|
||||
).catch(() => {
|
||||
console.log('表格没有数据,继续执行');
|
||||
});
|
||||
).catch(() => {});
|
||||
}
|
||||
|
||||
async clickCreateUser() {
|
||||
@@ -64,233 +40,97 @@ export class UserManagementPage {
|
||||
}
|
||||
|
||||
async fillUserForm(userData: {
|
||||
username: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
nickname?: string;
|
||||
email: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
password: string;
|
||||
confirmPassword?: string;
|
||||
status?: string;
|
||||
}) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const isCreateMode = !userData.hasOwnProperty('id');
|
||||
|
||||
// 表单字段顺序:
|
||||
// 创建模式:用户名(0), 密码(1), 昵称(2), 邮箱(3), 手机号(4)
|
||||
// 编辑模式:用户名(0), 昵称(1), 邮箱(2), 手机号(3)
|
||||
|
||||
await dialog.locator('input').first().fill(userData.username);
|
||||
|
||||
if (isCreateMode && userData.password) {
|
||||
await dialog.locator('input[type="password"]').fill(userData.password);
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增用户|编辑用户/ });
|
||||
|
||||
if (userData.username) {
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '用户名' }).locator('input').fill(userData.username);
|
||||
}
|
||||
if (userData.password) {
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '密码' }).locator('input[type="password"]').fill(userData.password);
|
||||
}
|
||||
|
||||
if (userData.nickname) {
|
||||
const nicknameIndex = isCreateMode ? 2 : 1;
|
||||
await dialog.locator('input').nth(nicknameIndex).fill(userData.nickname);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '昵称' }).locator('input').fill(userData.nickname);
|
||||
}
|
||||
|
||||
if (userData.email) {
|
||||
const emailIndex = isCreateMode ? 3 : 2;
|
||||
await dialog.locator('input').nth(emailIndex).fill(userData.email);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '邮箱' }).locator('input').fill(userData.email);
|
||||
}
|
||||
|
||||
if (userData.phone) {
|
||||
const phoneIndex = isCreateMode ? 4 : 3;
|
||||
await dialog.locator('input').nth(phoneIndex).fill(userData.phone);
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '手机' }).locator('input').fill(userData.phone);
|
||||
}
|
||||
|
||||
if (userData.status) {
|
||||
const statusSelect = dialog.locator('.el-form-item').filter({ hasText: '状态' }).locator('.el-select');
|
||||
if (await statusSelect.count() > 0) {
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const statusText = userData.status === '1' || userData.status === 'ACTIVE' ? '正常' : '禁用';
|
||||
const dropdown = this.page.locator('.el-select-dropdown');
|
||||
if (await dropdown.count() > 0) {
|
||||
const options = dropdown.locator('.el-select-dropdown__item');
|
||||
const optionCount = await options.count();
|
||||
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await options.nth(i).textContent();
|
||||
if (optionText && optionText.includes(statusText)) {
|
||||
await options.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const statusFormItem = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
|
||||
if (await statusFormItem.count() > 0) {
|
||||
await statusFormItem.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const statusText = userData.status === 'ACTIVE' ? '正常' : '禁用';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const submitButton = dialog.getByRole('button', { name: '确定' }).or(dialog.locator('button:has-text("确定")'));
|
||||
|
||||
await submitButton.click();
|
||||
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增用户|编辑用户/ });
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async waitForSuccessMessage(timeout: number = 10000): Promise<boolean> {
|
||||
try {
|
||||
const message = this.page.locator('.el-message--success').or(this.page.locator('.el-message'));
|
||||
await message.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log('等待成功消息超时,检查是否有错误消息');
|
||||
|
||||
try {
|
||||
const errorMessage = this.page.locator('.el-message--error').or(this.page.locator('.el-message--warning'));
|
||||
if (await errorMessage.count() > 0) {
|
||||
const errorText = await errorMessage.first().textContent();
|
||||
console.log('发现错误消息:', errorText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('没有发现错误消息');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
async cancelForm() {
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增用户|编辑用户/ });
|
||||
await modal.getByRole('button', { name: /取\s*消/ }).click();
|
||||
}
|
||||
|
||||
async editUser(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();
|
||||
const row = this.table.locator('tbody tr').nth(rowNumber - 1);
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async deleteUser(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();
|
||||
const row = this.table.locator('tbody tr').nth(rowNumber - 1);
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
async cancelDelete() {
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /取\s*消/ }).click();
|
||||
}
|
||||
|
||||
async nextPage() {
|
||||
await this.nextPageButton.click();
|
||||
}
|
||||
|
||||
async prevPage() {
|
||||
await this.prevPageButton.click();
|
||||
}
|
||||
|
||||
async getCurrentPage(): Promise<string> {
|
||||
async waitForSuccessMessage(timeout = 10000): Promise<boolean> {
|
||||
try {
|
||||
const activePage = this.page.locator('.el-pager li.is-active');
|
||||
if (await activePage.count() > 0) {
|
||||
return await activePage.textContent() || '1';
|
||||
}
|
||||
|
||||
const currentPage = this.page.locator('.el-pagination__current');
|
||||
if (await currentPage.count() > 0) {
|
||||
return await currentPage.textContent() || '1';
|
||||
}
|
||||
|
||||
return '1';
|
||||
} catch (error) {
|
||||
console.log('获取当前页码失败,返回默认值');
|
||||
return '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 });
|
||||
await this.successMessage.waitFor({ state: 'visible', timeout });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getUserCount(): Promise<number> {
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async getTableCellText(rowNumber: number, colIndex: number): Promise<string | null> {
|
||||
const row = this.table.locator('tbody tr').nth(rowNumber - 1);
|
||||
return row.locator('td').nth(colIndex).textContent();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.page.reload();
|
||||
}
|
||||
|
||||
async clickStatusButton(rowNumber: number) {
|
||||
const row = this.table.locator(`tbody tr:nth-child(${rowNumber})`);
|
||||
await row.locator('.el-tag').first().click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const dropdown = this.page.locator('.el-dropdown');
|
||||
if (await dropdown.count() > 0) {
|
||||
const options = dropdown.locator('.el-dropdown-menu__item');
|
||||
const optionCount = await options.count();
|
||||
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await options.nth(i).textContent();
|
||||
if (optionText && (optionText.includes('启用') || optionText.includes('禁用'))) {
|
||||
await options.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
async clickEditButton(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 clickDeleteButton(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 fillNickname(nickname: string) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
await dialog.locator('input').nth(1).fill(nickname);
|
||||
}
|
||||
|
||||
async selectRole(roleName: string) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
const roleSelect = dialog.locator('.el-select');
|
||||
if (await roleSelect.count() > 0) {
|
||||
await roleSelect.first().click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const dropdown = this.page.locator('.el-select-dropdown');
|
||||
if (await dropdown.count() > 0) {
|
||||
const options = dropdown.locator('.el-select-dropdown__item');
|
||||
const optionCount = await options.count();
|
||||
|
||||
for (let i = 0; i < optionCount; i++) {
|
||||
const optionText = await options.nth(i).textContent();
|
||||
if (optionText && optionText.includes(roleName)) {
|
||||
await options.nth(i).click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.fill('');
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user