DigitalConsumer.FixMyGlass/playwright-tests/pages/PolicyDriverPage.ts
maguire-arman 458e552d6b Removes URL declaration from page classes
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.
2025-07-14 16:13:56 -04:00

56 lines
No EOL
2.2 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { InsuranceBasePage } from './InsuranceBasePage';
import { ICustomerDetails } from 'safelite-playwright-core';
import { step } from 'framework/localTypes/Step';
import { ITestData } from 'framework/TestData';
export class PolicyDriverPage extends InsuranceBasePage {
readonly page: Page;
readonly driverListItems: Locator;
readonly driverNotListedOption: Locator;
readonly vehicleParkedOption: Locator;
constructor(page: Page) {
super(page);
this.page = page;
// Locators for driver list items (the clickable areas)
this.driverListItems = this.page.locator('.list-group-item');
// Locators for driver options
this.driverNotListedOption = this.page.getByRole('link', { name: 'Driver not listed' });
this.vehicleParkedOption = this.page.getByRole('link', { name: 'Vehicle was parked' });
}
async selectPolicyDriver(customerDetails: ICustomerDetails): Promise<void> {
// Format the customer name for matching
const customerFullName = `${customerDetails.firstName} ${customerDetails.lastName}`.toUpperCase();
// Get all driver list items
const driverItems = await this.driverListItems.all();
let driverFound = false;
// Check each driver item for a match with our customer
for (const item of driverItems) {
const nameText = await item.locator('.third-span').textContent();
if (nameText && nameText.toUpperCase().includes(customerFullName)) {
// If we found a match, click the list-group-item (the whole row)
await item.click();
driverFound = true;
break;
}
}
// If no match was found, select "Driver not listed"
if (!driverFound) {
await this.driverNotListedOption.click();
}
}
@step("PolicyDriverPage >> Select policy driver: ")
async handlePolicyDriverPage(testData: Partial<ITestData>) {
const { customerDetails } = testData;
await this.selectPolicyDriver(customerDetails!);
await this.nextPage();
}
}