47 lines
1.5 KiB
TypeScript
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();
|
|
}
|
|
}
|