Skip to content

select random product refactored #29

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

Merged
merged 1 commit into from
Jun 26, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/test/features/UserShoppingByWear.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Feature: Verify that the user is able to purchase some item.
And The details of the product are shown.

Examples:
| Section | Attire |
| Men | Shorts |
| Section | Attire |
| Men | Jackets |

@WomenShopping
Scenario: User shops for Women Jackets.
Expand Down
45 changes: 24 additions & 21 deletions src/test/pages/UserShoppingByWear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,32 @@ import { Page, expect } from "@playwright/test";
};

public async selectRandomProduct():Promise<any>{
const getNumberOfProducts = await this.userShoppingByWearByWearLocators.productShown().count();
let ind: number = Math.floor(Math.random() * (getNumberOfProducts - 1))+ 1;
if (ind == 0) {
Math.floor(Math.random() * getNumberOfProducts);
} else {
const el = (pageFixture.page.locator(getResource('itemsShown').selectorValue.replace('FLAG', `${ind}`)));
await expect(el).toBeVisible();
await el.dblclick({force: true, timeout: 3000});
const list = await this.userShoppingByWearByWearLocators.shoppingList().isVisible();
const listCount = await this.userShoppingByWearByWearLocators.shoppingList().count();
if (list == true){
await pageFixture.logger.warn('User not navigated, retrying click');
await pageFixture.page.waitForLoadState('networkidle');
for(let i=0;i<listCount;i++){
await el.dblclick({force: true, timeout: 3000});
try {
const getNumberOfProducts = await this.userShoppingByWearByWearLocators.productShown().count();
let ind: number = Math.floor(Math.random() * getNumberOfProducts);
ind = Math.max(ind, 1);
const el = pageFixture.page.locator(getResource('itemsShown').selectorValue.replace('FLAG', `${ind}`));
await expect(el).toBeVisible();
await el.dblclick({ force: true, timeout: 3000 });
const listVisible = await this.userShoppingByWearByWearLocators.shoppingList().isVisible();
if (listVisible) {
await pageFixture.logger.warn('User not navigated, retrying click');
await pageFixture.page.waitForLoadState('networkidle');
const listCount = await this.userShoppingByWearByWearLocators.shoppingList().count();
for (let i = 0; i < listCount; i++) {
await el.dblclick({ force: true, timeout: 3000 });
}
} else {
await pageFixture.logger.info('User navigated successfully.')
};
};
const productName = await this.userShoppingByWearByWearLocators.pageTitle().innerText();
UserShoppingByWear.globalArray.push(productName)
return console.log('inside the selectRandomProductFunction', UserShoppingByWear.globalArray)
await pageFixture.logger.info('User navigated successfully.');
}
const productName = await this.userShoppingByWearByWearLocators.pageTitle().innerText();
UserShoppingByWear.globalArray.push(productName);
console.log('Selected random product: ', UserShoppingByWear.globalArray);
return productName;
} catch (error) {
await pageFixture.logger.error('Random product selection failed', error);
throw error;
}
};

public async getProductPriceAndSizes():Promise<void>{
Expand Down
Loading