Removed duplicate locators.
This commit is contained in:
parent
b4d2719c35
commit
4a9c3f9cab
1 changed files with 24 additions and 49 deletions
|
|
@ -1,14 +1,12 @@
|
|||
import { expect, type Locator, type Page } from '@playwright/test';
|
||||
import { BasePage } from './BasePage';
|
||||
import { AddressForm } from './forms/AddressForm';
|
||||
import { IAddress } from '@business-logic/types/IAddress';
|
||||
import { ICustomerDetails } from '@business-logic/types/CustomerDetails';
|
||||
|
||||
export class AddressLookupPage extends BasePage {
|
||||
readonly page: Page;
|
||||
readonly streetAddressTextBox: Locator;
|
||||
readonly cityTextBox: Locator;
|
||||
readonly stateDropdown: Locator;
|
||||
readonly zipTextBox: Locator;
|
||||
readonly lastNameTextBox: Locator;
|
||||
readonly addressForm: AddressForm;
|
||||
readonly addressNoMatchTextBox: Locator;
|
||||
readonly stateRestrictionsTextBox: Locator;
|
||||
issPageValue = 'address-lookup';
|
||||
|
|
@ -16,69 +14,46 @@ export class AddressLookupPage extends BasePage {
|
|||
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.addressForm = new AddressForm(page);
|
||||
this.addressNoMatchTextBox = page.getByText('Your address didn’t 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 });
|
||||
await this.addressForm.streetAddressTextBox.click();
|
||||
await this.addressForm.streetAddressTextBox.pressSequentially('7400 Safelite Way');
|
||||
await this.addressForm.streetAddressTextBox.press('Tab');
|
||||
await expect(this.addressForm.zipCodeTextBox).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);
|
||||
async populateAddress(fullAddress: IAddress) {
|
||||
if (fullAddress.street) {
|
||||
// Transform IAddress to CustomerDetails address format
|
||||
const customerAddress: Partial<ICustomerDetails> = {
|
||||
address: {
|
||||
street: fullAddress.street,
|
||||
city: fullAddress.city,
|
||||
state: fullAddress.state,
|
||||
postalCode: fullAddress.postalCode
|
||||
},
|
||||
lastName: fullAddress.lastName || '',
|
||||
};
|
||||
// Fill address using AddressForm methods
|
||||
await this.addressForm.populateAddress(customerAddress);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue