DigitalConsumer.FixMyGlass/playwright-tests/pages/CCPolicyInfoPage.ts
maguire-arman 92c223487a Updating 836 with 631
Adds a new environment variable to skip content site checks, improving test environment flexibility.
Improves the "nextPage" function in BasePage to handle loader elements and button states more reliably.
Adds support for selecting loss location in CCPolicyInfoPage to reflect claim details accurately.
Updates assertion methods to use Soft assertions for smoother test execution.
Adds a new test case "InsuranceMeemicNearSchoolVerified" to expand test coverage.
2025-07-08 14:59:48 -04:00

88 lines
No EOL
3.6 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { IClaimDetails, ICustomerDetails } from 'safelite-playwright-core';
import { InsuranceBasePage } from './InsuranceBasePage';
import { STATE_ABBREVIATIONS } from 'safelite-playwright-core';
import { ITestData } from 'framework/TestData';
import { step } from 'framework/localTypes/Step';
export class CCPolicyInfoPage extends InsuranceBasePage {
readonly policyNumber: Locator;
readonly policyZip: Locator;
readonly damageDate: Locator;
readonly damageCause: Locator;
readonly phoneNumber: Locator;
readonly city: Locator;
readonly state: Locator;
readonly hasAdditionalDamage: Locator;
readonly isRentalVehicle: Locator;
readonly isOtherPartyResponsibleForCoverage: Locator;
readonly lossLocation: Locator;
url = `${process.env['BASE_URL']!}/FixMyGlass/CCPolicyInfo.aspx*`;
constructor(page: Page) {
super(page);
this.policyNumber = page.locator('#PolicyNumber');
this.policyZip = page.locator('#PolicyZip');
this.damageDate = page.locator('#LossDate');
this.damageCause = page.locator('#LossCause');
this.phoneNumber = page.locator('#PrimaryPhone');
this.city = page.locator('#LossLocCity');
this.state = page.locator('#LossLocState');
this.hasAdditionalDamage = page.locator('#HasAdditionalDamage');
this.isRentalVehicle = page.locator('#IsRentalVehicle');
this.isOtherPartyResponsibleForCoverage = page.locator('#IsOtherPartyResponsibleForCoverage');
this.lossLocation = page.locator('#LossLocationType');
}
async hasCityInfo(): Promise<boolean> {
await expect.soft(this.damageCause).toBeVisible();
return this.city.isVisible();
}
private getStateAbbreviation(stateName: string): string {
const abbreviation = STATE_ABBREVIATIONS[stateName];
if (!abbreviation) {
throw new Error(`State "${stateName}" not found in mapping`);
}
return abbreviation;
}
async populatePage(customerDetails: ICustomerDetails, claimDetails: IClaimDetails, isFillCityInfo: boolean): Promise<void> {
try {
await this.policyNumber.fill(claimDetails.policyNumber);
await this.policyZip.fill(claimDetails.policyZip || customerDetails.address.postalCode);
await this.damageDate.click();
await this.damageDate.fill(claimDetails.damageDate);
await this.damageCause.selectOption(claimDetails.damageCause);
await this.damageCause.press('Tab');
await this.phoneNumber.fill(customerDetails.phoneNumber);
if (isFillCityInfo) {
await this.city.fill(customerDetails.address.city);
}
if (await this.state.isVisible()) {
const stateAbbreviation = this.getStateAbbreviation(customerDetails.address.state);
await this.state.selectOption({ value: stateAbbreviation });
}
if (claimDetails.lossLocation) {
await this.lossLocation.selectOption(claimDetails.lossLocation);
}
} catch (error) {
console.error('Error populating policy info page:', error);
throw error;
}
}
@step("CCPolicyInfoPage >> Fill out claim information")
async handleCCPolicyInfoPage(testData: Partial<ITestData>) {
const { customerDetails, claimDetails} = testData;
await this.populatePage(customerDetails!, claimDetails!, await this.hasCityInfo());
await this.nextPage();
}
}