DigitalConsumer.FixMyGlass/playwright-tests/pages/VehicleSelectionPage.ts
maguire-arman 8da9b21539 Updates with 631 changes
Improves the handling of cash to insurance flows, including adding new test cases and adjusting logic for policy verification and payment methods.
Also, updates UI elements to ensure correct display of deductible information and handles split windshield scenarios.
The `safelite-playwright-core` dependency is updated to version 1.0.22.
2025-06-23 14:17:34 -04:00

72 lines
No EOL
3.2 KiB
TypeScript

import { type Locator, type Page, expect, test } from '@playwright/test';
import { BasePage } from './BasePage';
import { IVehicleDetails } from 'safelite-playwright-core';
import { TestSuccessAlert } from 'safelite-playwright-core';
import { step } from 'framework/localTypes/Step';
import { ITestData } from 'framework/TestData';
import { ProgressBarPercentages } from 'framework/localTypes/Enums';
export class VehicleSelectionPage extends BasePage {
readonly page: Page;
readonly yearDropdown: Locator;
readonly makeDropdown: Locator;
readonly modelDropdown: Locator;
readonly styleDropdown: Locator;
readonly zipCodeTextBox: 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.zipCodeTextBox = this.page.getByRole('textbox', { name: 'Zip code' });
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, isHeavyTruck, customerDetails } = testData;
const { isHeavyTruckVehicleAlert, isSplitWindshield } = testData.alertFlags || {};
await this.selectVehicle(vehicleDetails!);
if (isHeavyTruck) {
await this.zipCodeTextBox.fill(customerDetails?.address.postalCode!);
}
// Handle alert conditions for vehicle selection
if (isHeavyTruckVehicleAlert) {
await this.continueButton.click();
await this.checkForAlertMessages();
throw new TestSuccessAlert('Both assertions are met successfully.');
}
await this.nextPage();
}
}