import { expect, Page } from '@playwright/test'; import { ReviewAndCheckoutPage } from "../pages/reviewAndCheckoutPage"; import {DateOperations} from "../../utils/dateOperations"; import {PageBase} from "../../utils/page-base"; export class ReviewAndCheckoutPageStepDefs extends PageBase { constructor(page: Page) { super(page); } async assertLicenseName(productLicenseName: string): Promise { await this.page.waitForLoadState() await this.waitForElement(ReviewAndCheckoutPage.productName) await expect(this.page.locator(ReviewAndCheckoutPage.productName)).toHaveText(productLicenseName); } async assertIpAddress(ipAddress: string): Promise { await this.waitForElement(ReviewAndCheckoutPage.productName) await expect(this.page.locator(ReviewAndCheckoutPage.ipAddress)).toHaveText("ยป IP Address: " + ipAddress); } async assertProductMonthlyPrice(productMonthlyPrice: string): Promise { await expect(this.page.locator(ReviewAndCheckoutPage.productMonthlyPrice)).toHaveText(productMonthlyPrice+ " Monthly"); } async assertAddonMonthlyPrice(addonMonthlyPrice: string): Promise { await expect(this.page.locator(ReviewAndCheckoutPage.addonMonthlyPrice)).toHaveText(addonMonthlyPrice + " Monthly"); } async assertTotalDue(): Promise { const productTotalDue = await DateOperations.extractPrice(this.page, ReviewAndCheckoutPage.productMonthlyPrice).then(DateOperations.calculateTotalDue); const addonTotalDue = await DateOperations.extractPrice(this.page, ReviewAndCheckoutPage.addonMonthlyPrice).then(DateOperations.calculateTotalDue); console.log(`Product Monthly Price: ${productTotalDue}`); console.log(`Addon Monthly Price: ${addonTotalDue}`); const expectedTotalDueToday = productTotalDue + addonTotalDue; const actualTotalDue = await DateOperations.extractPrice(this.page, ReviewAndCheckoutPage.totalDueToday) expect(expectedTotalDueToday).toBeCloseTo(actualTotalDue, 2); } async clickOnCheckout(): Promise { await this.page.click(ReviewAndCheckoutPage.checkoutButton) } }