Skip to content

Commit

Permalink
feat: Add additional page objects for storefront account
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil23 committed May 27, 2024
1 parent 752e522 commit 8ecd51a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/page-objects/StorefrontPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { CheckoutFinish } from './storefront/CheckoutFinish';
import { CheckoutRegister } from './storefront/CheckoutRegister';
import { Account } from './storefront/Account';
import { AccountLogin } from './storefront/AccountLogin';
import { AccountProfile } from './storefront/AccountProfile';
import { AccountOrder } from './storefront/AccountOrder';
import { AccountAddresses } from './storefront/AccountAddresses';
import { AccountPayment } from './storefront/AccountPayment';
import { Search } from './storefront/Search';
import { SearchSuggest } from './storefront/SearchSuggest';

Expand All @@ -24,7 +27,10 @@ export interface StorefrontPageTypes {
StorefrontCheckoutRegister: CheckoutRegister;
StorefrontAccount: Account;
StorefrontAccountLogin: AccountLogin;
StorefrontAccountProfile: AccountProfile;
StorefrontAccountOrder: AccountOrder;
StorefrontAccountAddresses: AccountAddresses;
StorefrontAccountPayment: AccountPayment;
StorefrontSearch: Search;
StorefrontSearchSuggest: SearchSuggest;
}
Expand All @@ -39,7 +45,10 @@ export const StorefrontPageObjects = {
CheckoutRegister,
Account,
AccountLogin,
AccountProfile,
AccountOrder,
AccountAddresses,
AccountPayment,
Search,
SearchSuggest,
}
Expand Down Expand Up @@ -82,10 +91,22 @@ export const test = base.extend<FixtureTypes>({
await use(new AccountLogin(StorefrontPage));
},

StorefrontAccountProfile: async ({ StorefrontPage }, use) => {
await use(new AccountProfile(StorefrontPage));
},

StorefrontAccountOrder: async ({ StorefrontPage }, use) => {
await use(new AccountOrder(StorefrontPage));
},

StorefrontAccountAddresses: async ({ StorefrontPage }, use) => {
await use(new AccountAddresses(StorefrontPage));
},

StorefrontAccountPayment: async ({ StorefrontPage }, use) => {
await use(new AccountPayment(StorefrontPage));
},

StorefrontSearch: async ({ StorefrontPage }, use) => {
await use(new Search(StorefrontPage));
},
Expand Down
10 changes: 10 additions & 0 deletions src/page-objects/storefront/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import type { PageObject } from '../../types/PageObject';
export class Account implements PageObject {
public readonly headline: Locator;
public readonly personalDataCardTitle: Locator;
public readonly paymentMethodCardTitle: Locator;
public readonly billingAddressCardTitle: Locator;
public readonly shippingAddressCardTitle: Locator;
public readonly newsletterCheckbox: Locator;
public readonly newsletterRegistrationSuccessMessage: Locator;

constructor(public readonly page: Page) {
this.headline = page.getByRole('heading', { name: 'Overview' });
this.personalDataCardTitle = page.getByRole('heading', { name: 'Personal data' });
this.paymentMethodCardTitle = page.getByRole('heading', { name: 'Default payment method' });
this.billingAddressCardTitle = page.getByRole('heading', { name: 'Default billing address' });
this.shippingAddressCardTitle = page.getByRole('heading', { name: 'Default shipping address' });
this.newsletterCheckbox = page.getByLabel('Yes, I would like to');
this.newsletterRegistrationSuccessMessage = page.getByText('You have successfully subscribed to the newsletter.');
}

async goTo() {
Expand Down
22 changes: 22 additions & 0 deletions src/page-objects/storefront/AccountAddresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';

export class AccountAddresses implements PageObject {
public readonly addNewAddressButton: Locator;
public readonly editBillingAddressButton: Locator;
public readonly editShippingAddressButton: Locator;
public readonly useDefaultBillingAddressButton: Locator;
public readonly useDefaultShippingAddressButton: Locator;

constructor(public readonly page: Page) {
this.addNewAddressButton = page.getByRole('link', { name: 'Add new address' });
this.editBillingAddressButton = page.getByRole('link', { name: 'Edit address' }).first();
this.editShippingAddressButton = page.getByRole('link', { name: 'Edit address' }).nth(1);
this.useDefaultBillingAddressButton = page.getByRole('button', { name: 'Use as default billing address' });
this.useDefaultShippingAddressButton = page.getByRole('button', { name: 'Use as default shipping address' });
}

async goTo() {
await this.page.goto('account/address');
}
}
20 changes: 20 additions & 0 deletions src/page-objects/storefront/AccountPayment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';

export class AccountPayment implements PageObject {
public readonly cashOnDeliveryOption: Locator;
public readonly paidInAdvanceOption: Locator;
public readonly invoiceOption: Locator;
public readonly changeDefaultPaymentButton: Locator;

constructor(public readonly page: Page) {
this.cashOnDeliveryOption = page.getByLabel('Cash on delivery');
this.paidInAdvanceOption = page.getByLabel('Paid in advance');
this.invoiceOption = page.getByLabel('Invoice');
this.changeDefaultPaymentButton = page.getByRole('button', { name: 'Change' });
}

async goTo() {
await this.page.goto('account/payment');
}
}
44 changes: 44 additions & 0 deletions src/page-objects/storefront/AccountProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';

export class AccountProfile implements PageObject {
public readonly salutationSelect: Locator;
public readonly firstNameInput: Locator;
public readonly lastNameInput: Locator;
public readonly saveProfileButton: Locator;

public readonly changeEmailButton: Locator;
public readonly emailAddressInput: Locator;
public readonly emailAddressConfirmInput: Locator;
public readonly emailConfirmPasswordInput: Locator;
public readonly saveEmailAddressButton: Locator;

public readonly changePasswordButton: Locator;
public readonly newPasswordInput: Locator;
public readonly newPasswordConfirmInput: Locator;
public readonly currentPasswordInput: Locator;
public readonly saveNewPasswordButton: Locator;

constructor(public readonly page: Page) {
this.salutationSelect = page.getByLabel('Salutation');
this.firstNameInput = page.getByPlaceholder('Enter first name...');
this.lastNameInput = page.getByPlaceholder('Enter last name...');
this.saveProfileButton = page.locator('#profilePersonalForm').getByRole('button', { name: 'Save changes' })

this.changeEmailButton = page.getByRole('button', { name: 'Change email address' });
this.emailAddressInput = page.getByPlaceholder('Enter email address...');
this.emailAddressConfirmInput = page.getByPlaceholder('Enter your email address once again...');
this.emailConfirmPasswordInput = page.getByPlaceholder('Enter password...');
this.saveEmailAddressButton = page.locator('#profileMailForm').getByRole('button', { name: 'Save changes' });

this.changePasswordButton = page.getByRole('button', { name: 'Change password' });
this.newPasswordInput = page.getByPlaceholder('Enter new password...');
this.newPasswordConfirmInput = page.getByPlaceholder('Enter your new password once again...');
this.currentPasswordInput = page.getByPlaceholder('Enter current password...');
this.saveNewPasswordButton = page.locator('#profilePasswordForm').getByRole('button', { name: 'Save changes' });
}

async goTo() {
await this.page.goto('account/profile');
}
}

0 comments on commit 8ecd51a

Please sign in to comment.