import { Page, Locator, expect } from '@playwright/test'; export class RegisterPage { readonly page: Page; readonly usernameInput: Locator; readonly passwordInput: Locator; readonly confirmPasswordInput: Locator; readonly registerButton: Locator; readonly loginLink: Locator; readonly errorMessage: Locator; constructor(page: Page) { this.page = page; this.usernameInput = page.getByPlaceholder('请输入用户名'); this.passwordInput = page.getByPlaceholder('请输入密码'); this.confirmPasswordInput = page.getByPlaceholder('请再次输入密码'); this.registerButton = page.getByRole('button', { name: '注册账号' }); this.loginLink = page.getByRole('link', { name: '立即登录' }); this.errorMessage = page.locator('[data-sonner-toast]'); } async goto() { await this.page.goto('/register'); await this.page.waitForLoadState('networkidle'); } async register(username: string, password: string, confirmPassword?: string) { await this.usernameInput.fill(username); await this.passwordInput.fill(password); await this.confirmPasswordInput.fill(confirmPassword || password); await this.registerButton.click(); } async expectRegistrationSuccess() { await expect(this.page).toHaveURL('/'); await expect(this.page.locator('text=注册成功')).toBeVisible(); } async expectRegistrationError() { await expect(this.errorMessage).toBeVisible(); } async navigateToLogin() { await this.loginLink.click(); } }