Skip to content

Commit

Permalink
Merge pull request #42 from elgentos/gitlab-91
Browse files Browse the repository at this point in the history
[Gitlab-91] Updated flaky tests to always run
  • Loading branch information
dheesen authored Jan 22, 2025
2 parents 58fb7e8 + 0d53844 commit 80b6aac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/base/account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -109,20 +107,22 @@ 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;
let cityNameValue = inputvalues.firstAddress.firstCityValue;
let stateValue = inputvalues.firstAddress.firstProvinceValue;

await accountPage.addNewAddress(phoneNumberValue, addressValue, zipCodeValue, cityNameValue, stateValue);

});

/**
Expand All @@ -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);

});

/**
Expand All @@ -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);

});

/**
Expand All @@ -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);
});

Expand Down Expand Up @@ -235,6 +237,4 @@ test.describe('Newsletter actions', { annotation: {type: 'Account Dashboard', de
await expect(newsletterCheckElement).not.toBeChecked();
}
});

});

17 changes: 17 additions & 0 deletions tests/base/fixtures/account.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit 80b6aac

Please sign in to comment.