| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import { Page, Locator, expect } from '@playwright/test';
- export class LoginPage {
- readonly page: Page;
- readonly usernameInput: Locator;
- readonly passwordInput: Locator;
- readonly loginButton: Locator;
- readonly registerLink: Locator;
- readonly errorMessage: Locator;
- constructor(page: Page) {
- this.page = page;
- this.usernameInput = page.getByPlaceholder('请输入用户名');
- this.passwordInput = page.getByPlaceholder('请输入密码');
- this.loginButton = page.getByRole('button', { name: '登录' });
- this.registerLink = page.getByRole('link', { name: '立即注册' });
- this.errorMessage = page.locator('[data-sonner-toast]');
- }
- async goto() {
- await this.page.goto('/login');
- await this.page.waitForLoadState('networkidle');
- }
- async login(username: string, password: string) {
- await this.usernameInput.fill(username);
- await this.passwordInput.fill(password);
- await this.loginButton.click();
- }
- async expectLoginSuccess() {
- await expect(this.page).toHaveURL('/');
- await expect(this.page.locator('text=登录成功')).toBeVisible();
- }
- async expectLoginError() {
- await expect(this.errorMessage).toBeVisible();
- }
- async navigateToRegister() {
- await this.registerLink.click();
- }
- }
|