Skip to content

Commit

Permalink
Merge pull request #283 from shopware/next-40281/search-product-in-st…
Browse files Browse the repository at this point in the history
…orefront

fix: add searchForTerm task to customer and fix Homepage locator
  • Loading branch information
ocavli authored Jan 24, 2025
2 parents 776a1f4 + 7be4b6f commit 1c41f15
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/page-objects/storefront/Home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Home implements PageObject {
this.accountMenuButton = page.getByLabel('Your account');
this.closeGuestSessionButton = page.locator('.account-aside-btn');
this.productImages = page.locator('.product-image-wrapper');
this.productListItems = page.getByRole('listitem');
this.productListItems = page.locator('.product-box');
this.languagesDropdown = page.locator('.top-bar-language').filter({ has: page.getByRole('button') });
this.languagesMenuOptions = page.locator('.top-bar-language').filter({ has: page.getByRole('list') });
this.currenciesDropdown = page.locator('.top-bar-currency').filter({ has: page.getByRole('button') });
Expand Down
18 changes: 12 additions & 6 deletions src/page-objects/storefront/SearchSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ import type { PageObject } from '../../types/PageObject';
import { Home } from './Home';

export class SearchSuggest extends Home implements PageObject {

public readonly searchSuggestLineItemImages: Locator;
public readonly searchInput: Locator;
public readonly searchIcon: Locator;
public readonly searchSuggestNoResult: Locator;
public readonly searchSuggestLineItemName: Locator;
public readonly searchSuggestLineItemPrice: Locator;
public readonly searchSuggestTotalLink: Locator;
public readonly searchResultTotal: Locator;
public readonly searchHeadline: Locator;

constructor(public readonly page: Page) {
super(page);
this.searchSuggestLineItemImages = page.locator('.search-suggest-product-image-container');
this.searchInput = page.locator('.header-search-input');
this.searchIcon = page.locator('.header-search-icon');
this.searchSuggestNoResult = page.locator ('.search-suggest-no-result');
this.searchSuggestLineItemName = page.locator ('.search-suggest-product-name');
this.searchSuggestLineItemPrice = page.locator ('.col-auto.search-suggest-product-price');
this.searchSuggestTotalLink = page.locator ('.search-suggest-total-link');
this.searchHeadline = page.locator ('.search-headline');
this.searchSuggestNoResult = page.locator('.search-suggest-no-result');
this.searchSuggestLineItemName = page.locator('.search-suggest-product-name');
this.searchSuggestLineItemPrice = page.locator('.col-auto.search-suggest-product-price');
this.searchSuggestTotalLink = page.locator('.search-suggest-total-link');
this.searchResultTotal = page.locator('.search-suggest-total-count');
this.searchHeadline = page.locator('.search-headline');
}

async getTotalSearchResultCount(): Promise<number> {
const totalCountText = await this.searchResultTotal.textContent();
return parseInt(totalCountText?.trim().replace(/\D/g, '') || '0', 10);
}

url(searchTerm?: string) {
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/shop-customer-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Register } from './shop-customer/Account/Register';
import { RegisterGuest } from './shop-customer/Account/RegisterGuest';
import { ChangeStorefrontCurrency } from './shop-customer/Account/ChangeStorefrontCurrency';


import { AddProductToCart } from './shop-customer/Product/AddProductToCart';
import { ProceedFromProductToCheckout } from './shop-customer/Product/ProceedFromProductToCheckout';

Expand All @@ -22,6 +21,7 @@ import { SubmitOrder } from './shop-customer/Checkout/SubmitOrder';

import { OpenSearchResultPage } from './shop-customer/Search/OpenSearchResultPage';
import { OpenSearchSuggestPage } from './shop-customer/Search/OpenSearchSuggestPage';
import { SearchForTerm } from './shop-customer/Search/SearchForTerm';

import { ValidateAccessibility } from './shop-customer/Accessibility/ValidateAccessibility';

Expand All @@ -44,5 +44,6 @@ export const test = mergeTests(
SubmitOrder,
OpenSearchResultPage,
OpenSearchSuggestPage,
ValidateAccessibility,
);
SearchForTerm,
ValidateAccessibility
);
16 changes: 16 additions & 0 deletions src/tasks/shop-customer/Search/SearchForTerm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test as base } from '@playwright/test';
import type { Task } from '../../../types/Task';
import type { FixtureTypes } from '../../../types/FixtureTypes';

export const SearchForTerm = base.extend<{ SearchForTerm: Task }, FixtureTypes>({
SearchForTerm: async ({ StorefrontSearchSuggest }, use) => {
const task = (searchTerm: string) => {
return async function SearchForTerm() {
await StorefrontSearchSuggest.searchInput.fill(searchTerm);
await StorefrontSearchSuggest.page.waitForResponse((response) => response.url().includes(`suggest?search=${searchTerm}`) && response.ok());
};
};

await use(task);
},
});

0 comments on commit 1c41f15

Please sign in to comment.