Files
novalon-website/e2e/pages/AdminUserPage.ts
T
张翔 cda168cf60 feat: 创建Page Object Model基础结构
新增文件:
- e2e/pages/AdminLoginPage.ts - 管理员登录页面对象
- e2e/pages/AdminContentPage.ts - 内容管理页面对象
- e2e/pages/AdminUserPage.ts - 用户管理页面对象
- e2e/pages/FrontendNewsPage.ts - 前端新闻页面对象
- e2e/pages/FrontendProductPage.ts - 前端产品页面对象
- e2e/pages/index.ts - 导出索引文件

功能特性:
- 封装页面交互逻辑,减少测试代码重复
- 提供清晰的API接口,提升测试可读性
- 支持内容创建、删除、验证等核心操作
- 统一等待策略,提升测试稳定性
2026-04-09 13:17:37 +08:00

40 lines
1013 B
TypeScript

import { Page, expect } from '@playwright/test';
export interface UserData {
email: string;
password: string;
name?: string;
role?: 'admin' | 'editor' | 'viewer';
}
export class AdminUserPage {
constructor(private page: Page) {}
async goto() {
await this.page.goto('/admin/users');
await this.page.waitForLoadState('networkidle');
}
async createUser(data: UserData) {
await this.page.click('button:has-text("新建用户")');
await this.page.fill('input[name="email"]', data.email);
await this.page.fill('input[name="password"]', data.password);
if (data.name) {
await this.page.fill('input[name="name"]', data.name);
}
if (data.role) {
await this.page.selectOption('select[name="role"]', data.role);
}
await this.page.click('button[type="submit"]');
}
async expectUserInList(email: string) {
await this.goto();
const row = this.page.locator(`tr:has-text("${email}")`);
await expect(row).toBeVisible();
}
}