From 2d7b3cda9453f32d8238cee9cb0e851ad9737a3e Mon Sep 17 00:00:00 2001 From: najeeb1023 Date: Mon, 24 Jun 2024 23:42:49 +0200 Subject: [PATCH] fix: removed getProduct function and declared a globalArray to fetch and search the same product. --- src/test/features/ShopBySearch.feature | 2 +- src/test/pages/ShopBySearch.ts | 11 +++++------ src/test/pages/UserShoppingByWear.ts | 10 ++++------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/test/features/ShopBySearch.feature b/src/test/features/ShopBySearch.feature index db617bb..7653e6f 100644 --- a/src/test/features/ShopBySearch.feature +++ b/src/test/features/ShopBySearch.feature @@ -1,4 +1,4 @@ -@ShopyBySearch +@ShopBySearch Feature: Verify that the user is able to purchase an item by searching. diff --git a/src/test/pages/ShopBySearch.ts b/src/test/pages/ShopBySearch.ts index 9910027..c1c7d50 100644 --- a/src/test/pages/ShopBySearch.ts +++ b/src/test/pages/ShopBySearch.ts @@ -15,10 +15,9 @@ import { pageFixture } from "../hooks/pageFixture"; }; - public async searchProduct():Promise{ - const product: string = await this.saveSelectedProduct(); - console.log('Selected product:', product); - await this.shopBySearchLocators.searchBar().fill(product); // Fill searchBarInput with the actual product name - await pageFixture.page.keyboard.press('Enter'); - }; + public async searchProduct():Promise{ + console.log('Selected product:', UserShoppingByWear.globalArray[0]); + await this.shopBySearchLocators.searchBar().fill(UserShoppingByWear.globalArray[0]); + await pageFixture.page.keyboard.press('Enter'); + }; }; \ No newline at end of file diff --git a/src/test/pages/UserShoppingByWear.ts b/src/test/pages/UserShoppingByWear.ts index f06c209..4ba791c 100644 --- a/src/test/pages/UserShoppingByWear.ts +++ b/src/test/pages/UserShoppingByWear.ts @@ -40,7 +40,7 @@ import { Page, expect } from "@playwright/test"; pageFixture.page = page; }; - // public static savedProductName:string; + public static globalArray: string[] = []; userShoppingByWearByWearLocators = { shoppingSectionHeader:() => pageFixture.page.locator(getResource('shoppingSectionHeader').selectorValue), @@ -104,11 +104,9 @@ import { Page, expect } from "@playwright/test"; await pageFixture.logger.info('User navigated successfully.') }; }; - }; - - public async saveSelectedProduct():Promise{ - const productName = (await (this.userShoppingByWearByWearLocators.pageTitle().textContent())).trim(); - return productName; + const productName = await this.userShoppingByWearByWearLocators.pageTitle().innerText(); + UserShoppingByWear.globalArray.push(productName) + return console.log('inside the selectRandomProductFunction', UserShoppingByWear.globalArray) }; public async getProductPriceAndSizes():Promise{