- Updated configuration files and documentation to use new staging domain - Created centralized URL configuration for tests - Updated page objects to use configuration instead of hardcoded URLs - Added script to automatically update test files with new domain 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
No EOL
2.5 KiB
TypeScript
92 lines
No EOL
2.5 KiB
TypeScript
import { Page, expect } from '@playwright/test';
|
|
import { BasePage } from './BasePage';
|
|
import { PATHS } from '../config/staging-config';
|
|
|
|
/**
|
|
* Page object representing the login page
|
|
*/
|
|
export class LoginPage extends BasePage {
|
|
// Login form elements
|
|
private readonly usernameInput = '#user_login';
|
|
private readonly passwordInput = '#user_pass';
|
|
private readonly loginButton = '#wp-submit';
|
|
private readonly rememberMeCheckbox = '#rememberme';
|
|
private readonly loginError = '.login-error, .login_error';
|
|
private readonly forgotPasswordLink = 'a.forgot-password, a:text("Lost your password?")';
|
|
|
|
constructor(page: Page) {
|
|
super(page);
|
|
}
|
|
|
|
/**
|
|
* Navigate to the login page
|
|
*/
|
|
async navigate(): Promise<void> {
|
|
await this.page.goto(PATHS.login);
|
|
await this.page.waitForSelector(this.usernameInput);
|
|
}
|
|
|
|
/**
|
|
* Alternative name for navigate for backward compatibility
|
|
*/
|
|
async navigateToLogin(): Promise<void> {
|
|
await this.navigate();
|
|
}
|
|
|
|
/**
|
|
* Login with provided credentials
|
|
* @param username Username or email
|
|
* @param password Password
|
|
*/
|
|
async login(username: string, password: string): Promise<void> {
|
|
this.log(`Logging in as ${username}`);
|
|
await this.page.fill(this.usernameInput, username);
|
|
await this.page.fill(this.passwordInput, password);
|
|
await this.page.click(this.loginButton);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
/**
|
|
* Check if we're logged in
|
|
*/
|
|
async isLoggedIn(): Promise<boolean> {
|
|
const url = await this.getUrl();
|
|
return url.includes('hvac-dashboard');
|
|
}
|
|
|
|
/**
|
|
* Check if username field is visible
|
|
*/
|
|
async isUsernameFieldVisible(): Promise<boolean> {
|
|
return await this.page.isVisible(this.usernameInput);
|
|
}
|
|
|
|
/**
|
|
* Get error message if login failed
|
|
*/
|
|
async getErrorMessage(): Promise<string | null> {
|
|
if (await this.page.isVisible(this.loginError)) {
|
|
return await this.page.textContent(this.loginError);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Click on "forgot password" link
|
|
*/
|
|
async clickForgotPassword(): Promise<void> {
|
|
await this.page.click(this.forgotPasswordLink);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
/**
|
|
* Toggle "remember me" checkbox
|
|
* @param check If true, check the box; if false, uncheck it
|
|
*/
|
|
async setRememberMe(check: boolean): Promise<void> {
|
|
const isChecked = await this.page.isChecked(this.rememberMeCheckbox);
|
|
if (check !== isChecked) {
|
|
await this.page.click(this.rememberMeCheckbox);
|
|
}
|
|
}
|
|
} |