Skip to content

Gitlab 124: Implementing fixtures #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
151eb54
Renamed fixtures to poms. Added actual fixtures to handle login and a…
shayfaber Feb 25, 2025
f8736c6
Created fixtures. WIP: update cart.spec.ts to utilize fixtures, rewri…
shayfaber Feb 25, 2025
1207151
WIP: Implementing fixtures
shayfaber Mar 3, 2025
f297d2a
Logout() added to login.page.ts, WIP: Rewriting account.spec.ts to in…
shayfaber Mar 4, 2025
caba62b
Rewrote test 'Add_the_first_address' to use fixture and skip if defau…
shayfaber Mar 4, 2025
1371e9d
Moved element identifier to appropriate JSON file
shayfaber Mar 4, 2025
e2a744e
Rewrote 'Add_another_address' to use a fixture
shayfaber Mar 4, 2025
cab8d3e
Rewrote test 'Update_existing_address' to include a fixture
shayfaber Mar 4, 2025
47069ee
Rewrote 'Delete_existing_address' to include fixture
shayfaber Mar 4, 2025
336ee24
Reworked 'Password_change' test to include fixture
shayfaber Mar 4, 2025
850772a
Rewrote account.spec.ts to use fixtures
shayfaber Mar 4, 2025
649edcd
Rewrote test 'Address_is_filled_in_checkout' to utilize fixtures
shayfaber Mar 4, 2025
a0bed4d
Reworked 'Place_order_for_simple_product' to include fixtures. Update…
shayfaber Mar 4, 2025
522ca77
Rewrite 'Remove_coupon_code_in_checkout' to utilize fixtures
shayfaber Mar 4, 2025
f1d0c54
Rewrote 'Invalid_coupon_code_in_checkout_is_rejected' to utilize fixt…
shayfaber Mar 4, 2025
a069d7e
WIP: implementing fixtures
shayfaber Mar 11, 2025
535c817
updated checkout.spec.ts to utilize fixtures
shayfaber Mar 18, 2025
fc604d9
WIP: fixtures
shayfaber Mar 24, 2025
23475a3
Fixes based on code review
shayfaber Mar 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 90 additions & 148 deletions tests/base/account.spec.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,18 @@
import {test, expect} from '@playwright/test';
import {MainMenuPage} from './fixtures/mainmenu.page';
import {LoginPage} from './fixtures/login.page';
import {RegisterPage} from './fixtures/register.page';
import {AccountPage} from './fixtures/account.page';
import {NewsletterSubscriptionPage} from './fixtures/newsletter.page';
import {faker} from '@faker-js/faker';
import {productTest} from './fixtures/fixtures';

import {LoginPage} from './poms/login.page';
import {RegisterPage} from './poms/register.page';
import {AccountPage} from './poms/account.page';
import {NewsletterSubscriptionPage} from './poms/newsletter.page';

import slugs from './config/slugs.json';
import inputvalues from './config/input-values/input-values.json';
import UIReference from './config/element-identifiers/element-identifiers.json';
import outcomeMarker from './config/outcome-markers/outcome-markers.json';

// Before each test, log in
test.beforeEach(async ({ page, browserName }) => {
const browserEngine = browserName?.toUpperCase() || "UNKNOWN";
let emailInputValue = process.env[`MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine}`];
let passwordInputValue = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD;

if(!emailInputValue || !passwordInputValue) {
throw new Error("MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine} and/or MAGENTO_EXISTING_ACCOUNT_PASSWORD have not defined in the .env file, or the account hasn't been created yet.");
}

const loginPage = new LoginPage(page);
await loginPage.login(emailInputValue, passwordInputValue);
});

test.describe('Account information actions', {annotation: {type: 'Account Dashboard', description: 'Test for Account Information'},}, () => {

test.beforeEach(async ({page}) => {
await page.goto(slugs.account.accountOverviewSlug);
await page.waitForLoadState();
});

/**
* @feature Magento 2 Change Password
* @scenario User changes their password
* @given I am logged in
* @and I am on the Account Dashboard page
* @when I navigate to the Account Information page
* @and I check the 'change password' option
* @when I fill in the new credentials
* @and I click Save
* @then I should see a notification that my password has been updated
* @and I should be able to login with my new credentials.
*/
test('I can change my password',{ tag: '@account-credentials', }, async ({page, browserName}, testInfo) => {

// Create instances and set variables
const mainMenu = new MainMenuPage(page);
const registerPage = new RegisterPage(page);
const accountPage = new AccountPage(page);
const loginPage = new LoginPage(page);

const browserEngine = browserName?.toUpperCase() || "UNKNOWN";
let randomNumberforEmail = Math.floor(Math.random() * 101);
let emailPasswordUpdatevalue = `passwordupdate-${randomNumberforEmail}-${browserEngine}@example.com`;
let passwordInputValue = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD;
let changedPasswordValue = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD;

// Log out of current account
if(await page.getByRole('link', { name: UIReference.mainMenu.myAccountLogoutItem }).isVisible()){
await mainMenu.logout();
}

// Create account
if(!changedPasswordValue || !passwordInputValue) {
throw new Error("Changed password or original password in your .env file is not defined or could not be read.");
}

await registerPage.createNewAccount(inputvalues.accountCreation.firstNameValue, inputvalues.accountCreation.lastNameValue, emailPasswordUpdatevalue, passwordInputValue);

// Update password
await page.goto(slugs.account.changePasswordSlug);
await page.waitForLoadState();
await accountPage.updatePassword(passwordInputValue, changedPasswordValue);

// If login with changePasswordValue is possible, then password change was succesful.
await loginPage.login(emailPasswordUpdatevalue, changedPasswordValue);

// Logout again, login with original account
await mainMenu.logout();
let emailInputValue = process.env[`MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine}`];
if(!emailInputValue) {
throw new Error("MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine} and/or MAGENTO_EXISTING_ACCOUNT_PASSWORD have not defined in the .env file, or the account hasn't been created yet.");
}
await loginPage.login(emailInputValue, passwordInputValue);
});
});

test.describe.serial('Account address book actions', { annotation: {type: 'Account Dashboard', description: 'Tests for the Address Book'},}, () => {
test.beforeEach(async ({page}) => {
await page.goto(slugs.account.addressBookSlug);
await page.waitForLoadState();
});

test.describe('Address actions', () => {
/**
* @feature Magento 2 Add First Address to Account
* @feature Add First Address to Account
* @scenario User adds a first address to their account
* @given I am logged in
* @and I am on the account dashboard page
Expand All @@ -105,21 +23,24 @@ test.describe.serial('Account address book actions', { annotation: {type: 'Accou
* @then I should see a notification my address has been updated.
* @and The new address should be selected as default and shipping address
*/
productTest('Add_the_first_address', {tag: ['@address']}, async ({userPage}, testInfo) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you have a look at all these user tests? Looks like this should be called something like userTest right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitlab ticket has been created to rename this!

const accountPage = new AccountPage(userPage.page);
await userPage.page.goto(slugs.account.accountOverviewSlug);

test('I can add my first address',{ tag: '@address-actions', }, async ({page}, testInfo) => {
const accountPage = new AccountPage(page);
let addNewAddressTitle = page.getByRole('heading', {level: 1, name: UIReference.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 defaultBillingAddressSet = userPage.page.getByText(UIReference.accountDashboard.defaultAddressNotSetLabel);

await accountPage.addNewAddress();
if(await defaultBillingAddressSet.isVisible()) {
// No default address set, so no address has been added yet.
await userPage.page.goto(slugs.account.addressNewSlug);
await accountPage.addNewAddress();
} else {
testInfo.annotations.push({ type: 'Test skipped', description: `A default address has been set, adding a first address has already been done.`});
test.skip(true,'Default billing address found.');
}
});

/**
* @feature Add another address
* @given I am logged in
* @and I am on the account dashboard page
* @when I go to the page where I can add another address
Expand All @@ -128,15 +49,15 @@ test.describe.serial('Account address book actions', { annotation: {type: 'Accou
* @then I should see a notification my address has been updated.
* @and The new address should be listed
*/
test('I can add another address',{ tag: '@address-actions', }, async ({page}) => {
await page.goto(slugs.account.addressNewSlug);
const accountPage = new AccountPage(page);
productTest('Add_another_address', {tag: ['@address']}, async ({userPage}) => {
await userPage.page.goto(slugs.account.addressNewSlug);
const accountPage = new AccountPage(userPage.page);

await accountPage.addNewAddress();
});

/**
* @feature Magento 2 Update Address in Account
* @feature Update Address in Account
* @scenario User updates an existing address to their account
* @given I am logged in
* @and I am on the account dashboard page
Expand All @@ -147,17 +68,14 @@ test.describe.serial('Account address book actions', { annotation: {type: 'Accou
* @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}) => {
const accountPage = new AccountPage(page);
await page.goto(slugs.account.addressNewSlug);
let editAddressButton = page.getByRole('link', {name: UIReference.accountDashboard.editAddressIconButton}).first();

productTest('Update_existing_address', {tag: ['@address']}, async ({userPage}) => {
const accountPage = new AccountPage(userPage.page);
await userPage.page.goto(slugs.account.addressBookSlug);
let editAddressButton = userPage.page.getByRole('link', {name: UIReference.accountDashboard.editAddressIconButton}).first();
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();
});

Expand All @@ -172,52 +90,76 @@ test.describe.serial('Account address book actions', { annotation: {type: 'Accou
* @then I should see a notification my address has been deleted.
* @and The address should be removed from the overview.
*/
test('I can delete an address',{ tag: '@address-actions', }, async ({page}, testInfo) => {
const accountPage = new AccountPage(page);

let deleteAddressButton = page.getByRole('link', {name: UIReference.accountDashboard.addressDeleteIconButton}).first();

productTest('Delete_existing_address', {tag: ['@address']}, async ({userPage}) => {
const accountPage = new AccountPage(userPage.page);
await userPage.page.goto(slugs.account.addressBookSlug);
let deleteAddressButton = userPage.page.getByRole('link', {name: UIReference.accountDashboard.addressDeleteIconButton}).first();
if(await deleteAddressButton.isHidden()) {
await page.goto(slugs.account.addressNewSlug);
await userPage.page.goto(slugs.account.addressNewSlug);
await accountPage.addNewAddress();
}
await accountPage.deleteFirstAddressFromAddressBook();
});
});

test.describe('Newsletter actions', { annotation: {type: 'Account Dashboard', description: 'Newsletter tests'},}, () => {
test.beforeEach(async ({page}) => {
await page.goto(slugs.account.accountOverviewSlug);
});

/**
* @feature Magento 2 newsletter subscriptions
* @scenario User (un)subscribes from a newsletter
* @given I am logged in
* @and I am on the account dashboard page
* @when I click on the newsletter link in the sidebar
* @then I should navigate to the newsletter subscription page
* @when I (un)check the subscription button
* @then I should see a message confirming my action
* @and My subscription option should be updated.
*/
test('I can update my newsletter subscription',{ tag: '@newsletter-actions', }, async ({page, browserName}) => {
test.skip(browserName === 'webkit', '.click() does not work, still searching for a workaround');
const newsletterPage = new NewsletterSubscriptionPage(page);
let newsletterLink = page.getByRole('link', { name: UIReference.accountDashboard.links.newsletterLink });
const newsletterCheckElement = page.getByLabel(UIReference.newsletterSubscriptions.generalSubscriptionCheckLabel);
/**
* @feature Magento 2 Change Password
* @scenario User changes their password
* @given I am logged in
* @and I am on the Account Dashboard page
* @when I navigate to the Account Information page
* @and I check the 'change password' option
* @when I fill in the new credentials
* @and I click Save
* @then I should see a notification that my password has been updated
* @and I should be able to login with my new credentials.
*/
test('Password_change',{ tag: '@password',}, async ({page, browserName}, testInfo) => {
// Create instances and set variables
const registerPage = new RegisterPage(page);
const accountPage = new AccountPage(page);
const loginPage = new LoginPage(page);
const browserEngine = browserName?.toUpperCase() || "UNKNOWN";
let emailInputValue = `passwordupdate-${browserEngine}@example.com`;
let passwordInputValue = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD;
let changedPasswordValue = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD;

await newsletterLink.click();
await expect(page.getByText(outcomeMarker.account.newsletterSubscriptionTitle, { exact: true })).toBeVisible();
if(!changedPasswordValue || !passwordInputValue) {
throw new Error("Changed password or original password in your .env file is not defined or could not be read.");
}

let updateSubscription = await newsletterPage.updateNewsletterSubscription();
await test.step('Create a throwaway account', async () =>{
await registerPage.createNewAccount(faker.person.firstName(), faker.person.lastName(), emailInputValue, passwordInputValue);
});

await newsletterLink.click();
await test.step('Update the password', async () =>{
await page.goto(slugs.account.changePasswordSlug);
await page.waitForLoadState();
await accountPage.updatePassword(passwordInputValue, changedPasswordValue);
});

if(updateSubscription){
await expect(newsletterCheckElement).toBeChecked();
} else {
await expect(newsletterCheckElement).not.toBeChecked();
}
await test.step('Login with updated password', async () =>{
await loginPage.login(emailInputValue, changedPasswordValue);
await loginPage.logout();
});

});

/**
* @feature Newsletter subscriptions
* @scenario User (un)subscribes from a newsletter
* @given I am logged in
* @and I am on the account dashboard page
* @when I click on the newsletter link in the sidebar
* @then I should navigate to the newsletter subscription page
* @when I (un)check the subscription button
* @then I should see a message confirming my action
* @and My subscription option should be updated.
*/
productTest('Update_newsletter_subscription', {tag: ['@newsletter']}, async ({userPage, browserName}) => {
test.skip(browserName === 'webkit', '.click() does not work, will be fixed later');
const newsLetterPage = new NewsletterSubscriptionPage(userPage.page);
await newsLetterPage.page.goto(slugs.account.newsLetterSlug);

await newsLetterPage.updateNewsletterSubscription();
});
Loading