-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from maharrshi/first_branch
completed the workflow
- Loading branch information
Showing
4 changed files
with
124 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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,88 @@ | ||
import { Page, expect } from "@playwright/test"; | ||
|
||
export class AmazonPage { | ||
private page: Page; | ||
private cartPage: Page | null; | ||
private wishListPage: Page | null; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.cartPage = null; | ||
this.wishListPage = null; | ||
} | ||
|
||
async goToHomePage() { | ||
await this.page.goto("https://www.amazon.in"); | ||
} | ||
|
||
async isLoginButtonPresent() { | ||
const loginButton = await this.page.$("#nav-link-accountList"); | ||
return loginButton !== null; | ||
} | ||
|
||
async searchProduct(productName: string) { | ||
await this.page.fill("#twotabsearchtextbox", productName); | ||
await this.page.keyboard.press("Enter"); | ||
await this.page.waitForSelector( | ||
'//div[@data-cy="title-recipe"]//span[text()="Alchemist"]' | ||
); | ||
} | ||
|
||
async addProductToCart() { | ||
const bookTitle = | ||
'//div[@data-cy="title-recipe"]//span[text()="Alchemist"]'; | ||
const product = await this.page.$(bookTitle); | ||
if (product) { | ||
await product.click(); | ||
const [cartPage] = await Promise.all([ | ||
await this.page.waitForEvent("popup"), | ||
]); | ||
this.cartPage = cartPage; | ||
await this.cartPage.waitForSelector("#add-to-cart-button"); | ||
await this.cartPage.click("#add-to-cart-button"); | ||
console.log("Product added to cart successfully."); | ||
} else { | ||
console.error("No product found to add to cart."); | ||
} | ||
} | ||
|
||
async proceedToCheckoutPresent() { | ||
if (this.cartPage) { | ||
await this.cartPage.waitForSelector("#sc-buy-box-ptc-button"); | ||
await expect( | ||
this.cartPage.locator("#sc-buy-box-ptc-button") | ||
).toBeVisible(); | ||
} else { | ||
console.error( | ||
"Cart page is not available. Please add a product to the cart first." | ||
); | ||
} | ||
} | ||
|
||
async searchResultsCount() { | ||
const searchResults = await this.page.$$( | ||
'div[data-component-type="s-search-result"]' | ||
); | ||
return searchResults.length; | ||
} | ||
|
||
async isWishListButtonPresent() { | ||
const bookTitle = | ||
'//div[@data-cy="title-recipe"]//span[text()="Alchemist"]'; | ||
const product = await this.page.$(bookTitle); | ||
if (product) { | ||
await product.click(); | ||
const [wishListPage] = await Promise.all([ | ||
await this.page.waitForEvent("popup"), | ||
]); | ||
this.wishListPage = wishListPage; | ||
|
||
await this.wishListPage.waitForTimeout(3000); | ||
await expect( | ||
this.wishListPage.locator('//a[contains(text(),"Add to Wish List")]') | ||
).toBeVisible(); | ||
} else { | ||
console.error("Unable to find Wishlist on the page"); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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,33 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { AmazonPage } from "../pageModel/amazonPage"; | ||
|
||
test("Amazon Page", async ({ page }) => { | ||
const amazonPage = new AmazonPage(page); | ||
|
||
try { | ||
await amazonPage.goToHomePage(); | ||
|
||
// Validate Login | ||
const isLoginButtonPresent = await amazonPage.isLoginButtonPresent(); | ||
expect(isLoginButtonPresent).toBeTruthy(); | ||
|
||
// Product Checkout | ||
await amazonPage.searchProduct("the alchemist by paulo coelho"); | ||
await amazonPage.addProductToCart(); | ||
|
||
//Validate Proceed to checkout | ||
await amazonPage.proceedToCheckoutPresent(); | ||
|
||
// Search Functionality | ||
const searchQuery = "the alchemist by paulo coelho"; | ||
await page.bringToFront(); | ||
await amazonPage.searchProduct(searchQuery); | ||
const searchResultsCount = await amazonPage.searchResultsCount(); | ||
console.log(`Search results for '${searchQuery}': ${searchResultsCount}`); | ||
|
||
// Validate Wishlist | ||
await amazonPage.isWishListButtonPresent(); | ||
} catch (error) { | ||
console.error("Error occurred during test execution:", error); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.