-
Notifications
You must be signed in to change notification settings - Fork 0
hotSellersSection first test rework #99
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
Open
AlexStefan17
wants to merge
4
commits into
main
Choose a base branch
from
hotSellersSection-rework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
504df1e
hotSellersSection first test rework
AlexStefan17 680a836
added product.details.js and reworked 2nd test from hotSellerSection
AlexStefan17 db60727
tests rework, added utils.js + product.details, update home.page
AlexStefan17 fa02234
updated utils.js and HotSellersSection 2nd test
AlexStefan17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { HomePage } from "../pages/home.page"; | ||
| /** | ||
| * Navigates to the home page and generates a random number between 0 and max (exclusive). | ||
| * @param {Object} homePage - The object representing the home page. | ||
| * @param {number} max - The upper limit for the random number. | ||
| * @returns {Promise<number>} - A promise that resolves to a random number. | ||
| */ | ||
| export async function getRandomNumber(max) { | ||
| return Math.floor(Math.random() * max); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,31 @@ | ||
| export class HomePage { | ||
|
|
||
| constructor(page) { | ||
| this.page = page; | ||
| this.homePageUrl = 'https://magento.softwaretestingboard.com/'; | ||
| this.homePageUrl = "https://magento.softwaretestingboard.com/"; | ||
| } | ||
|
|
||
| // locators | ||
| whatIsNewBTN = () => this.page.locator("#ui-id-3") | ||
| whatIsNewBTN = () => this.page.locator("#ui-id-3"); | ||
| hotSellersProducts = () => this.page.locator(".product-item"); | ||
|
|
||
| async navigateToHomePage() { | ||
| await this.page.goto(this.homePageUrl); | ||
| } | ||
| } | ||
|
|
||
| async getNumberOfHotSellers() { | ||
| return await this.hotSellersProducts().count(); | ||
| } | ||
|
|
||
| async getNameOfHotSeller(hotSellerIndex) { | ||
| const productName = ( | ||
| await this.hotSellersProducts() | ||
| .locator(`nth=${hotSellerIndex}`) | ||
| .innerText() | ||
| ).split("\n")[0]; | ||
| return productName; | ||
| } | ||
|
|
||
| async clickOnHotSellerProduct(indexOfSelector) { | ||
| await this.hotSellersProducts().locator(`nth=${indexOfSelector}`).click(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export class ProductDetails { | ||
| constructor(page) { | ||
| this.page = page; | ||
| } | ||
|
|
||
| // locators | ||
| productName = () => this.page.locator(".base"); | ||
|
|
||
| async getProductName() { | ||
| return await this.productName().innerText(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,25 @@ | ||
| import { test, expect } from "@playwright/test"; | ||
| import { HomePage } from "../../pages/home.page"; | ||
| import { ProductDetails } from "../../pages/product.details"; | ||
| import { getRandomNumber } from "../../helpers/utils"; | ||
|
|
||
| test("Six items displayed at hot sellers", async ({ page }) => { | ||
| await page.goto("https://magento.softwaretestingboard.com/"); | ||
| const productItems = await page.$$(".product-item"); | ||
| expect(productItems).toHaveLength(6); | ||
| const homePage = new HomePage(page); | ||
| await homePage.navigateToHomePage(); | ||
| await expect(homePage.hotSellersProducts()).toHaveCount(6); | ||
| }); | ||
|
|
||
| test("Item redirects correctly on home page", async ({ page }) => { | ||
| await page.goto("https://magento.softwaretestingboard.com/"); | ||
|
|
||
| const productItems = await page.$$(".product-item"); | ||
| const priceItems = await page.locator(".price").allTextContents(); | ||
| const nameItems = await page.locator(".product-item-link").allInnerTexts(); | ||
|
|
||
| for (let item in productItems) { | ||
| // Re-fetch the elements inside the loop to ensure they are still attached to the DOM | ||
| const updatedProductItems = await page.$$(".product-item"); | ||
|
|
||
| // Go to item`s page | ||
| await updatedProductItems[item].click(); | ||
|
|
||
| // Get the name of the item | ||
| const nameItemsPage = await page.locator("span.base").innerText(); | ||
|
|
||
| // Get the price of the item | ||
| const priceItemPage = await page.locator(".product-info-main .price"); | ||
|
|
||
| expect(nameItemsPage).toContain(nameItems[item]); | ||
| expect(priceItemPage).toHaveText(priceItems[item]); | ||
|
|
||
| await page.goto("https://magento.softwaretestingboard.com/"); | ||
| } | ||
| const homePage = new HomePage(page); | ||
| const productDetails = new ProductDetails(page); | ||
|
|
||
| await homePage.navigateToHomePage(); | ||
| const randomNumber = await getRandomNumber( | ||
| await homePage.getNumberOfHotSellers() | ||
| ); | ||
|
|
||
| const productName = await homePage.getNameOfHotSeller(randomNumber); | ||
| await homePage.clickOnHotSellerProduct(randomNumber); | ||
| const productName2 = await productDetails.getProductName(); | ||
| expect(productName).toContain(productName2); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations says you take two params, but function takes only one