Skip to content

Getproduct description updated. #18

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 3 commits into from
Jun 23, 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
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import createCustomLogger from "./logger/logger";
const logger = createCustomLogger();

export const config: LaunchOptions = {
timeout: 600000,
timeout: 150000,
headless: true,
// args:['--window-position=-1070,-100'], //* customized for left-sided portrait monitor.
slowMo: 300,
Expand Down
4 changes: 2 additions & 2 deletions src/test/features/UserShopping.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Verify that the user is able to purchase some item.
Scenario: User shops for Men Jackets.
When The user clicks on the "<Section>" section and the user clicks on "<Attire>" option.
And The products are shown and user navigates to a product.
And The price, size of that product is shown.
And The details of the product are shown.

Examples:
| Section | Attire |
Expand All @@ -21,7 +21,7 @@ Feature: Verify that the user is able to purchase some item.
Scenario: User shops for Women Jackets.
When The user clicks on the "<Section>" section and the user clicks on "<Attire>" option.
And The products are shown and user navigates to a product.
And The price, size of that product is shown.
And The details of the product are shown.

Examples:
| Section | Attire |
Expand Down
2 changes: 1 addition & 1 deletion src/test/hooks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let context: BrowserContext;

BeforeAll(async function () {
pageFixture.logger = createCustomLogger();
pageFixture.logger.info('----------------- New Test Run -----------------');
pageFixture.logger.info('----------------- New Test Run -----------------' + "\n");
browser = await chromium.launch(config);
});

Expand Down
42 changes: 28 additions & 14 deletions src/test/pages/UserShopping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Page, expect } from "@playwright/test";
export class CategoryAndProductSelectionFacade{
private userShopping: UserShopping;

constructor(menSection: UserShopping){
this.userShopping = menSection;
constructor(userShopping: UserShopping){
this.userShopping = userShopping;
};

public async productSelection(section: string, attire: string){
Expand All @@ -22,6 +22,11 @@ import { Page, expect } from "@playwright/test";
await this.userShopping.showItems();
await this.userShopping.selectRandomProduct();
};

public async showProductDetails(){
await this.userShopping.getProductPriceAndSizes();
await this.userShopping.selectAndGetProductColors()
};
};

export class UserShopping {
Expand All @@ -30,7 +35,7 @@ import { Page, expect } from "@playwright/test";
};

userShoppingLocators = {
menSectionHeader:() => pageFixture.page.locator(getResource('menSectionBtn').selectorValue),
shoppingSectionHeader:() => pageFixture.page.locator(getResource('shoppingSectionHeader').selectorValue),
attireSectionBtn:() => pageFixture.page.locator(getResource('attireSectionBtn').selectorValue),
itemsShown:() => pageFixture.page.locator(getResource('itemsShown').selectorValue),
attireSectionOptions:() => pageFixture.page.locator(getResource('attireSectionOptions').selectorValue),
Expand All @@ -42,11 +47,12 @@ import { Page, expect } from "@playwright/test";
getProductSizesAvailable:() => pageFixture.page.locator(getResource('getProductSizesAvailable').selectorValue),
getCurrentSelectedColor:() => pageFixture.page.locator(getResource('getCurrentSelectedColor').selectorValue),
getColorSwatches:() => pageFixture.page.locator(getResource('getColorSwatches').selectorValue),
getSelectedProductSize:() => pageFixture.page.locator(getResource('getSelectedProductSize').selectorValue)

};

public async goSectionAndAttire(section: string, attire: string):Promise<void>{
const el = pageFixture.page.locator(getResource('menSectionBtn').selectorValue.replace('FLAG', section));
const el = pageFixture.page.locator(getResource('shoppingSectionHeader').selectorValue.replace('FLAG', section));
await el.click();
for(let i=0;i<=0;i++){
const el = await pageFixture.page.locator(getResource('attireSectionBtn').selectorValue.replace('FLAG', attire));
Expand All @@ -56,19 +62,20 @@ import { Page, expect } from "@playwright/test";

public async showItems():Promise<void>{
const getNumberOfProducts = await this.userShoppingLocators.productShown().count();
process.stdout.write(' Products shown -> ' + getNumberOfProducts + '\n');
console.log(' Products shown -> ' + getNumberOfProducts + '\n');
for(let i=1;i<=getNumberOfProducts;i++){
const getEl = await pageFixture.page.locator(getResource('itemsShown').selectorValue.replace('FLAG', i.toString())).allTextContents();
for (const text of getEl) {
console.log(''+i +")" + " " + text.trim());
//console.log(''+i +")" + " " + '\u001b[34m',text.trim());
console.log(''+i +")" + " " + '\x1b[36m%s\x1b[0m',text.trim());
};
};
};

public async selectRandomProduct():Promise<void>{
const getNumberOfProducts = await this.userShoppingLocators.productShown().count();
let ind: number = Math.floor(Math.random() * (getNumberOfProducts - 1))+ 1;

if (ind == 0) {
Math.floor(Math.random() * getNumberOfProducts);
} else {
Expand All @@ -78,7 +85,7 @@ import { Page, expect } from "@playwright/test";
const list = await this.userShoppingLocators.shoppingList().isVisible();
const listCount = await this.userShoppingLocators.shoppingList().count();
if (list == true){
pageFixture.logger.error('User not navigated, retrying click');
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});
Expand All @@ -92,22 +99,27 @@ import { Page, expect } from "@playwright/test";
public async getProductPriceAndSizes():Promise<void>{
const priceText = (await this.userShoppingLocators.productPrice().textContent()).trim();
if(await this.userShoppingLocators.productPrice().isVisible() == true){
pageFixture.logger.error('Product price is not visible, attempting to click product again.')
pageFixture.logger.warn('Product price is not visible, attempting to click product again.')
const regEx = /\$\d+\.\d{2}/;
const matchPriceText = priceText.match(regEx);
console.log("The price of the product -> "+matchPriceText[0]);
const sizeText = (await this.userShoppingLocators.productSize().textContent()).trim();
const getSizes = await this.userShoppingLocators.getProductSizesAvailable().count();
console.log(sizeText+'s' + ' available are: ');
console.log('\x1b[36m%s\x1b[0m',sizeText+'s' + ' available are: ');
for(let i=1;i<=getSizes;i++){
const el = await pageFixture.page.locator(getResource('getProductSize').selectorValue.replace('FLAG', i.toString())).allTextContents();
for (const text of el) {
console.log(''+i +")" + " " + text.trim());
console.log(''+i +")" + " " + '\x1b[36m%s\x1b[0m',text.trim());
};
}
} else {
} else {
return this.selectRandomProduct();
}
};
const getSizes = await this.userShoppingLocators.getProductSizesAvailable().count();
let ind: number = Math.floor(Math.random() * (getSizes - 1))+ 1;
const sizeEl = (pageFixture.page.locator(getResource('getProductSize').selectorValue.replace('FLAG', `${ind}`)));
await sizeEl.click();
console.log("Size selected: "+await this.userShoppingLocators.getSelectedProductSize().textContent());
};

public async selectAndGetProductColors():Promise<void>{
Expand All @@ -121,7 +133,9 @@ import { Page, expect } from "@playwright/test";
await colorToBeSelect.click();
await this.userShoppingLocators.getCurrentSelectedColor().isVisible();
const getColor = await this.userShoppingLocators.getCurrentSelectedColor().textContent();
console.log(getColor);
console.log('Selected color: ' +getColor);
};
};


};
6 changes: 5 additions & 1 deletion src/test/resources/userShoppingPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"webElements": [

{
"elementName": "menSectionBtn",
"elementName": "shoppingSectionHeader",
"selectorValue": "//span[contains(.,'FLAG')]"
},
{
Expand Down Expand Up @@ -38,6 +38,10 @@
"elementName": "getProductSize",
"selectorValue": "//div[contains(@class,'swatch-option text')][FLAG]"
},
{
"elementName": "getSelectedProductSize",
"selectorValue": "//div[contains(@class,'swatch-attribute size')]//span[2]"
},
{
"elementName": "getProductSizesAvailable",
"selectorValue": "//div[contains(@class,'swatch-option text')]"
Expand Down
5 changes: 2 additions & 3 deletions src/test/steps/userShopping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ When("The products are shown and user navigates to a product.", async function (
await categoryAndProductSectionFacade.selectRandomItem();
});

When("The price, size of that product is shown.", async function (){
await userShopping.getProductPriceAndSizes();
await userShopping.selectAndGetProductColors();
When("The details of the product are shown.", async function (){
await categoryAndProductSectionFacade.showProductDetails();
});
Loading