fix: 修复Playwright页面对象定义错误 + 根目录config

- 修复LoginPage/SurgeryBillingPage/DoctorStationPage中page变量作用域问题
- 新增根目录playwright.config.ts(解决配置加载问题)
- .gitignore添加test-results和report目录排除
This commit is contained in:
2026-04-25 22:14:19 +08:00
parent 305ab15436
commit 34ba7cae6a
6 changed files with 45 additions and 53 deletions

View File

@@ -1,15 +1,7 @@
import { Page, expect } from '@playwright/test';
/**
* 登录页面对象模型 (POM)
*/
export class LoginPage {
readonly page: Page;
readonly usernameInput = page.locator('input[placeholder*="用户名"], input[placeholder*="账号"]');
readonly passwordInput = page.locator('input[placeholder*="密码"]');
readonly loginButton = page.locator('button:has-text("登录"), button[type="submit"]');
readonly errorMessage = page.locator('.el-message--error');
readonly successMessage = page.locator('.el-message--success');
constructor(page: Page) {
this.page = page;
@@ -21,9 +13,9 @@ export class LoginPage {
}
async login(username: string, password: string) {
await this.usernameInput.fill(username);
await this.passwordInput.fill(password);
await this.loginButton.click();
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');
}
@@ -32,10 +24,10 @@ export class LoginPage {
}
async expectLoginFailed() {
await expect(this.errorMessage).toBeVisible({ timeout: 5000 });
await expect(this.page.locator('.el-message--error')).toBeVisible({ timeout: 5000 });
}
async expectOnLoginPage() {
await expect(this.usernameInput).toBeVisible();
await expect(this.page.locator('input[placeholder*="用户名"], input[placeholder*="账号"]')).toBeVisible();
}
}