Skip to content

Commit

Permalink
feat: add new address
Browse files Browse the repository at this point in the history
  • Loading branch information
vanpham-sw committed Feb 4, 2025
1 parent b58761b commit 78537bd
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/page-objects/storefront/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class Account implements PageObject {
public readonly newsletterCheckbox: Locator;
public readonly newsletterRegistrationSuccessMessage: Locator;
public readonly customerGroupRequestMessage: Locator;

public readonly cannotDeliverToCountryAlert: Locator;
public readonly shippingToAddressNotPossibleAlert: Locator;
constructor(public readonly page: Page, public readonly instanceMeta: HelperFixtureTypes['InstanceMeta']) {
this.headline = page.getByRole('heading', { name: 'Overview' });
this.personalDataCardTitle = page.getByRole('heading', { name: 'Personal data' });
Expand All @@ -27,7 +28,9 @@ export class Account implements PageObject {
} else {
this.customerGroupRequestMessage = page.locator('.alert-content-container');
}

this.cannotDeliverToCountryAlert = page.getByText('We can not deliver to the country that is stored in your delivery address.');
this.shippingToAddressNotPossibleAlert = page.getByText('Shipping to the selected shipping address is currently not possible.');

}

async getCustomerGroupAlert(customerGroup: string): Promise<Locator> {
Expand Down
5 changes: 5 additions & 0 deletions src/page-objects/storefront/AccountAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ export class AccountAddresses implements PageObject {
public readonly editShippingAddressButton: Locator;
public readonly useDefaultBillingAddressButton: Locator;
public readonly useDefaultShippingAddressButton: Locator;
public readonly deliveryNotPossibleAlert: Locator;
public readonly otherAddressInfo: 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' });
const otherAddress = page.locator('.other-address');
this.deliveryNotPossibleAlert = otherAddress.getByText('A delivery to this country is not possible.');
this.otherAddressInfo = otherAddress.locator('.address').nth(1);
}

url() {
Expand Down
2 changes: 2 additions & 0 deletions src/page-objects/storefront/AccountAddresssCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class AccountAddressCreate implements PageObject {
public readonly cityInput: Locator;
public readonly countryDropdown: Locator;
public readonly saveAddressButton: Locator;
public readonly stateDropdown: Locator;

constructor(public readonly page: Page) {
this.salutationDropdown = page.locator('#addresspersonalSalutation');
Expand All @@ -23,6 +24,7 @@ export class AccountAddressCreate implements PageObject {
this.zipcodeInput = page.locator('#addressAddressZipcode');
this.cityInput = page.locator('#addressAddressCity');
this.countryDropdown = page.locator('#addressAddressCountry');
this.stateDropdown = page.locator('#addressAddressCountryState');
this.saveAddressButton = page.locator('.address-form-submit');
}

Expand Down
27 changes: 27 additions & 0 deletions src/page-objects/storefront/AccountLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export class AccountLogin implements PageObject {
public readonly postalCodeInput: Locator;
public readonly registerButton: Locator;

//Input for shipping address
public readonly differentShippingAddressCheckbox: Locator;
public readonly registerShippingAddressFormArea: Locator;
public readonly shippingAddressSalutationSelect: Locator;
public readonly shippingAddressFirstNameInput: Locator;
public readonly shippingAddressLastNameInput: Locator;
public readonly shippingAddressStreetAddressInput: Locator;
public readonly shippingAddressCityInput: Locator;
public readonly shippingAddressCountryInput: Locator;
public readonly shippingAddressPostalCodeInput: Locator;
public readonly shippingAddressStateInput: Locator;


constructor(public readonly page: Page) {
this.emailInput = page.getByLabel('Your email address');
this.passwordInput = page.getByLabel('Your password');
Expand All @@ -52,10 +65,24 @@ export class AccountLogin implements PageObject {
this.cityInput = this.billingAddressFormArea.getByLabel('City');
this.countryInput = this.billingAddressFormArea.getByLabel('Country');
this.postalCodeInput = this.billingAddressFormArea.getByLabel('Postal code');
this.differentShippingAddressCheckbox = page.getByRole('checkbox', { name: 'Shipping and billing address do not match.' });
this.registerShippingAddressFormArea = page.locator('.register-shipping');
this.shippingAddressSalutationSelect = this.registerShippingAddressFormArea.locator('.form-group').filter({ has: page.getByLabel('Salutation') }).locator('.form-select');
this.shippingAddressFirstNameInput = this.registerShippingAddressFormArea.getByLabel('First name');
this.shippingAddressLastNameInput = this.registerShippingAddressFormArea.getByLabel('Last name');
this.shippingAddressStreetAddressInput = this.registerShippingAddressFormArea.getByLabel('Street address');
this.shippingAddressCityInput = this.registerShippingAddressFormArea.getByLabel('City');
this.shippingAddressCountryInput = this.registerShippingAddressFormArea.getByLabel('Country');
this.shippingAddressPostalCodeInput = this.registerShippingAddressFormArea.getByLabel('Postal code');
this.shippingAddressStateInput = this.registerShippingAddressFormArea.getByLabel('State');
this.registerButton = page.getByRole('button', { name: 'Continue' });
this.logoutLink = page.getByRole('link', { name: 'Log out'});
this.successAlert = page.getByText('Successfully logged out.');
this.passwordUpdatedAlert = page.getByText('Your password has been updated.');
}

async getShippingCountryLocatorByName(countryName: string): Promise<Locator> {
return this.shippingAddressCountryInput.locator('option').filter({ hasText: countryName });
}

url() {
Expand Down
2 changes: 1 addition & 1 deletion src/services/TestDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class TestDataService {
*
* @private
*/
private highPriorityEntities = ['order', 'product', 'landing_page', 'shipping_method', 'sales_channel_domain', 'sales_channel_currency', 'sales_channel_country', 'customer'];
private highPriorityEntities = ['order', 'product', 'landing_page', 'shipping_method', 'sales_channel_domain', 'sales_channel_currency', 'sales_channel_country', 'customer', 'customer_address'];

/**
* A registry of all created records.
Expand Down
2 changes: 2 additions & 0 deletions src/tasks/shop-customer-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Logout } from './shop-customer/Account/Logout';
import { Register } from './shop-customer/Account/Register';
import { RegisterGuest } from './shop-customer/Account/RegisterGuest';
import { ChangeStorefrontCurrency } from './shop-customer/Account/ChangeStorefrontCurrency';
import { AddNewAddress } from './shop-customer/Account/AddNewAddress';

import { AddProductToCart } from './shop-customer/Product/AddProductToCart';
import { ProceedFromProductToCheckout } from './shop-customer/Product/ProceedFromProductToCheckout';
Expand All @@ -31,6 +32,7 @@ export const test = mergeTests(
Register,
RegisterGuest,
ChangeStorefrontCurrency,
AddNewAddress,
AddProductToCart,
ChangeProductQuantity,
ProceedFromProductToCheckout,
Expand Down
31 changes: 31 additions & 0 deletions src/tasks/shop-customer/Account/AddNewAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test as base } from '@playwright/test';
import type { Task } from '../../../types/Task';
import type { FixtureTypes} from '../../../types/FixtureTypes';
import { Address } from '../../../types/ShopwareTypes';

export const AddNewAddress = base.extend<{ AddNewAddress: Task }, FixtureTypes>({
AddNewAddress: async ({ ShopCustomer, StorefrontAccountAddresses, StorefrontAccountAddressCreate }, use)=> {
const task = (address: Address) => {
return async function AddNewAddress() {

await ShopCustomer.goesTo(StorefrontAccountAddresses.url());
await StorefrontAccountAddresses.addNewAddressButton.click();

await StorefrontAccountAddressCreate.firstNameInput.fill(address.firstName);
await StorefrontAccountAddressCreate.lastNameInput.fill(address.lastName);
await StorefrontAccountAddressCreate.companyInput.fill(address.company);
await StorefrontAccountAddressCreate.departmentInput.fill(address.department);
await StorefrontAccountAddressCreate.streetInput.fill(address.street);
await StorefrontAccountAddressCreate.zipcodeInput.fill(address.zipCode);
await StorefrontAccountAddressCreate.cityInput.fill(address.city);
await StorefrontAccountAddressCreate.countryDropdown.selectOption({label: address.country});
await StorefrontAccountAddressCreate.stateDropdown.selectOption({label: address.state});

await StorefrontAccountAddressCreate.saveAddressButton.click();

}
};

await use(task);
},
});
19 changes: 18 additions & 1 deletion src/types/ShopwareTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ export type CustomerAddress = components['schemas']['CustomerAddress'] & {
id: string,
}

export interface Address {
salutation: string,
firstName: string,
lastName: string,
company: string,
department: string,
street: string,
city: string,
zipCode: string,
country: string,
state: string,
}

export type Salutation = components['schemas']['Salutation'] & {
id: string,
}
Expand Down Expand Up @@ -106,8 +119,12 @@ export type Currency = components['schemas']['Currency'] & {
id: string,
}

export type Country = components['schemas']['Country'] & {
export type Country = Omit<components['schemas']['Country'], 'states'> & {
id: string,
states: [{
name: string,
shortCode: string,
}],
}

export type SystemConfig = components['schemas']['SystemConfig'] & {
Expand Down

0 comments on commit 78537bd

Please sign in to comment.