DigitalConsumer.ISS/playwright-tests/pages/forms/AddressForm.ts
chase-safelite 5d3ab0ef59
Added playwright tests into repo (#923)
* Initial import of playwright tests

* Pipeline changes for automated tests

* Modified pipeline for testing

* Attempt #2

* Attempt #3

* Added missing paren

* Removed debug stuff from pipeline

* Changes from playwright repo

* Changed pipeline for debugging

* Fix for ServiceLocationPage playwright locators

* Change pipeline to run with TEST APIs

* Moved more of Siraj's changes to this repo

* Changed where updating env occurs

* Changed location of env update again

* Escaped double quotes

* Added visible report in Azure

* Moved changes into main pipeline

* Made it so dotenv only runs config in local
2025-02-14 09:54:11 -05:00

58 lines
No EOL
2.4 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { BasePage } from '../BasePage';
import { ICustomerDetails } from '@business-logic/types/CustomerDetails';
import { faker } from '@faker-js/faker/locale/en';
export class AddressForm extends BasePage {
readonly page: Page;
readonly streetAddressTextBox: Locator;
readonly cityTextBox: Locator;
readonly stateDrpDwn: Locator;
readonly zipCodeTextBox: Locator;
readonly firstNameTextBox: Locator;
readonly lastNameTextBox: Locator;
readonly addressNotFoundMsg: Locator;
constructor(page: Page) {
super(page);
this.page = page;
this.streetAddressTextBox = page.getByRole('textbox', { name: /Street (a|A)ddress$/ });
this.cityTextBox = page.getByRole('textbox', { name: 'City' });
this.stateDrpDwn = page.getByRole('combobox', { name: 'State' });
this.zipCodeTextBox = page.getByRole('textbox', { name: 'ZIP code' });
this.firstNameTextBox = page.getByRole('textbox', { name: 'First name' });
this.lastNameTextBox = page.getByRole('textbox', { name: 'Last name' });
this.addressNotFoundMsg = page.getByText('Address not found.');
}
async forceAddressFormToAppear() {
await expect(async () => {
await this.streetAddressTextBox.click();
await this.streetAddressTextBox.pressSequentially('7400 Safelite Way');
await this.streetAddressTextBox.press('Tab');
await expect(this.zipCodeTextBox).toBeVisible({ timeout: 100 });
}).toPass();
}
async populateAddress(customerDetails: Partial<ICustomerDetails>) {
if (customerDetails.address) {
// Force address form to appear
await this.forceAddressFormToAppear();
// Fill address
await this.fillAndValidate(this.streetAddressTextBox, customerDetails.address.street);
await this.fillAndValidate(this.zipCodeTextBox, customerDetails.address.postalCode)
await this.fillAndValidate(this.cityTextBox, customerDetails.address.city);
await this.stateDrpDwn.selectOption(customerDetails.address.state);
}
if (customerDetails.firstName) {
await this.fillAndValidate(this.firstNameTextBox, customerDetails.firstName);
}
if (customerDetails.lastName) {
await this.fillAndValidate(this.lastNameTextBox, customerDetails.lastName);
}
}
}