Files
novalon-manage-system/novalon-manage-web/e2e/pages/SystemConfigPage.ts
T
张翔 ba9cdb4b6f fix: optimize all Page Object navigation with better error handling
- MenuManagementPage: add tree/table wait and error handling
- SystemConfigPage: add table wait and error handling
- DictionaryManagementPage: add table wait and error handling
- FileManagementPage: add table wait and error handling
- OperationLogPage: add table wait and error handling
- LoginLogPage: add table wait and error handling
- ExceptionLogPage: add table wait and error handling
2026-04-04 09:06:01 +08:00

105 lines
3.6 KiB
TypeScript

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() {
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)}`);
}
}
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;
}
}