test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名 - 新增 UAT 测试套件与 journey 测试用例 - 优化测试辅助工具与数据工厂 - 更新 playwright 认证状态
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user