diff --git a/package.json b/package.json index 97e8b1f..dd66ffa 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "license": "ISC", "description": "", "devDependencies": { + "@faker-js/faker": "^9.4.0", "@playwright/test": "^1.47.2", "@types/node": "^22.7.4" }, diff --git a/tests/base/account.spec.ts b/tests/base/account.spec.ts index a1ecf4b..6535f93 100644 --- a/tests/base/account.spec.ts +++ b/tests/base/account.spec.ts @@ -97,14 +97,7 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash testInfo.skip(await addNewAddressTitle.isHidden(), `Heading "Add New Addres" is not found, please check if an address has already been added.`); const accountPage = new AccountPage(page); - let phoneNumberValue = inputvalues.firstAddress.firstPhoneNumberValue; - let addressValue = inputvalues.firstAddress.firstStreetAddressValue; - let zipCodeValue = inputvalues.firstAddress.firstZipCodeValue; - let cityNameValue = inputvalues.firstAddress.firstCityValue; - let stateValue = inputvalues.firstAddress.firstProvinceValue; - - await accountPage.addNewAddress(phoneNumberValue, addressValue, zipCodeValue, cityNameValue, stateValue); - + await accountPage.addNewAddress(); }); /** @@ -118,17 +111,8 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash */ test('I can add another address',{ tag: '@address-actions', }, async ({page}) => { await page.goto(slugs.account.addressNewSlug); - const accountPage = new AccountPage(page); - - let phoneNumberValue = inputvalues.secondAddress.secondPhoneNumberValue; - let addressValue = inputvalues.secondAddress.secondStreetAddressValue; - let zipCodeValue = inputvalues.secondAddress.secondZipCodeValue; - let cityNameValue = inputvalues.secondAddress.secondCityValue; - let stateValue = inputvalues.secondAddress.secondProvinceValue; - - await accountPage.addNewAddress(phoneNumberValue, addressValue, zipCodeValue, cityNameValue, stateValue); - + await accountPage.addNewAddress(); }); /** @@ -143,21 +127,18 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash * @then I should see a notification my address has been updated. * @and The updated address should be visible in the addres book page. */ - test('I can edit an existing address',{ tag: '@address-actions', }, async ({page}, testInfo) => { + test('I can edit an existing address',{ tag: '@address-actions', }, async ({page}) => { const accountPage = new AccountPage(page); - let newFirstName = inputvalues.editedAddress.editfirstNameValue; - let newLastName = inputvalues.editedAddress.editLastNameValue; - let newStreet = inputvalues.editedAddress.editStreetAddressValue; - let newZipCode = inputvalues.editedAddress.editZipCodeValue; - let newCity = inputvalues.editedAddress.editCityValue; - let newState = inputvalues.editedAddress.editStateValue; - + await page.goto(slugs.account.addressNewSlug); let editAddressButton = page.getByRole('link', {name: selectors.accountDashboard.editAddressIconButton}).first(); - testInfo.skip(await editAddressButton.isHidden(), `Button to edit Address is not found, please check if an address has been added.`); - await page.goto(slugs.account.addressBookSlug); - await accountPage.editExistingAddress(newFirstName, newLastName, newStreet, newZipCode, newCity, newState); + if(await editAddressButton.isHidden()){ + // The edit address button was not found, add another address first. + await accountPage.addNewAddress(); + } + await page.goto(slugs.account.addressBookSlug); + await accountPage.editExistingAddress(); }); /** diff --git a/tests/base/fixtures/account.page.ts b/tests/base/fixtures/account.page.ts index 69aabd9..c7b7179 100644 --- a/tests/base/fixtures/account.page.ts +++ b/tests/base/fixtures/account.page.ts @@ -1,4 +1,5 @@ import {expect, type Locator, type Page} from '@playwright/test'; +import {faker} from '@faker-js/faker'; import selectors from '../config/selectors/selectors.json'; import verify from '../config/expected/expected.json'; @@ -39,7 +40,7 @@ export class AccountPage { */ // TODO: Update these functionalities to be able to take in non-required fields. - + constructor(page: Page){ this.page = page; this.accountDashboardTitle = page.getByRole('heading', { name: selectors.accountDashboard.accountDashboardTitleLabel }); @@ -79,49 +80,49 @@ export class AccountPage { this.editAddressButton = page.getByRole('link', {name: selectors.accountDashboard.editAddressIconButton}).first(); } - //TODO: Add ability to choose different country other than US - async addNewAddress(phonenumber: string,streetName: string, zipCode: string, cityName: string, state: string){ + async addNewAddress(){ let addressAddedNotification = verify.address.newAddressAddedNotifcation; - + let streetName = faker.location.streetAddress(); // Name should be filled in automatically. await expect(this.firstNameField).not.toBeEmpty(); await expect(this.lastNameField).not.toBeEmpty(); - await this.phoneNumberField.fill(phonenumber); + await this.phoneNumberField.fill(faker.phone.number()); await this.streetAddressField.fill(streetName); - await this.zipCodeField.fill(zipCode); - await this.cityField.fill(cityName); - await this.stateSelectorField.selectOption(state); + await this.zipCodeField.fill(faker.location.zipCode()); + await this.cityField.fill(faker.location.city()); + await this.stateSelectorField.selectOption(faker.location.state()); await this.saveAddressButton.click(); await this.page.waitForLoadState(); - await expect(this.page.getByText(addressAddedNotification)).toBeVisible(); + await expect.soft(this.page.getByText(addressAddedNotification)).toBeVisible(); await expect(this.page.getByText(streetName).last()).toBeVisible(); } + - async editExistingAddress(firstName: string, lastName: string, streetName: string, zipCode: string, cityName: string, state: string){ + async editExistingAddress(){ // the notification for a modified address is the same as the notification for a new address. let addressModifiedNotification = verify.address.newAddressAddedNotifcation; + let streetName = faker.location.streetAddress(); - // .click() replaced by .press("Enter") as a workaround for webkit issues await this.editAddressButton.click(); // Name should be filled in automatically, but editable. await expect(this.firstNameField).not.toBeEmpty(); await expect(this.lastNameField).not.toBeEmpty(); - await this.firstNameField.fill(firstName); - await this.lastNameField.fill(lastName); + await this.firstNameField.fill(faker.person.firstName()); + await this.lastNameField.fill(faker.person.lastName()); await this.streetAddressField.fill(streetName); - await this.zipCodeField.fill(zipCode); - await this.cityField.fill(cityName); - await this.stateSelectorField.selectOption(state); - // .click() replaced by .press("Enter") as a workaround for webkit issues + await this.zipCodeField.fill(faker.location.zipCode()); + await this.cityField.fill(faker.location.city()); + await this.stateSelectorField.selectOption(faker.location.state()); + await this.saveAddressButton.click(); await this.page.waitForLoadState(); - await expect(this.page.getByText(addressModifiedNotification)).toBeVisible(); + await expect.soft(this.page.getByText(addressModifiedNotification)).toBeVisible(); await expect(this.page.getByText(streetName).last()).toBeVisible(); }