import { Page, expect } from '@playwright/test'; export class LoginPage { readonly page: Page; // Selectors private readonly usernameInput = '#user_login'; private readonly passwordInput = '#user_pass'; private readonly loginButton = '#wp-submit'; private readonly rememberMeCheckbox = '#rememberme'; private readonly errorMessage = '.login-error'; private readonly resetPasswordLink = 'a[href*="lost-password"]'; private readonly logoutLink = 'a[href*="logout"]'; constructor(page: Page) { this.page = page; } async goto() { await this.page.goto('/wp-login.php'); } async login(username: string, password: string, rememberMe = false) { await this.page.fill(this.usernameInput, username); await this.page.fill(this.passwordInput, password); if (rememberMe) { await this.page.check(this.rememberMeCheckbox); } await this.page.click(this.loginButton); } async logout() { await this.page.click(this.logoutLink); // Verify we're back at the login page await expect(this.page).toHaveURL(/.*wp-login.php/); } async initiatePasswordReset(username: string) { await this.page.click(this.resetPasswordLink); await this.page.fill('#user_login', username); await this.page.click('input[value="Get New Password"]'); } async getErrorMessage() { const error = await this.page.locator(this.errorMessage); return error.textContent(); } async isLoggedIn() { return await this.page.locator('body.logged-in').isVisible(); } async isRememberMeChecked() { const checkbox = await this.page.locator(this.rememberMeCheckbox); return await checkbox.isChecked(); } }