diff --git a/src/page-objects/storefront/Home.ts b/src/page-objects/storefront/Home.ts index 82dca9c..ea862f8 100644 --- a/src/page-objects/storefront/Home.ts +++ b/src/page-objects/storefront/Home.ts @@ -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') }); diff --git a/src/page-objects/storefront/SearchSuggest.ts b/src/page-objects/storefront/SearchSuggest.ts index 004d565..128d33c 100644 --- a/src/page-objects/storefront/SearchSuggest.ts +++ b/src/page-objects/storefront/SearchSuggest.ts @@ -3,7 +3,6 @@ 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; @@ -11,6 +10,7 @@ export class SearchSuggest extends Home implements PageObject { 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) { @@ -18,11 +18,17 @@ export class SearchSuggest extends Home implements PageObject { 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 { + const totalCountText = await this.searchResultTotal.textContent(); + return parseInt(totalCountText?.trim().replace(/\D/g, '') || '0', 10); } url(searchTerm?: string) { diff --git a/src/tasks/shop-customer-tasks.ts b/src/tasks/shop-customer-tasks.ts index f9de269..9607263 100644 --- a/src/tasks/shop-customer-tasks.ts +++ b/src/tasks/shop-customer-tasks.ts @@ -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'; @@ -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'; @@ -44,5 +44,6 @@ export const test = mergeTests( SubmitOrder, OpenSearchResultPage, OpenSearchSuggestPage, - ValidateAccessibility, -); \ No newline at end of file + SearchForTerm, + ValidateAccessibility +); diff --git a/src/tasks/shop-customer/Search/SearchForTerm.ts b/src/tasks/shop-customer/Search/SearchForTerm.ts new file mode 100644 index 0000000..5ce0d50 --- /dev/null +++ b/src/tasks/shop-customer/Search/SearchForTerm.ts @@ -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); + }, +});