51 lines
No EOL
2.9 KiB
TypeScript
51 lines
No EOL
2.9 KiB
TypeScript
import { type Locator, type Page } from '@playwright/test';
|
|
import { BasePage } from './BasePage';
|
|
import { IPaymentDetails } from 'safelite-playwright-core';
|
|
import { PaypalPage } from './PaypalPage';
|
|
|
|
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(): Promise<PaypalPage> {
|
|
await this.payPalButton.click();
|
|
return new PaypalPage(this.page);
|
|
}
|
|
} |