import { Page, expect } from '@playwright/test'; export class LoginPage { readonly page: Page; constructor(page: Page) { this.page = page; } async goto() { await this.page.goto('/'); await this.page.waitForLoadState('domcontentloaded'); } async login(username: string, password: string) { await this.page.fill('input[placeholder*="用户名"], input[placeholder*="账号"]', username); await this.page.fill('input[placeholder*="密码"]', password); await this.page.click('button:has-text("登录")'); await this.page.waitForLoadState('networkidle'); } async expectLoginSuccess() { await expect(this.page).toHaveURL(/.*(dashboard|home|index).*/, { timeout: 15000 }); } async expectLoginFailed() { await expect(this.page.locator('.el-message--error')).toBeVisible({ timeout: 5000 }); } async expectOnLoginPage() { await expect(this.page.locator('input[placeholder*="用户名"], input[placeholder*="账号"]')).toBeVisible(); } }