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 { expect, type Locator, type Page } from '@playwright/test';
|
||||||
import { BasePage } from './BasePage';
|
import { BasePage } from './BasePage';
|
||||||
|
import { AddressForm } from './forms/AddressForm';
|
||||||
import { IAddress } from '@business-logic/types/IAddress';
|
import { IAddress } from '@business-logic/types/IAddress';
|
||||||
|
import { ICustomerDetails } from '@business-logic/types/CustomerDetails';
|
||||||
|
|
||||||
export class AddressLookupPage extends BasePage {
|
export class AddressLookupPage extends BasePage {
|
||||||
readonly page: Page;
|
readonly page: Page;
|
||||||
readonly streetAddressTextBox: Locator;
|
readonly addressForm: AddressForm;
|
||||||
readonly cityTextBox: Locator;
|
|
||||||
readonly stateDropdown: Locator;
|
|
||||||
readonly zipTextBox: Locator;
|
|
||||||
readonly lastNameTextBox: Locator;
|
|
||||||
readonly addressNoMatchTextBox: Locator;
|
readonly addressNoMatchTextBox: Locator;
|
||||||
readonly stateRestrictionsTextBox: Locator;
|
readonly stateRestrictionsTextBox: Locator;
|
||||||
issPageValue = 'address-lookup';
|
issPageValue = 'address-lookup';
|
||||||
|
|
@ -16,69 +14,46 @@ export class AddressLookupPage extends BasePage {
|
||||||
constructor(page: Page) {
|
constructor(page: Page) {
|
||||||
super(page);
|
super(page);
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.streetAddressTextBox = page.getByRole('textbox', { name: 'Street address' })
|
this.addressForm = new AddressForm(page);
|
||||||
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 didn’t return a VIN matchPlease re-enter the information below or');
|
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');
|
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() {
|
async forceAddressFormToAppear() {
|
||||||
await expect(async () => {
|
await expect(async () => {
|
||||||
await this.streetAddressTextBox.click();
|
await this.addressForm.streetAddressTextBox.click();
|
||||||
await this.streetAddressTextBox.pressSequentially('7400 Safelite Way');
|
await this.addressForm.streetAddressTextBox.pressSequentially('7400 Safelite Way');
|
||||||
await this.streetAddressTextBox.press('Tab');
|
await this.addressForm.streetAddressTextBox.press('Tab');
|
||||||
await expect(this.zipTextBox).toBeVisible({ timeout: 100 });
|
await expect(this.addressForm.zipCodeTextBox).toBeVisible({ timeout: 100 });
|
||||||
}).toPass();
|
}).toPass();
|
||||||
}
|
}
|
||||||
async populateAddress(fullAdddress: IAddress) {
|
|
||||||
|
|
||||||
if (fullAdddress.street) {
|
async populateAddress(fullAddress: IAddress) {
|
||||||
// Force address form to appear
|
if (fullAddress.street) {
|
||||||
await this.forceAddressFormToAppear();
|
// Transform IAddress to CustomerDetails address format
|
||||||
|
const customerAddress: Partial<ICustomerDetails> = {
|
||||||
// Fill address
|
address: {
|
||||||
await this.fillAndValidate(this.streetAddressTextBox, fullAdddress.street);
|
street: fullAddress.street,
|
||||||
await this.fillAndValidate(this.zipTextBox, fullAdddress.postalCode)
|
city: fullAddress.city,
|
||||||
await this.fillAndValidate(this.cityTextBox, fullAdddress.city);
|
state: fullAddress.state,
|
||||||
await this.stateDropdown.selectOption(fullAdddress.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[]) {
|
async validateAddressLookupAlerts(addressSet: IAddress[]) {
|
||||||
await this.populateAddress(addressSet[0]);
|
await this.populateAddress(addressSet[0]);
|
||||||
await this.continueButton.click();
|
await this.continueButton.click();
|
||||||
await expect(this.addressNoMatchTextBox).toBeVisible();
|
await expect(this.addressNoMatchTextBox).toBeVisible();
|
||||||
|
|
||||||
await this.populateAddress(addressSet[1]);
|
await this.populateAddress(addressSet[1]);
|
||||||
await this.continueButton.click();
|
await this.continueButton.click();
|
||||||
await expect(this.stateRestrictionsTextBox).toBeVisible();
|
await expect(this.stateRestrictionsTextBox).toBeVisible();
|
||||||
|
|
||||||
await this.populateAddress(addressSet[2]);
|
await this.populateAddress(addressSet[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue