Skip to content

Random item selection added #7

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 2 commits into from
Jun 18, 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
5 changes: 4 additions & 1 deletion src/test/features/UserShopping.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ Feature: Verify that the user is able to purchase some item.
Background: User is landed on the webpage.
Given The user lands at the webpage.

@MenShopping
Scenario: User shops for Men Jackets.
When The user clicks on the "<Section>" section.
And The user clicks on "<Attire>" option.
Then The products are shown.
And The products are shown.
And User navigates to a product.

Examples:
| Section | Attire |
| Men | Tees |

@WomenShopping
Scenario: User shops for Women Jackets.
When The user clicks on the "<Section>" section.
And The user clicks on "<Attire>" option.
Expand Down
32 changes: 9 additions & 23 deletions src/test/pages/UserShopping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,26 @@ export class MenSection {
const el = await pageFixture.page.locator(getResource('attireSectionBtn').selectorValue.replace('FLAG', attire));
await el.click();
};
// for (let i=0;i<=getAttireOptions;i++){
// console.log(getAttireOptions);
// };
// const getCountAttire = pageFixture.page.locator(getResource('attireSectionBtn').selectorValue.replace('FLAG', attire))
// await this.menSectionLocators.menAttire().innerText().then(value => console.log(value))
// const el = await expect(this.menSectionLocators.menAttire()).toContainText(attire).then(value => console.log(value))
// console.log(el)
};

public async showItems():Promise<void>{
const getNumberOfProducts = await this.menSectionLocators.productShown().count();
process.stdout.write(' 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) {
// const firstLine = text.split('\n')[1].trim();
// const getItem = await getEl;
// process.stdout.write(` ${firstLine}${getItem}`);
// };
for (const text of getEl) {
// const getItem = await getEl;
// process.stdout.write(` Item ${i} -> ${getItem}${firstLine}\n`);
console.log(' '+i +")" + " " + text.trim());
};

// console.log(getEl)
};


// for(let i=0;i<=getNumberOfProducts;i++){
// await pageFixture.page.locator(getResource('productsShown').selectorValue.replace('FLAG', i.toString())).textContent();
// const showCount = await this.menSectionLocators.itemsShown().textContent();
// console.log(showCount);
// };
};

public async selecRandomItem():Promise<void>{
const getNumberOfProducts = await this.menSectionLocators.productShown().count();
let ind: number = Math.floor(Math.random() * getNumberOfProducts);
if (ind == 0) {
Math.floor(Math.random() * getNumberOfProducts);
} else {
await pageFixture.page.locator(getResource('itemsShown').selectorValue.replace('FLAG', `${ind}`)).dblclick();
};
};
};
6 changes: 5 additions & 1 deletion src/test/steps/userShopping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ When("The user clicks on {string} option.", async function (attire: string){
await menSection.goToAttire(attire);
});

Then("The products are shown.", async function (){
When("The products are shown.", async function (){
await menSection.showItems();
});

When("User navigates to a product.", async function (){
await menSection.selecRandomItem();
});
Loading