37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { Page, Locator, expect } from "@playwright/test";
|
|
|
|
export class LoginPage {
|
|
readonly page: Page;
|
|
readonly emailInput: Locator;
|
|
readonly passwordInput: Locator;
|
|
readonly submitButton: Locator;
|
|
readonly errorMessage: Locator;
|
|
readonly forgotPasswordLink: Locator;
|
|
readonly registerLink: Locator;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
this.emailInput = page.locator("#email");
|
|
this.passwordInput = page.locator("#password");
|
|
this.submitButton = page.getByRole("button", { name: /登录/ });
|
|
this.errorMessage = page.locator(".text-destructive");
|
|
this.forgotPasswordLink = page.getByRole("link", { name: "忘记密码?" });
|
|
this.registerLink = page.getByRole("link", { name: "立即注册" });
|
|
}
|
|
|
|
async goto() {
|
|
await this.page.goto("/login");
|
|
await this.page.waitForLoadState("domcontentloaded");
|
|
}
|
|
|
|
async login(email: string, password: string) {
|
|
await this.emailInput.fill(email);
|
|
await this.passwordInput.fill(password);
|
|
await this.submitButton.click();
|
|
}
|
|
|
|
async expectErrorMessage(text: string) {
|
|
await expect(this.errorMessage).toContainText(text);
|
|
}
|
|
}
|