Files
his/openhis-ui-vue3/tests/e2e/pages/LoginPage.ts
zhangfei bbd9d48fa6 test: Playwright E2E测试12个用例全部通过!
- 修复登录按钮选择器:'登 录'(带空格)
- 修复placeholder:'账号'/'密码'
- 修复登录失败检测逻辑
- 12/12用例通过,耗时16.9秒
- 覆盖:登录4场景 + Bug回归3个(#437/#443/#427) + 手术计费2个 + 医生站2个 + 并发1个
2026-04-25 22:33:53 +08:00

47 lines
1.5 KiB
TypeScript

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) {
// Actual placeholders from login.vue: "账号" and "密码"
await this.page.fill('input[placeholder="账号"]', username);
await this.page.fill('input[placeholder="密码"]', password);
// Check for tenant selection if exists
const tenantSelect = this.page.locator('.el-select__wrapper, input[placeholder="请选择医疗机构"]').first();
if (await tenantSelect.isVisible().catch(() => false)) {
await tenantSelect.click();
await this.page.waitForTimeout(500);
// Select first option
const firstOption = this.page.locator('.el-select-dropdown__item, .el-option').first();
if (await firstOption.isVisible().catch(() => false)) {
await firstOption.click();
await this.page.waitForTimeout(500);
}
}
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="账号"]')).toBeVisible();
}
}