Skip to content

Commit

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

class OrderDetailsPage{

constructor(page){
this.page = page;
this.rows = page.locator("tbody tr");
this.details = page.locator(".col-text");
}

async selectingOrderDetails(orderId){
await this.rows;
for (let i = 0; i < await this.rows.count(); ++i) {
const rowOrderId = await this.rows.nth(i).locator("th").textContent();
console.log(rowOrderId);
if (orderId.includes(rowOrderId)) {
await this.rows.nth(i).locator("button").first().click();
break;
}
}

}

async validatingOrderDetails(orderId){
const orderIdDetails = await this.details.textContent();
expect(orderId.includes(orderIdDetails)).toBeTruthy();
}
}
module.exports = {OrderDetailsPage};
12 changes: 12 additions & 0 deletions PageObjects/POManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const {LoginPage} = require('../PageObjects/LoginPage');
const {DashboardPage} = require('../PageObjects/DashboardPage');
const {CartPage} = require('../PageObjects/CartPage');
const {PaymentPage} = require('../PageObjects/PaymentPage');
const {ThankyouPage} = require('../PageObjects/ThankyouPage');
const {OrderDetailsPage} = require('../PageObjects/OrderDetailsPage');

class POManager{

Expand All @@ -11,6 +13,8 @@ class POManager{
this.dashboardPage = new DashboardPage(page);
this.cartPage = new CartPage(page);
this.paymentPage = new PaymentPage(page);
this.thankyouPage = new ThankyouPage(page);
this.orderDetailsPage = new OrderDetailsPage(page);
}

getLoginPage(){
Expand All @@ -28,5 +32,13 @@ class POManager{
getPaymentPage(){
return this.paymentPage;
}

getThankyouPage(){
return this.thankyouPage;
}

getOrderDetailsPage(){
return this.orderDetailsPage;
}
}
module.exports = {POManager};
21 changes: 21 additions & 0 deletions PageObjects/PaymentPage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
const { expect } = require('@playwright/test');

class PaymentPage{

constructor(page){
this.page = page;
this.country = page.locator("[placeholder*='Country']");
this.dropdown = page.locator(".ta-results");
this.buttons = this.dropdown.locator("button");
this.emailIdPresent = page.locator(".user__name [type='text']");
this.submitBtn = page.locator(".action__submit");
}

async selectCountry(){
await this.country.pressSequentially("ind");
await this.dropdown.waitFor();
const optionsCount = await this.buttons.count();
for (let i = 0; i < optionsCount; ++i) {
const text = await this.buttons.nth(i).textContent();
if (text === " India") {
await this.buttons.nth(i).click();
break;
}
}
}

async validatingEmail(email){
await expect(this.emailIdPresent.first()).toHaveText(email);
await this.submitBtn.click();

}
}
module.exports = {PaymentPage};
24 changes: 24 additions & 0 deletions PageObjects/ThankyouPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { expect } = require('@playwright/test');

class ThankyouPage{

constructor(page){
this.page = page;
this.thanksText = page.locator(".hero-primary");
this.orderIdPresent = page.locator(".em-spacer-1 .ng-star-inserted");
this.myOrderBtn = page.locator("button[routerlink*='myorders']");
this.element = page.locator("tbody");
}

async validateOrderId(){
await expect(this.thanksText).toHaveText(" Thankyou for the order. ");
return await this.orderIdPresent.textContent();

}

async myOrder(){
await this.myOrderBtn.click();
await this.element.waitFor();
}
}
module.exports = {ThankyouPage};
45 changes: 11 additions & 34 deletions tests/EndToEndPageObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,22 @@ test('@Client App login', async ({ page }) => {
await dashboardPage.navigateToCart();

const cartPage = poManager.getCartPage();
cartPage.checkAddedProduct();
cartPage.checkOut();
await cartPage.checkAddedProduct();
await cartPage.checkOut();

const paymentPage = poManager.getPaymentPage();
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();
await paymentPage.selectCountry();
await paymentPage.validatingEmail(email);

const thankyouPage = poManager.getThankyouPage();
const orderId = await thankyouPage.validateOrderId();
console.log(orderId);
await thankyouPage.myOrder();

await page.locator("button[routerlink*='myorders']").click();
await page.locator("tbody").waitFor();
const rows = await page.locator("tbody tr");
const orderDetailsPage = poManager.getOrderDetailsPage();
await orderDetailsPage.selectingOrderDetails(orderId);
await orderDetailsPage.validatingOrderDetails(orderId);


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 bee2095

Please sign in to comment.