bd21e2d1f7
- 更新 Page Object 模型适配新字段名 - 新增 UAT 测试套件与 journey 测试用例 - 优化测试辅助工具与数据工厂 - 更新 playwright 认证状态
82 lines
3.3 KiB
TypeScript
82 lines
3.3 KiB
TypeScript
import { Page, Locator, expect } from '@playwright/test';
|
|
|
|
export class SystemConfigPage {
|
|
readonly page: Page;
|
|
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('.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() {
|
|
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, configType?: string, remark?: string) {
|
|
await this.addButton.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(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('tbody tr').filter({ hasText: configKey }).first();
|
|
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
|
await this.page.waitForTimeout(500);
|
|
|
|
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('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');
|
|
}
|
|
}
|