DigitalConsumer.FixMyGlass/playwright-tests/pages/PaymentPage.ts
maguire-arman 458e552d6b Removes URL declaration from page classes
Removes the explicit URL declaration from the page classes.

The URL validation and navigation are now handled directly within the tests, providing greater flexibility and control over test execution and removing the need to manage URLs within each page object.
2025-07-14 16:13:56 -04:00

50 lines
No EOL
2.8 KiB
TypeScript

import { type Locator, type Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { IPaymentDetails } from 'safelite-playwright-core';
export class PaymentPage extends BasePage {
readonly page: Page;
readonly cardNumberTextField: Locator;
readonly expirationMonthDropDown: Locator;
readonly expirationYearDropDown: Locator;
readonly cvvTextField: Locator;
readonly billingAddressTextField: Locator;
readonly cityTextField: Locator;
readonly stateDropDown: Locator;
readonly billingZipTextField: Locator;
readonly submitPaymentButton: Locator;
readonly payPalButton: Locator;
constructor(page: Page) {
super(page);
this.page = page;
this.cardNumberTextField = page.frameLocator('iframe[name="card-frame"]').getByLabel('Card number*');
this.expirationMonthDropDown = page.frameLocator('iframe[name="card-frame"]').getByRole('combobox', { name: 'Expiration month' });
this.expirationYearDropDown = page.frameLocator('iframe[name="card-frame"]').getByRole('combobox', { name: 'Expiration year' });
this.cvvTextField = page.frameLocator('iframe[name="card-frame"]').getByRole('textbox', { name: 'CVV' });
this.billingAddressTextField = page.frameLocator('iframe[name="card-frame"]').getByRole('textbox', { name: 'Billing address' });
this.cityTextField = page.frameLocator('iframe[name="card-frame"]').getByRole('textbox', { name: 'City' });
this.stateDropDown = page.frameLocator('iframe[name="card-frame"]').getByRole('combobox', { name: 'State' });
this.billingZipTextField = page.frameLocator('iframe[name="card-frame"]').getByRole('textbox', { name: 'Billing ZIP code' });;
this.submitPaymentButton = page.frameLocator('iframe[name="card-frame"]').locator('#buttonContainer');
this.payPalButton = page.frameLocator('iframe[name="card-frame"]').locator('#paypalParentLink');
}
async populateCreditCardDetails(paymentDetails: IPaymentDetails){
await this.cardNumberTextField.fill(paymentDetails.cardNumber || '');
await this.expirationMonthDropDown.selectOption(paymentDetails.expirationMonth!);
await this.expirationYearDropDown.selectOption(paymentDetails.expirationYear!);
await this.cvvTextField.fill(paymentDetails.cvv!);
await this.billingAddressTextField.fill(paymentDetails.billingAddress!.street);
await this.cityTextField.fill(paymentDetails.billingAddress!.city);
await this.stateDropDown.selectOption(paymentDetails.billingAddress!.state);
await this.billingZipTextField.fill(paymentDetails.billingAddress!.postalCode);
await this.submitPaymentButton.click();
}
async navigateToPaypalCheckout() {
await this.payPalButton.click();
}
}