diff --git a/tests/base/account.spec.ts b/tests/base/account.spec.ts index 317ca24..e130aab 100644 --- a/tests/base/account.spec.ts +++ b/tests/base/account.spec.ts @@ -87,10 +87,8 @@ test.describe('Account information actions', {annotation: {type: 'Account Dashbo }); }); - -test.describe('Account address book actions', { annotation: {type: 'Account Dashboard', description: 'Tests for the Address Book'},}, () => { +test.describe.serial('Account address book actions', { annotation: {type: 'Account Dashboard', description: 'Tests for the Address Book'},}, () => { test.beforeEach(async ({page}) => { - // go to the Adress Book page await page.goto(slugs.account.addressBookSlug); await page.waitForLoadState(); }); @@ -109,12 +107,15 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash */ test('I can add my first address',{ tag: '@address-actions', }, async ({page}, testInfo) => { - // If account has no address, Address Book redirects to the 'Add New Address' page. - // We expect this to be true before continuing. - let addNewAddressTitle = page.getByRole('heading', {level: 1, name: selectors.newAddress.addNewAddressTitle}); - 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 addNewAddressTitle = page.getByRole('heading', {level: 1, name: selectors.newAddress.addNewAddressTitle}); + if(await addNewAddressTitle.isHidden()) { + await accountPage.deleteAllAddresses(); + testInfo.annotations.push({ type: 'Notification: deleted addresses', description: `All addresses are deleted to recreate the first address flow.` }); + await page.goto(slugs.account.addressNewSlug); + } + let phoneNumberValue = inputvalues.firstAddress.firstPhoneNumberValue; let addressValue = inputvalues.firstAddress.firstStreetAddressValue; let zipCodeValue = inputvalues.firstAddress.firstZipCodeValue; @@ -122,7 +123,6 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash let stateValue = inputvalues.firstAddress.firstProvinceValue; await accountPage.addNewAddress(phoneNumberValue, addressValue, zipCodeValue, cityNameValue, stateValue); - }); /** @@ -146,7 +146,6 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash let stateValue = inputvalues.secondAddress.secondProvinceValue; await accountPage.addNewAddress(phoneNumberValue, addressValue, zipCodeValue, cityNameValue, stateValue); - }); /** @@ -171,11 +170,12 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash let newState = inputvalues.editedAddress.editStateValue; 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.`); + if(await editAddressButton.isHidden()) { + await page.goto(slugs.account.addressNewSlug); + await accountPage.addNewAddress(inputvalues.firstAddress.firstPhoneNumberValue, inputvalues.firstAddress.firstStreetAddressValue, inputvalues.firstAddress.firstZipCodeValue, inputvalues.firstAddress.firstCityValue, inputvalues.firstAddress.firstProvinceValue); + } - await page.goto(slugs.account.addressBookSlug); await accountPage.editExistingAddress(newFirstName, newLastName, newStreet, newZipCode, newCity, newState); - }); /** @@ -193,15 +193,17 @@ test.describe('Account address book actions', { annotation: {type: 'Account Dash const accountPage = new AccountPage(page); let deleteAddressButton = page.getByRole('link', {name: selectors.accountDashboard.addressDeleteIconButton}).first(); - testInfo.skip(await deleteAddressButton.isHidden(), `Button to delete Address is not found, please check if an address has been added.`); + if(await deleteAddressButton.isHidden()) { + await page.goto(slugs.account.addressNewSlug); + await accountPage.addNewAddress(inputvalues.firstAddress.firstPhoneNumberValue, inputvalues.firstAddress.firstStreetAddressValue, inputvalues.firstAddress.firstZipCodeValue, inputvalues.firstAddress.firstCityValue, inputvalues.firstAddress.firstProvinceValue); + } await accountPage.deleteFirstAddressFromAddressBook(); }); }); test.describe('Newsletter actions', { annotation: {type: 'Account Dashboard', description: 'Newsletter tests'},}, () => { test.beforeEach(async ({page}) => { - // go to the Dashboard page await page.goto(slugs.account.accountOverviewSlug); }); @@ -235,6 +237,4 @@ test.describe('Newsletter actions', { annotation: {type: 'Account Dashboard', de await expect(newsletterCheckElement).not.toBeChecked(); } }); - }); - diff --git a/tests/base/fixtures/account.page.ts b/tests/base/fixtures/account.page.ts index 9a16e8e..946f89a 100644 --- a/tests/base/fixtures/account.page.ts +++ b/tests/base/fixtures/account.page.ts @@ -150,4 +150,21 @@ export class AccountPage { await this.accountCreationPasswordRepeatField.fill(password); await this.accountCreationConfirmButton.click(); } + + async deleteAllAddresses() { + let addressDeletedNotification = verify.address.addressDeletedNotification; + + this.page.on('dialog', async (dialog) => { + if (dialog.type() === 'confirm') { + await dialog.accept(); + } + }); + + while (await this.deleteAddressButton.isVisible()) { + await this.deleteAddressButton.click(); + await this.page.waitForLoadState(); + + await expect(this.page.getByText(addressDeletedNotification)).toBeVisible(); + } + } }