fix(e2e): 修复用户管理测试按钮选择器超时问题

- 优化按钮选择器使用locator API
- 增加页面加载等待时间
- 添加错误处理和日志

任务 1/4
This commit is contained in:
2026-04-11 23:54:24 +08:00
parent 0f098d00d1
commit a96ef304f3
+17 -7
View File
@@ -8,27 +8,37 @@ export interface UserData {
} }
export class AdminUserPage { export class AdminUserPage {
constructor(private page: Page) {} constructor(private page: Page) { }
async goto() { async goto() {
await this.page.goto('/admin/users'); await this.page.goto('/admin/users');
await this.page.waitForLoadState('networkidle'); await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForSelector('table', { timeout: 10000, state: 'visible' });
} }
async createUser(data: UserData) { async createUser(data: UserData) {
await this.page.click('button:has-text("新建用户")'); await this.goto();
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForTimeout(1000);
const addButton = this.page.locator('button:has-text("添加用户")');
await addButton.waitFor({ timeout: 10000, state: 'visible' });
await addButton.click();
await this.page.waitForSelector('input[name="email"]', { timeout: 5000, state: 'visible' });
await this.page.fill('input[name="email"]', data.email); await this.page.fill('input[name="email"]', data.email);
await this.page.fill('input[name="password"]', data.password); await this.page.fill('input[name="password"]', data.password);
if (data.name) { if (data.name) {
await this.page.fill('input[name="name"]', data.name); await this.page.fill('input[name="name"]', data.name);
} }
if (data.role) { if (data.role) {
await this.page.selectOption('select[name="role"]', data.role); await this.page.selectOption('select[name="role"]', data.role);
} }
await this.page.click('button[type="submit"]'); await this.page.click('button:has-text("创建")');
} }
async expectUserInList(email: string) { async expectUserInList(email: string) {