DigitalConsumer.FixMyGlass/playwright-tests/pages/PaymentPage.ts
2025-06-17 12:15:04 -04:00

51 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;
url = process.env['BASE_URL']! + '/fmg/?fmgPage=payment';
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');
// this.validateURL(this.url);
}
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();
}
}