test: E2E 测试用例更新与新增

- 更新 Page Object 模型适配新字段名
- 新增 UAT 测试套件与 journey 测试用例
- 优化测试辅助工具与数据工厂
- 更新 playwright 认证状态
This commit is contained in:
张翔
2026-05-06 14:17:51 +08:00
committed by zhangxiang
parent 9e635b1483
commit e8f51309e5
47 changed files with 1764 additions and 1226 deletions
+21 -37
View File
@@ -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();
}
}
}