DigitalConsumer.FixMyGlass/playwright-tests/pages/VehicleSelectionPage.ts
2025-05-23 11:58:33 -04:00

65 lines
No EOL
2.9 KiB
TypeScript

import { type Locator, type Page, expect, test } from '@playwright/test';
import { BasePage } from './BasePage';
import { IVehicleDetails } from '@business-logic/types/CustomerDetails';
import TestSuccessAlert from '@business-logic/types/TestSuccessAlert';
import { step } from '@business-logic/types/Step';
import { ITestData } from '@business-logic/types/ITestData';
import { ProgressBarPercentages } from '@business-logic/types/Enums';
export class VehicleSelectionPage extends BasePage {
readonly page: Page;
readonly yearDropdown: Locator;
readonly makeDropdown: Locator;
readonly modelDropdown: Locator;
readonly styleDropdown: Locator;
readonly discontinuedServiceAlert: Locator;
url = process.env['BASE_URL']! + '/fmg/?fmgPage=vehicle';
constructor(page: Page) {
super(page);
this.page = page;
this.yearDropdown = this.page.locator('#yearQuestionField');
this.makeDropdown = this.page.locator('#makeQuestionField');
this.modelDropdown = this.page.locator('#modelQuestionField');
this.styleDropdown = this.page.locator('#styleQuestionField');
this.discontinuedServiceAlert = this.page.locator('.alert-danger.widget-name-AlertNoServiceWidget');
// this.validateURL(this.url);
}
async selectVehicle(vehicleDetails: IVehicleDetails) {
await this.yearDropdown.selectOption(vehicleDetails.year);
await this.yearDropdown.press('Tab');
await this.makeDropdown.selectOption(vehicleDetails.make);
await this.yearDropdown.press('Tab');
await this.modelDropdown.selectOption(vehicleDetails.model);
await this.yearDropdown.press('Tab');
if (vehicleDetails.style != undefined) {
await this.styleDropdown.selectOption(vehicleDetails.style);
}
}
async checkForAlertMessages() {
await expect(this.discontinuedServiceAlert).toBeVisible();
const alertMessage = await this.discontinuedServiceAlert.textContent();
await console.log(`Alert encountered: ${alertMessage}`);
await expect(alertMessage).toContain('Service not available in your areaWe do not offer glass service for your vehicle in your ZIP code. We apologize for the inconvenience.');
}
@step("VehicleSelectionPage >> Select Vehicle: ")
async handleVehicleSelectionPage(testData: Partial<ITestData>) {
await this.validateProgressBar(ProgressBarPercentages.VehicleSelectionPage);
const { vehicleDetails } = testData;
const { isHeavyTruckVehicle, isSplitWindshield } = testData.alertFlags || {};
await this.selectVehicle(vehicleDetails!);
// Handle alert conditions for vehicle selection
if (isHeavyTruckVehicle || isSplitWindshield) {
await this.checkForAlertMessages();
throw new TestSuccessAlert('Both assertions are met successfully.');
}
await this.nextPage();
}
}