Skip to content

Commit

Permalink
PageObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
An5hul-Choudhary committed Apr 21, 2024
1 parent 54f4cf0 commit be0a57c
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
23 changes: 23 additions & 0 deletions PageObjects/CartPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { expect } = require('@playwright/test');

class CartPage{

constructor(page){
this.page = page;
this.firstListItem = page.locator("div li");
this.addedProduct = page.locator("h3:has-text('ADIDAS ORIGINAL')");
this.checkoutBtn = page.locator("text=Checkout");
}

async checkAddedProduct(){
await this.firstListItem.first().waitFor();
const bool = await this.addedProduct.isVisible();
expect(bool).toBeTruthy();
}

async checkOut(){
await this.checkoutBtn.click();
}

}
module.exports = {CartPage};
29 changes: 29 additions & 0 deletions PageObjects/DashboardPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class DashboardPage{

constructor(page){
this.products = page.locator(".card-body");
this.productsText = page.locator(".card-body b");
this.cart = page.locator("[routerlink*='cart']");
}

async searchProduct(productName){

await this.productsText.first().waitFor();
const titles = await this.productsText.allTextContents();
console.log(titles);
const count = await this.products.count();
for (let i = 0; i < count; ++i) {
if (await this.products.nth(i).locator("b").textContent() === productName) {
//add to cart
await this.products.nth(i).locator("text= Add To Cart").click();
break;
}
}
}

async navigateToCart(){
await this.cart.click();
}

}
module.exports = {DashboardPage};
21 changes: 21 additions & 0 deletions PageObjects/LoginPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class LoginPage{

constructor(page){
this.page = page;
this.userName = page.locator("#userEmail");
this.passWord = page.locator("#userPassword");
this.signInBtn = page.locator("[value='Login']");
}

async goto(){
await this.page.goto("https://rahulshettyacademy.com/client");
}

async validLogin(email, password){
await this.userName.fill(email);
await this.passWord.fill(password);
await this.signInBtn.click();
await this.page.waitForLoadState('networkidle');
}
}
module.exports = {LoginPage};
12 changes: 12 additions & 0 deletions PageObjects/PaymentPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class PaymentPage{

constructor(page){
this.page = page;
this.country = page.locator("[placeholder*='Country']");
}

async selectCountry(){
await this.country.pressSequentially("ind");
}
}
module.exports = {PaymentPage};
65 changes: 65 additions & 0 deletions tests/EndToEndPageObject.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { test, expect } = require('@playwright/test');
const {LoginPage} = require('../PageObjects/LoginPage');
const {DashboardPage} = require('../PageObjects/DashboardPage');
const {CartPage} = require('../PageObjects/CartPage');
const {PaymentPage} = require('../PageObjects/PaymentPage');


test('@Client App login', async ({ page }) => {
//js file- Login js, DashboardPage
const email = "anshika222@gmail.com";
const password = "Iamking@000";
const productName = 'ADIDAS ORIGINAL';

const loginPage = new LoginPage(page);

await loginPage.goto();
await loginPage.validLogin(email, password);

const dashboardPage = new DashboardPage(page);
await dashboardPage.searchProduct(productName);
await dashboardPage.navigateToCart();

const cartPage = new CartPage(page);
cartPage.checkAddedProduct();
cartPage.checkOut();

const paymentPage = new PaymentPage(page);
paymentPage.selectCountry();

const dropdown = page.locator(".ta-results");
await dropdown.waitFor();
const optionsCount = await dropdown.locator("button").count();
for (let i = 0; i < optionsCount; ++i) {
const text = await dropdown.locator("button").nth(i).textContent();
if (text === " India") {
await dropdown.locator("button").nth(i).click();
break;
}
}

await expect(page.locator(".user__name [type='text']").first()).toHaveText(email);
await page.locator(".action__submit").click();
await expect(page.locator(".hero-primary")).toHaveText(" Thankyou for the order. ");
const orderId = await page.locator(".em-spacer-1 .ng-star-inserted").textContent();
console.log(orderId);

await page.locator("button[routerlink*='myorders']").click();
await page.locator("tbody").waitFor();
const rows = await page.locator("tbody tr");


for (let i = 0; i < await rows.count(); ++i) {
const rowOrderId = await rows.nth(i).locator("th").textContent();
if (orderId.includes(rowOrderId)) {
await rows.nth(i).locator("button").first().click();
break;
}
}
const orderIdDetails = await page.locator(".col-text").textContent();
expect(orderId.includes(orderIdDetails)).toBeTruthy();


});


0 comments on commit be0a57c

Please sign in to comment.