DigitalConsumer.ISS/playwright-tests/pages/PaymentMethodPage.ts
chase-safelite 5d3ab0ef59
Added playwright tests into repo (#923)
* Initial import of playwright tests

* Pipeline changes for automated tests

* Modified pipeline for testing

* Attempt #2

* Attempt #3

* Added missing paren

* Removed debug stuff from pipeline

* Changes from playwright repo

* Changed pipeline for debugging

* Fix for ServiceLocationPage playwright locators

* Change pipeline to run with TEST APIs

* Moved more of Siraj's changes to this repo

* Changed where updating env occurs

* Changed location of env update again

* Escaped double quotes

* Added visible report in Azure

* Moved changes into main pipeline

* Made it so dotenv only runs config in local
2025-02-14 09:54:11 -05:00

82 lines
No EOL
3.1 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { IPaymentDetails } from '@business-logic/types/CustomerDetails';
import { PaymentType } from '@business-logic/types/Enums';
import { PaymentPage } from './PaymentPage';
import { AfterpayPage } from './AfterpayPage';
import { PaypalPage } from './PaypalPage';
export class PaymentMethodPage extends BasePage {
readonly page: Page;
readonly payAtServiceButton: Locator;
readonly payNowButton: Locator;
readonly payInFourButton: Locator;
readonly paypalButton: Locator;
readonly paymentPage: PaymentPage;
readonly paypalPage: PaypalPage;
url = process.env['BASE_URL']! + '/?issPage=payment-method';
constructor(page: Page) {
super(page);
this.page = page;
this.payAtServiceButton = this.page.locator('[buttonlabel="Pay at my appointment"]'); //this.page.getByText('Pay at time of service');
this.payNowButton = this.page.locator('[buttonlabel="Pay now"]');
this.payInFourButton = this.page.locator('[buttonlabel="Pay in 4 installments"]');
this.paypalButton = this.page.frameLocator('iframe[name="card-frame"]').locator('div[id="paypalParentDiv"]');
this.paymentPage = new PaymentPage(page);
this.paypalPage = new PaypalPage(page);
}
async executePayment(paymentDetails: IPaymentDetails) {
const browserContext = this.page.context();
switch (paymentDetails.paymentType) {
case PaymentType.Credit:
await this.selectCreditCard();
await this.paymentPage.populateCreditCardDetails(paymentDetails);
break;
case PaymentType.Paypal:
await this.selectPaypal();
await this.paypalPage.completePaypalPurchase(paymentDetails);
break;
case PaymentType.AfterPay:
await this.payInFourButton.click();
await this.nextPage();
// Capture popup
const afterpayPopup = await browserContext.waitForEvent('page');
const afterpayPage = new AfterpayPage(afterpayPopup);
// Execute payment
await afterpayPage.executeAfterpayPayment(paymentDetails);
break;
case PaymentType.PayAtService:
await this.selectPayAtService();
break;
default:
console.error('PaymentMethodPage >> Logic for this payment method unimplemented');
break;
}
}
async selectPaypal() {
await this.payNowButton.click();
await this.nextPage();
await this.paypalButton.click();
}
async selectCreditCard() {
await this.payNowButton.click();
await this.nextPage();
}
async selectPayAtService() {
await this.payAtServiceButton.click();
}
// async validateAmountDue(customer){
// await this.amountDueDropDown.click();
// await expect(this.deductibleAmountTextField).toContainText(`${customer.deductibleAmount}`);
// }
}