pixiu/pages/loginPage.ts
LingandRX 627f423779 feat(login): 更新登录功能并添加环境变量配置
- 在 .env 文件中添加 ACCOUNT 和 PASSWORD 环境变量
- 更新 baseFixture 中的 page.goto 方法,使用 baseURL 配置
- 移除 exportFixture 中未使用的 baseTest
- 在 LoginPage 中添加 tenant 参数以支持多租户登录
- 更新 login.spec 中的测试用例,使用环境变量配置
- 调整 setup.ts 中的登录流程,使用新的登录方法
2025-05-29 21:32:08 +08:00

39 lines
1.5 KiB
TypeScript

import { expect, type Locator, type Page } from "@playwright/test";
export class LoginPage {
readonly page: Page;
readonly login_account: Locator;
readonly login_password: Locator;
readonly login_button: Locator;
readonly login_protocol: Locator;
readonly account_pass_hint: Locator;
readonly account_error_hint: Locator;
readonly first_menu: Locator;
constructor(page: Page) {
this.page = page;
this.login_account = page.getByRole('textbox', { name: '请输入您的手机号码' });
this.login_password = page.getByRole('textbox', { name: '请输入登录密码' });
this.login_button = page.getByRole('button', { name: /登\s录/ });
this.login_protocol = page.locator('#agreement');
this.account_pass_hint = page.locator('.pass_svg');
this.account_error_hint = page.locator('.error_svg');
this.first_menu = page.getByText('概况');
}
async user_login(account: string, password: string, tenant?: string) {
await this.login_account.fill(account);
await this.account_pass_hint.waitFor();
await this.login_password.fill(password);
await this.login_protocol.click();
await this.login_button.click();
if (tenant) {
await this.page.getByText(tenant).click();
}
}
async user_login_success() {
await expect(this.page).toHaveURL(/.*\/frame\/dashboard/);
await expect(this.page.getByText('商城数据')).toBeVisible();
}
}