DigitalConsumer.ISS/playwright-tests/pages/Addresslookuppage.ts
2025-03-10 10:55:29 -04:00

84 lines
No EOL
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, type Locator, type Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { IAddress } from '@business-logic/types/IAddress';
export class AddressLookupPage extends BasePage {
readonly page: Page;
readonly streetAddressTextBox: Locator;
readonly cityTextBox: Locator;
readonly stateDropdown: Locator;
readonly zipTextBox: Locator;
readonly lastNameTextBox: Locator;
readonly addressNoMatchTextBox: Locator;
readonly stateRestrictionsTextBox: Locator;
url = process.env['baseurl']! + '/?issPage=address-lookup';
constructor(page: Page) {
super(page);
this.page = page;
this.streetAddressTextBox = page.getByRole('textbox', { name: 'Street address' })
this.cityTextBox = page.getByRole('textbox', { name: 'City' })
this.stateDropdown = page.getByRole('combobox')
this.zipTextBox = page.getByRole('textbox', { name: 'ZIP code' })
this.lastNameTextBox = page.getByRole('textbox', { name: 'Last name' })
this.addressNoMatchTextBox = page.getByText('Your address didnt return a VIN matchPlease re-enter the information below or');
this.stateRestrictionsTextBox = page.getByText('State restrictionsLooks like');
}
async enterAddress(street, city, state, zip, lastName) {
this.streetAddressTextBox.clear();
this.page.waitForTimeout(250);
this.streetAddressTextBox.fill(street);
this.cityTextBox.clear();
this.page.waitForTimeout(250);
this.cityTextBox.fill(city);
this.stateDropdown.selectOption(state);
this.zipTextBox.clear();
this.page.waitForTimeout(250);
this.zipTextBox.fill(zip);
this.lastNameTextBox.clear();
this.page.waitForTimeout(250);
this.lastNameTextBox.fill(lastName);
this.page.waitForTimeout(250);
}
async forceAddressFormToAppear() {
await expect(async () => {
await this.streetAddressTextBox.click();
await this.streetAddressTextBox.pressSequentially('7400 Safelite Way');
await this.streetAddressTextBox.press('Tab');
await expect(this.zipTextBox).toBeVisible({ timeout: 100 });
}).toPass();
}
async populateAddress(fullAdddress: IAddress) {
if (fullAdddress.street) {
// Force address form to appear
await this.forceAddressFormToAppear();
// Fill address
await this.fillAndValidate(this.streetAddressTextBox, fullAdddress.street);
await this.fillAndValidate(this.zipTextBox, fullAdddress.postalCode)
await this.fillAndValidate(this.cityTextBox, fullAdddress.city);
await this.stateDropdown.selectOption(fullAdddress.state);
}
if (fullAdddress.lastName) {
await this.fillAndValidate(this.lastNameTextBox, fullAdddress.lastName!);
}
// if (fullAdddress.firstName!) {
// await this.fillAndValidate(this.firstNameTextBox, fullAdddress.firstName);
// }
}
async validateAddressLookupAlerts(addressSet: IAddress[]) {
await this.populateAddress(addressSet[0]);
await this.continueButton.click();
await expect(this.addressNoMatchTextBox).toBeVisible();
await this.populateAddress(addressSet[1]);
await this.continueButton.click();
await expect(this.stateRestrictionsTextBox).toBeVisible();
await this.populateAddress(addressSet[2]);
}
}