Skip to content
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

feat: create storefront wishlist page and wishlist tasks #295

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion src/page-objects/StorefrontPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SearchSuggest } from './storefront/SearchSuggest';
import { CustomRegister } from './storefront/CustomRegister';
import { CheckoutOrderEdit } from './storefront/CheckoutOrderEdit';
import { AccountAddressCreate } from './storefront/AccountAddresssCreate';
import { Wishlist } from './storefront/Wishlist';

export interface StorefrontPageTypes {
StorefrontHome: Home;
Expand All @@ -43,6 +44,7 @@ export interface StorefrontPageTypes {
StorefrontSearchSuggest: SearchSuggest;
StorefrontCustomRegister: CustomRegister;
StorefrontCheckoutOrderEdit: CheckoutOrderEdit;
StorefrontWishlist: Wishlist;
}

export const StorefrontPageObjects = {
Expand All @@ -66,6 +68,7 @@ export const StorefrontPageObjects = {
SearchSuggest,
CustomRegister,
CheckoutOrderEdit,
Wishlist,
}

export const test = base.extend<FixtureTypes>({
Expand Down Expand Up @@ -144,10 +147,13 @@ export const test = base.extend<FixtureTypes>({

StorefrontCustomRegister: async ({ StorefrontPage }, use) => {
await use(new CustomRegister(StorefrontPage));

},

StorefrontCheckoutOrderEdit: async ({ StorefrontPage }, use) => {
await use(new CheckoutOrderEdit(StorefrontPage));
},

StorefrontWishlist: async ({ StorefrontPage }, use) => {
await use(new Wishlist(StorefrontPage));
},
});
17 changes: 16 additions & 1 deletion src/page-objects/storefront/Home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
public readonly consentCookieBannerContainer: Locator;
public readonly offcanvasBackdrop: Locator;

//wishlist
public readonly wishlistIcon: Locator;
public readonly wishlistBasket: Locator;

constructor(public readonly page: Page) {
this.accountMenuButton = page.getByLabel('Your account');
this.closeGuestSessionButton = page.locator('.account-aside-btn');
Expand Down Expand Up @@ -63,6 +67,11 @@
exact: true,
});
this.offcanvasBackdrop = page.locator('.offcanvas-backdrop');

//wishlist
this.wishlistIcon = page.locator('.header-wishlist-icon');
this.wishlistBasket = page.locator('.header-wishlist-badge');
this.contactFormLink = this.page.getByRole('listitem').getByTitle('Contact form', { exact: true });

Check failure on line 74 in src/page-objects/storefront/Home.ts

View workflow job for this annotation

GitHub Actions / build

Property 'contactFormLink' does not exist on type 'Home'.
Copy link
Contributor

Choose a reason for hiding this comment

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

SOemthing went wrong here during the merge or?

}

async getMenuItemByCategoryName(categoryName: string): Promise<Record<string, Locator>> {
Expand Down Expand Up @@ -97,6 +106,9 @@
const productAddToShoppingCart = listingItem.getByRole('button', {
name: 'Add to shopping cart',
});
const wishlistNotAddedIcon = listingItem.locator('.product-wishlist-not-added');
const wishlistAddedIcon = listingItem.locator('.product-wishlist-added');
const removeProductFromWishlist = listingItem.locator('.icon-wishlist-remove');

return {
productImage: productImage,
Expand All @@ -108,10 +120,13 @@
productPrice: productPrice,
productName: productName,
productAddToShoppingCart: productAddToShoppingCart,
wishlistNotAddedIcon: wishlistNotAddedIcon,
wishlistAddedIcon: wishlistAddedIcon,
removeFromWishlistXButton: removeProductFromWishlist,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
removeFromWishlistXButton: removeProductFromWishlist,
removeFromWishlistButton: removeProductFromWishlist,

};
}

url() {
return './';
}
}
}
34 changes: 34 additions & 0 deletions src/page-objects/storefront/Wishlist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';
import { Home } from './Home';

export class Wishlist extends Home implements PageObject {
public readonly wishListHeader: Locator;
public readonly removeAlert: Locator;
public readonly emptyListing: Locator;

public readonly offCanvas: Locator;
public readonly offCanvasCartTitle: Locator;
public readonly offCanvasCart: Locator;
public readonly offCanvasCartGoToCheckoutButton: Locator;
public readonly offCanvasLineItemImages: Locator;
public readonly offCanvasSummaryTotalPrice: Locator;
Comment on lines +10 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

You can extend these elements from OffCanvasCart.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

But then he has to extend the whole class... It doesn't make sense logically but technically possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it make more sense to inject the OffCanvasCart fixture in the test instead of defining the locators here in the Whitelist again.


constructor(public readonly page: Page) {
super(page);
this.wishListHeader = page.locator('.wishlist-headline');
this.removeAlert = page.locator('.alert-content');
this.emptyListing = page.locator('.wishlist-listing-empty');

this.offCanvas = page.locator('offcanvas-body');
this.offCanvasCartTitle = page.getByText('Shopping cart', { exact: true });
this.offCanvasCart = page.getByRole('dialog');
this.offCanvasCartGoToCheckoutButton = page.getByRole('link', { name: 'Go to checkout' });
this.offCanvasLineItemImages = page.locator('.line-item-img-link');
this.offCanvasSummaryTotalPrice = page.locator('.offcanvas-summary').locator('dt:has-text("Subtotal") + dd');
}

url() {
return `wishlist`;
}
}
35 changes: 34 additions & 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', 'sales_channel_payment_method', 'customer'];

/**
* A registry of all created records.
Expand Down Expand Up @@ -1212,6 +1212,39 @@ export class TestDataService {
return salesChannel;
}

/**
* Assigns a payment method to a sales channel.
*
* @param salesChannelId - The uuid of the sales channel.
* @param paymentMethodId - The uuid of the currency.
*/
async assignSalesChannelPaymentMethod(salesChannelId: string, paymentMethodId: string) {
const syncSalesChannelResponse = await this.AdminApiClient.post('./_action/sync', {
data: {
'write-sales-channel-payment-method': {
entity: 'sales_channel_payment_method',
action: 'upsert',
payload: [
{
salesChannelId: salesChannelId,
paymentMethodId: paymentMethodId,
},
],
},
},
});
expect(syncSalesChannelResponse.ok()).toBeTruthy();

const { data: salesChannel } = await syncSalesChannelResponse.json();

this.addCreatedRecord('sales_channel_payment_method', {
salesChannelId: salesChannelId,
paymentMethodId: paymentMethodId,
});

return salesChannel;
}

/**
* Assigns a media resource to a payment method as a logo.
*
Expand Down
6 changes: 5 additions & 1 deletion src/tasks/shop-customer-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { OpenSearchSuggestPage } from './shop-customer/Search/OpenSearchSuggestP
import { SearchForTerm } from './shop-customer/Search/SearchForTerm';

import { ValidateAccessibility } from './shop-customer/Accessibility/ValidateAccessibility';
import { AddProductToCartFromWishlist, AddProductToWishlist, RemoveProductFromWishlist } from './shop-customer/Wishlist/WishlistActions';

export const test = mergeTests(
Login,
Expand All @@ -45,5 +46,8 @@ export const test = mergeTests(
OpenSearchResultPage,
OpenSearchSuggestPage,
SearchForTerm,
ValidateAccessibility
ValidateAccessibility,
RemoveProductFromWishlist,
AddProductToCartFromWishlist,
AddProductToWishlist
);
48 changes: 48 additions & 0 deletions src/tasks/shop-customer/Wishlist/WishlistActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test as base } from '@playwright/test';
import type { Task } from '../../../types/Task';
import type { FixtureTypes } from '../../../types/FixtureTypes';
import { Product } from '../../../types/ShopwareTypes';

export const AddProductToCartFromWishlist = base.extend<{ AddProductToCartFromWishlist: Task }, FixtureTypes>({
AddProductToCartFromWishlist: async ({ ShopCustomer, StorefrontWishlist }, use) => {
const task = (ProductData: Product) => {
return async function AddProductToCart() {
const listedItem = await StorefrontWishlist.getListingItemByProductId(ProductData.id);
await listedItem.productAddToShoppingCart.click();
await StorefrontWishlist.page.waitForResponse((response) => response.url().includes(`checkout/offcanvas`) && response.ok());
await ShopCustomer.expects(StorefrontWishlist.offCanvasCartTitle).toBeVisible();
await ShopCustomer.expects(StorefrontWishlist.offCanvasCart.getByText(ProductData.name)).toBeVisible();
}
};

await use(task);
},
});

export const RemoveProductFromWishlist = base.extend<{ RemoveProductFromWishlist: Task }, FixtureTypes>({
RemoveProductFromWishlist: async ({ StorefrontHome , StorefrontWishlist}, use) => {
const task = (ProductData: Product) => {
return async function AddProductToWishlist() {
const listedItem = await StorefrontHome.getListingItemByProductId(ProductData.id);
await listedItem.wishlistAddedIcon.click();
await StorefrontWishlist.page.waitForResponse((response) => response.url().includes(`remove/${ProductData.id}`) && response.ok());
}
};

await use(task);
},
});

export const AddProductToWishlist = base.extend<{ AddProductToWishlist: Task }, FixtureTypes>({
AddProductToWishlist: async ({ StorefrontHome , ShopCustomer}, use) => {
const task = (ProductData: Product) => {
return async function AddProductToWishlist() {
const listedItem = await StorefrontHome.getListingItemByProductId(ProductData.id);
await listedItem.wishlistNotAddedIcon.click();
await ShopCustomer.expects(listedItem.wishlistAddedIcon).toBeVisible();
}
};

await use(task);
},
});
Loading