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