import { Page } from '@playwright/test'; import { BasePage } from './BasePage'; export class LoginPage extends BasePage { private readonly usernameField = '#username'; private readonly passwordField = '#password'; private readonly loginButton = 'button[type="submit"]'; private readonly rememberMeCheckbox = '#rememberme'; private readonly errorMessage = '.error-message'; private readonly forgotPasswordLink = 'a:has-text("Forgot Password")'; constructor(page: Page) { super(page); } async navigateToLogin(): Promise { await this.navigate('/community-login/'); } async login(username: string, password: string, rememberMe: boolean = false): Promise { await this.fill(this.usernameField, username); await this.fill(this.passwordField, password); if (rememberMe) { await this.click(this.rememberMeCheckbox); } await this.click(this.loginButton); await this.waitForNavigation(); } async getErrorMessage(): Promise { if (await this.isVisible(this.errorMessage)) { return await this.getText(this.errorMessage); } return ''; } async isLoginFormVisible(): Promise { return await this.isVisible(this.usernameField) && await this.isVisible(this.passwordField); } async clickForgotPassword(): Promise { await this.click(this.forgotPasswordLink); } }