Removes the explicit URL declaration from the page classes. The URL validation and navigation are now handled directly within the tests, providing greater flexibility and control over test execution and removing the need to manage URLs within each page object.
219 lines
No EOL
12 KiB
TypeScript
219 lines
No EOL
12 KiB
TypeScript
import { type Locator, type Page, expect, test } from '@playwright/test';
|
|
import { BasePage } from './BasePage';
|
|
import { VehicleDamage } from 'safelite-playwright-core';
|
|
import { ProgressBarPercentages } from 'framework/localTypes/Enums';
|
|
import { TestSuccessAlert } from 'safelite-playwright-core';
|
|
import { step } from 'framework/localTypes/Step';
|
|
import { ITestData } from 'framework/TestData';
|
|
|
|
export class VehicleDamagePage extends BasePage {
|
|
readonly page: Page;
|
|
readonly windshieldChkBox: Locator;
|
|
readonly crackButton: Locator;
|
|
readonly chipButton: Locator;
|
|
readonly sideDoorButton: Locator;
|
|
readonly driverSideButton: Locator;
|
|
readonly passengerSideButton: Locator;
|
|
readonly driverQuarterPanelChkBox: Locator;
|
|
readonly driverFrontDoorChkBox: Locator;
|
|
readonly driverBackDoorChkBox: Locator;
|
|
readonly driverSlidingDoorChkBox: Locator;
|
|
readonly driverVentGlassChkBox: Locator;
|
|
readonly passengerQuarterPanelChkBox: Locator;
|
|
readonly passengerFrontDoorChkBox: Locator;
|
|
readonly passengerBackDoorChkBox: Locator;
|
|
readonly passengerVentGlassChkBox: Locator;
|
|
readonly rearWindowChkBox: Locator;
|
|
readonly rearStationaryBttn: Locator;
|
|
readonly rearSlidingGlassBttn: Locator;
|
|
readonly editVehicleLink: Locator;
|
|
readonly singleSplitWindshieldChkBox: Locator;
|
|
readonly driverSplitWindshieldChkBox: Locator;
|
|
readonly passengerSplitWindshieldChkBox: Locator;
|
|
|
|
readonly noReplacementAvailableAlert: Locator;
|
|
readonly bothReplaceRepairAlert: Locator;
|
|
readonly splitWindshieldAlert: Locator;
|
|
|
|
constructor(page: Page) {
|
|
super(page);
|
|
this.page = page;
|
|
this.windshieldChkBox = this.page.locator('[buttonlabel="Windshield"]');
|
|
this.crackButton = this.page.locator('[buttonlabel="Crack"]');
|
|
this.chipButton = this.page.locator('[buttonlabel="Chip(s)"]');
|
|
this.sideDoorButton = this.page.locator('[buttonlabel="Side door"]');
|
|
this.driverSideButton = this.page.locator('[buttonlabel="Driver side"]');
|
|
this.passengerSideButton = this.page.locator('[buttonlabel="Passenger side"]');
|
|
this.driverQuarterPanelChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Quarter panel"]');
|
|
this.driverFrontDoorChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Front door"]');
|
|
this.driverBackDoorChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Back door"]');
|
|
this.driverVentGlassChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Vent glass"]');
|
|
this.driverSlidingDoorChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Sliding door"]');
|
|
this.passengerQuarterPanelChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Quarter panel"]');
|
|
this.passengerFrontDoorChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Front door"]');
|
|
this.passengerVentGlassChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Vent glass"]');
|
|
this.passengerBackDoorChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Back door"]');
|
|
this.rearWindowChkBox = this.page.locator('[buttonlabel="Rear window"]');
|
|
this.singleSplitWindshieldChkBox = this.page.locator('[aria-labelledby="WindshieldReplaceOptions"]').locator('[buttonlabel="Single windshield"]');
|
|
this.driverSplitWindshieldChkBox = this.page.locator('[aria-labelledby="WindshieldReplaceOptions"]').locator('[buttonlabel="Split windshield, driver side"]');
|
|
this.passengerSplitWindshieldChkBox = this.page.locator('[aria-labelledby="WindshieldReplaceOptions"]').locator('[buttonlabel="Split windshield, passenger side"]');
|
|
this.noReplacementAvailableAlert = this.page.locator('.alert-danger.widget-name-NoReplacementAvailableError');
|
|
this.bothReplaceRepairAlert = this.page.locator('div.alert-danger.widget-name-HasReplacementConflict');
|
|
this.splitWindshieldAlert = this.page.locator('.alert-danger.widget-name-SplitSingleConflict');
|
|
this.rearStationaryBttn = this.page.locator('label').filter({ hasText: 'Stationary' });
|
|
this.rearSlidingGlassBttn = this.page.locator('label').filter({ hasText: 'Glass with slider' });
|
|
this.editVehicleLink = this.page.getByRole('link', { name: 'Edit vehicle' });
|
|
}
|
|
|
|
async selectDamage(vehicleDamage: VehicleDamage[]) {
|
|
for (const damage of vehicleDamage) {
|
|
switch(damage) {
|
|
case VehicleDamage.WindshieldOneChip:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectChips('1');
|
|
break;
|
|
case VehicleDamage.WindshieldTwoChips:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectChips('2');
|
|
break;
|
|
case VehicleDamage.WindshieldThreeChips:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectChips('3');
|
|
break;
|
|
case VehicleDamage.WindshieldCrack:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectCrack();
|
|
break;
|
|
case VehicleDamage.SingleSplitWindshield:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectCrack();
|
|
await this.singleSplitWindshieldChkBox.check();
|
|
break;
|
|
case VehicleDamage.DriverSplitWindshield:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectCrack();
|
|
await this.driverSplitWindshieldChkBox.check();
|
|
break;
|
|
case VehicleDamage.PassengerSplitWindshield:
|
|
await this.windshieldChkBox.check();
|
|
await this.selectCrack();
|
|
await this.passengerSplitWindshieldChkBox.check();
|
|
break;
|
|
case VehicleDamage.DriverFrontDoor:
|
|
await this.sideDoorButton.check();
|
|
await this.driverSideButton.check();
|
|
await this.driverFrontDoorChkBox.check();
|
|
break;
|
|
case VehicleDamage.DriverRearDoor:
|
|
await this.sideDoorButton.check();
|
|
await this.driverSideButton.check();
|
|
await this.driverBackDoorChkBox.check();
|
|
break;
|
|
case VehicleDamage.DriverQuarterPanel:
|
|
await this.sideDoorButton.check();
|
|
await this.driverSideButton.check();
|
|
await this.driverQuarterPanelChkBox.check();
|
|
break;
|
|
case VehicleDamage.DriverVentGlass:
|
|
await this.sideDoorButton.check();
|
|
await this.driverSideButton.check();
|
|
await this.driverVentGlassChkBox.check();
|
|
break;
|
|
case VehicleDamage.DriverSlidingDoor:
|
|
await this.sideDoorButton.check();
|
|
await this.driverSideButton.check();
|
|
await this.driverSlidingDoorChkBox.check();
|
|
break;
|
|
case VehicleDamage.PassengerFrontDoor:
|
|
await this.sideDoorButton.check();
|
|
await this.passengerSideButton.check();
|
|
await this.passengerFrontDoorChkBox.check();
|
|
break;
|
|
case VehicleDamage.PassengerRearDoor:
|
|
await this.sideDoorButton.check();
|
|
await this.passengerSideButton.check();
|
|
await this.passengerBackDoorChkBox.check();
|
|
break;
|
|
case VehicleDamage.PassengerQuarterPanel:
|
|
await this.sideDoorButton.check();
|
|
await this.passengerSideButton.check();
|
|
await this.passengerQuarterPanelChkBox.click();
|
|
break;
|
|
case VehicleDamage.PassengerVentGlass:
|
|
await this.sideDoorButton.check();
|
|
await this.passengerSideButton.check();
|
|
await this.passengerVentGlassChkBox.check();
|
|
break;
|
|
case VehicleDamage.RearWindow:
|
|
await this.selectRearWindowDamage();
|
|
if (await this.rearStationaryBttn.isVisible()) {
|
|
await this.rearStationaryBttn.click();
|
|
}
|
|
break;
|
|
case VehicleDamage.RearSliding:
|
|
await this.selectRearWindowDamage();
|
|
if (await this.rearSlidingGlassBttn.isVisible()) {
|
|
await this.rearSlidingGlassBttn.click();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
async selectCrack(){
|
|
await this.crackButton.check();
|
|
}
|
|
|
|
async selectChips(numChips: string){
|
|
await this.chipButton.check();
|
|
await this.page.getByText(numChips, {exact: true}).click();
|
|
}
|
|
|
|
async selectRearWindowDamage(){
|
|
await this.rearWindowChkBox.check();
|
|
}
|
|
|
|
async checkForBothRepairReplaceAlertMessage(): Promise<void> {
|
|
await expect(this.bothReplaceRepairAlert).toBeVisible();
|
|
const alertMessage = await this.bothReplaceRepairAlert.textContent();
|
|
console.log(`Alert encountered: ${alertMessage}`);
|
|
expect(alertMessage).toContain("You'll need to schedule separate appointmentsVehicle service requiring both glass repair and replacement must be scheduled separately, as they're performed by different technicians. Continue scheduling your first service now, and then come back to schedule the second service.")
|
|
}
|
|
|
|
async checkForRepairOnlyAlertMessage(): Promise<void> {
|
|
await expect(this.noReplacementAvailableAlert).toBeVisible();
|
|
const alertMessage = await this.noReplacementAvailableAlert.textContent();
|
|
console.log(`Alert encountered: ${alertMessage}`);
|
|
expect(alertMessage).toContain("Service not availableWe're sorry, but we currently offer only repair service for your vehicle type. Need help with next steps? Call us at800-394-0288.")
|
|
}
|
|
|
|
async checkForSplitWindshieldAlertMessage(): Promise<void> {
|
|
await expect(this.splitWindshieldAlert).toBeVisible();
|
|
const alertMessage = await this.splitWindshieldAlert.textContent();
|
|
console.log(`Alert encountered: ${alertMessage}`);
|
|
expect(alertMessage).toContain("Single-piece or split?Please select just one windshield option: single-piece or split.")
|
|
}
|
|
|
|
@step('VehicleDamagePage >> Select Damage')
|
|
async handleVehicleDamagePage(testData: Partial<ITestData>): Promise<void> {
|
|
const {vehicleDamage} = testData;
|
|
const {isRepairReplace, isRepairOnly, isSplitWindshield} = testData.alertFlags || {};
|
|
|
|
await this.validateProgressBar(ProgressBarPercentages.VehicleDamagePage);
|
|
await this.selectDamage(vehicleDamage!);
|
|
// Handle alert conditions for vehicle damage
|
|
if (isRepairReplace) {
|
|
await this.checkForBothRepairReplaceAlertMessage();
|
|
throw new TestSuccessAlert('Both assertions are met successfully.');
|
|
}
|
|
if (isRepairOnly) {
|
|
await this.checkForRepairOnlyAlertMessage();
|
|
throw new TestSuccessAlert('Both assertions are met successfully.');
|
|
}
|
|
if (isSplitWindshield) {
|
|
await this.checkForSplitWindshieldAlertMessage();
|
|
throw new TestSuccessAlert('Both assertions are met successfully.');
|
|
}
|
|
await this.nextPage();
|
|
}
|
|
} |