DigitalConsumer.FixMyGlass/playwright-tests/pages/PaypalPage.ts
maguire-arman 5c92fe8322 Adapts PayPal login flow for different scenarios
Adjusts the PayPal purchase completion logic to handle cases where the "Log in with password" option is immediately visible or requires an initial login step with email.

This ensures a more robust and reliable payment process across different PayPal configurations.
2025-05-20 10:06:03 -04:00

48 lines
2.2 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { IPaymentDetails } from '@business-logic/types/CustomerDetails';
export class PaypalPage extends BasePage {
readonly page: Page;
readonly loginWithPasswordButton: Locator;
readonly usernameTextBox: Locator;
readonly nextButton: Locator;
readonly usePasswordInsteadButton: Locator;
readonly passwordTextBox: Locator;
readonly paypalLoginButton: Locator;
readonly completePurchaseButton: Locator;
readonly payButton: Locator;
constructor(page: Page) {
super(page);
this.page = page;
this.usernameTextBox = page.getByPlaceholder('Email');
this.nextButton = page.getByRole('button', { name: 'Next' });
this.loginWithPasswordButton = page.getByRole('link', { name: 'Log in with a password instead' })
this.usePasswordInsteadButton = page.getByRole('button', { name: 'Use Password Instead' });
this.passwordTextBox = page.getByPlaceholder('Password');
this.paypalLoginButton = page.getByRole('button', { name: 'Log In', exact: true });
this.completePurchaseButton = page.getByTestId('submit-button-initial')
this.payButton = page.getByRole('button', { name: 'Pay $' });
}
async completePaypalPurchase(paymentDetails: IPaymentDetails){
// Wait for the PayPal login page to load
await this.page.waitForFunction(() => window.location.href.includes('sandbox.paypal.com'), null, { timeout: 10000 });
// handle flow with and without the "Log in with a password instead" link
if (await this.loginWithPasswordButton.isVisible()) {
await this.loginWithPasswordButton.click();
await this.passwordTextBox.fill(paymentDetails.password!);
await this.paypalLoginButton.click();
await this.completePurchaseButton.click();
} else {
await this.usernameTextBox.fill(paymentDetails.username!);
await this.nextButton.click();
await this.usePasswordInsteadButton.click();
await this.passwordTextBox.fill(paymentDetails.password!);
await this.paypalLoginButton.click();
await this.payButton.click();
}
}
}