OBA Website automated using playwright
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

521 lines
21 KiB

import { test, expect } from '@playwright/test';
const { chromium } = require('playwright');
import { OrderDetails } from '../../OBAPages/Orderapipage.spec';
import { Appconfig } from '../../OBAPages/AppConfig.spec';
const FormData =require('form-data');
//order sync to get order details using userid and user phone number and mercchant id.
test ('OrderSync of completed orders',async({request,page})=>{
const response = await request.get('https://dev.orderbookings.com/api/order/syncOrders?user_id=670766e4272db54e96e423e0&phone=919480111222&lastupdatetime=0&merchantCode=919480707707&role=ROLE_TYPE_USER')
const res=await response.json();
let OrderedBy = res.data[0].ordered_by_name; //you will get user from this.
let Orderstatus = res.data[0].order_status; //order status i will get from response
const orderdetail = new OrderDetails(page);
await orderdetail.navigateToOrderDetails();
const result= await orderdetail.searchOrder(Orderstatus,OrderedBy);
const username = result.OrderId;
const userid =result.OrderId;
const useremail = result.OrderId;
const userphone = result.OrderId;
const userorderitems = result.Order_items;
const userorderstatus = result.OrderStatusis;
let ordercost = result.Order_cost;
let orderqty = result.Order_qty;
expect.soft(userid).toContain(res.data[0].id); //id
expect.soft(username).toContain(res.data[0].ordered_by_name); //name
expect.soft(useremail).toContain(res.data[0].ordered_by_email); //email
expect.soft(userphone).toContain(res.data[0].ordered_by_phone); //phone
expect.soft(userorderitems).toContain((res.data[0].ordered_items[0]).toString()); //order items
expect.soft(ordercost).toContain((res.data[0].order_cost).toString()); //order cost
expect.soft(orderqty).toContain((res.data[0].ordered_items_qty[0]).toString()); // order qty
expect.soft(userorderstatus).toContain(res.data[0].order_status); // order status is complete
await page.close();
})
//C:\PlayWright\tests\navigatetomen.spec.js
//unable to automate becasue its contains bug in the orderitems,order qty,order item price.
//locator finds two locators when we run the automated testcode.
test.skip('OrderSync for Pending ',async({request,page})=>{
const response = await request.get('https://dev.orderbookings.com/api/order/syncOrders?user_id=670766e4272db54e96e423e0&phone=919480111222&lastupdatetime=0&merchantCode=919480707707&role=ROLE_TYPE_USER')
const res=await response.json();
const orderdetail = new OrderDetails(page);
await orderdetail.navigateToOrderDetails();
const result= await orderdetail.searchOrder('ORDER_STATUS_CANCELLED','Shubya');
const username = result.OrderId;
const userid =result.OrderId;
const useremail = result.OrderId;
const userphone = result.OrderId;
const userorderitems = result.Order_items;
const userorderstatus = result.OrderStatusis;
let ordercost = result.Order_cost;
let orderqty = result.Order_qty;
expect.soft(userid).toContain(res.data[1].id); //id
expect.soft(username).toContain(res.data[1].ordered_by_name); //name
expect.soft(useremail).toContain(res.data[1].ordered_by_email); //email
expect.soft(userphone).toContain(res.data[1].ordered_by_phone); //phone
expect.soft(userorderitems).toContain((res.data[1].ordered_items[1]).toString()); //order items
expect.soft(ordercost).toContain((res.data[1].order_cost).toString()); //order cost
expect.soft(orderqty).toContain((res.data[1].ordered_items_qty[1]).toString()); // order qty
expect.soft(userorderstatus).toContain(res.data[1].order_status); // order status is complete
await page.close();
})
test('GetUserDetails',async({request,page})=>{
const response = await request.get('https://dev.orderbookings.com/api/user/userreg?phone=919480111222&merchantCode=919480707707')
const res=await response.json();
const orderdetail = new OrderDetails(page);
await orderdetail.navigateTouser();
const result = await orderdetail.searchUserDetails('Shubya');
const userDetails = result.userDetails;
const merchantid = result.merchantid;
const userstatus = result.isActive;
expect.soft(userDetails).toContain(res.data.name);
expect.soft(userDetails).toContain(res.data.email);
expect.soft(userDetails).toContain(res.data.phone);
expect.soft(merchantid).toContain(res.data.merchantCode);
expect.soft(userDetails).toContain(res.data.area[0]);
expect.soft(userDetails).toContain(res.data.multiple_address_list[0].addressLine1);
expect.soft((userstatus).toString()).toContain((res.data.is_user_active).toString());
await page.close();
})
let useraddressid; // USER ADDRESS ID
test('Get Delete Post Patch Address of User',async({request,page})=>{
const response = await request.get('https://dev.orderbookings.com/api/user/addresslist?user_id=670766e4272db54e96e423e0')
const res=await response.json();
await console.log('GET ADDRESS OF USER');
await console.log(res);
const userdetail = new OrderDetails(page);
await userdetail.navigateTouser();
const result = await userdetail.updateUserAddress('Shubya');
await page.reload();
const user_Address_updated = result.user_Address_updated;
const user_area_updated =result.user_area_updated;
expect.soft(user_Address_updated).toContain((res.data[0].addressLine1).toString());
expect.soft(user_Address_updated).toContain((res.data[0].addressLine2).toString());
expect.soft(user_Address_updated).toContain((res.data[0].postalCode).toString());
expect.soft(user_area_updated).toContain(res.data[0].area);
const responseofdelete = await request.delete('https://dev.orderbookings.com/api/user/deleteaddress', {
data: {
"user_id": "670766e4272db54e96e423e0",
"address_id": "67076a2d272db54e96e423e8"
}
})
await console.log('DELETE ADDRESS OF USER');
await console.log(responseofdelete.json);
const response1 = await request.post('https://dev.orderbookings.com/api/user/addnewaddress', {
data: {
"addressLine1": "Adding address through the code1",
"addressLine2": "api is my home",
"city": "",
"stateOrProvince": "",
"postalCode": "123456",
"phone": "917777777777",
"deliveryInstructions": null,
"isDefault": true,
"user_id": "670766e4272db54e96e423e0",
"title": "Api test address1",
"area": "Mumbai"
}
})
const res1 = await response1.json();
useraddressid = res1.data.id;
await console.log(useraddressid);
await console.log('ADDED NEW ADDRESS OF USER');
await console.log(res1);
await page.reload();
const result1 = await userdetail.updateUserAddress('Shubya');
const user_Address_updated1 = result1.user_Address_updated;
const user_area_updated1 =result1.user_area_updated;
expect.soft(user_Address_updated1).toContain(res1.data.addressLine1);
expect.soft(user_Address_updated1).toContain((res1.data.addressLine2).toString());
expect.soft(user_Address_updated1).toContain((res1.data.postalCode).toString());
expect.soft(user_area_updated1).toContain(res1.data.area);
const response2 = await request.patch('https://dev.orderbookings.com/api/user/updateaddress', {
data: {
"addressLine1": "Update address through api request from code",
"addressLine2": "api",
"city": "Bijapur",
"stateOrProvince": "Goa",
"postalCode": "555555",
"phone": "919999999999",
"deliveryInstructions": null,
"isDefault": true,
"title": "test thought patch method address",
"area": "Mumbai",
"address_id": useraddressid
}
})
const res2 = await response2.json();
await console.log('UPDATED ADDRESS OF USER');
await console.log(res2);
const result2 = await userdetail.updateUserAddress('Shubya');
const user_Address_updated2 = result2.user_Address_updated;
const user_area_updated2 =result2.user_area_updated;
//await page.reload();
expect.soft(user_Address_updated2).toContain((res2.data.addressLine1).toString());
expect.soft(user_Address_updated2).toContain((res2.data.addressLine2).toString());
expect.soft(user_Address_updated2).toContain((res2.data.postalCode).toString());
expect.soft(user_area_updated2).toContain(res1.data.area);
await page.close();
})
//get order by order id and compare with web ui in the order list.
test('GET ORDER BY ORDER_ID',async ({request,page})=>{
let Orderstatus;
let OrderedBy;
const response1 = await request.get('https://dev.orderbookings.com/api/order/getorder/67076a2f272db54e96e423e9', {
data: {
"order_id": "6710b588b03c253fa86cf9cb",
"note": "note added again"
}
})
const res = await response1.json();
OrderedBy = res.data.ordered_by_name;
Orderstatus = res.data.order_status;
const orderdetail = new OrderDetails(page);
await orderdetail.navigateToOrderDetails();
const result= await orderdetail.searchOrder(Orderstatus,OrderedBy);
const username = result.OrderId;
const userid =result.OrderId;
const useremail = result.OrderId;
const userphone = result.OrderId;
const userorderitems = result.Order_items;
const userorderstatus = result.OrderStatusis;
let ordercost = result.Order_cost;
let orderqty = result.Order_qty;
expect.soft(userid).toContain(res.data.id); //id
expect.soft(username).toContain(res.data.ordered_by_name); //name
expect.soft(useremail).toContain(res.data.ordered_by_email); //email
expect.soft(userphone).toContain(res.data.ordered_by_phone); //phone
expect.soft(userorderitems).toContain((res.data.ordered_items[0]).toString()); //order items
expect.soft(ordercost).toContain((res.data.order_cost).toString()); //order cost
expect.soft(orderqty).toContain((res.data.ordered_items_qty[0]).toString()); // order qty
expect.soft(userorderstatus).toContain(res.data.order_status); // order status is complete
await page.close();
})
//app configuration details are compared with api response.
test('GET APP Config Details',async ({request,page})=>{
const response = await request.get('https://dev.orderbookings.com/api/config/919480707707?merchantCode=919480707707')
const res = await response.json();
const orderdetail = new OrderDetails(page);
await orderdetail.NavigatetoAppconfig();
await page.reload();
const appconfig = new Appconfig(page);
const app = await appconfig.GetAppConfigDetailsforApiRequest(); ////Currency,soundloop,canceltime,mincartvalue,deliletycharge,Actioncall,selecttype,Area
let currency = app.selectedCurrency;
let soundloop = app.soundloop;
let canceltime = app.canceltime;
let mincartvalue = app.mincartvalue;
let delivarycharge = app.delivarycharge;
let actioncall = app.Actioncall;
let selecttype = app.selectedtype;
let area = app.Area;
let MerachantCode = app.Merchantcode;
let profileDetails = app.ProfileDetails;
expect.soft(currency).toContain(res.data.currency_code); //currency
expect.soft(soundloop).toContain((res.data.notification_sound_loop).toString()); //soundloop
expect.soft(canceltime).toContain((res.data.cancellation_till).toString()); //canceltime
expect.soft(mincartvalue).toContain((res.data.minimum_cart_price).toString()); //mincartvalue
expect.soft(delivarycharge).toContain((res.data.delivery_charge).toString()); //delivarycharge
expect.soft(actioncall).toContain(res.data.call_to_action); //actioncall
expect.soft(selecttype).toContain(res.data.area_type);
expect.soft(MerachantCode).toContain(res.data.merchantCode); //merchant code
expect.soft(profileDetails).toContain(res.data.merchant_details.name); //Company Name
expect.soft(profileDetails).toContain(res.data.merchant_details.email); //Merchant Email
await page.close();
//expect.soft(area).toContain(res.data.area); //area
})
//unable to automate bcoz of the formdata cant be sent properly and unable to handle table data to comparre with response.
//place order -- complete order
//place order --- cancel order
//Place order using api request
let Orderstatus;
let OrderedBy;
let OrderId;
test('Place Order', async ({ request, page }) => {
const formData = new FormData();
const jsondata = {
"order_id": "",
"amount_received": 0,
"order_status": "ORDER_STATUS_PENDING",
"ordered_by_phone": "919480111222",
"ordered_by_user_id": "670766e4272db54e96e423e0",
"order_cost": 748,
"order_tax": 748,
"order_gross_amount": 1496,
"ordered_items": [
"Jeans Pant",
"T-Shirt"
],
"ordered_items_sku": [
"jeans_pant",
"t-shirt_"
],
"ordered_items_qty": [
1,
2
],
"ordered_items_tax": [
4,
9
],
"ordered_items_price": [
0,
0
],
"merchantCode": "919480707707",
"order_validation_pin": 254034,
"note": "",
"ordered_items_notes": [],
"images_arraylist": [],
"image_latitude": 0,
"image_longitude": 0,
"use_amount_from_wallet": false,
"service_request_date": 1729137865273,
"order_rating": 0,
"order_is_approved": true,
"ordered_items_audio": [],
"logs": [],
"ordered_by_name": "Shubya",
"ordered_by_email": "Shubya111@gmail.com",
"ordered_by_area": [
"Mumbai"
],
"order_time": "40860000",
"order_last_updated_on": "",
"order_complete_time": "",
"order_cancel_time": "",
"order_assigned_to": "",
"ordered_delivered_by": "",
"order_payment_received": false,
"order_has_audio_file": false,
"order_has_admin_audio_file": false,
"order_has_image_file": false,
"ordered_by_address": "67079c7b272db54e96e423f4",
"invoiceid": "",
"amount_from_wallet": 0,
"coupon": "",
"cart": [
{
"id": "670767d0272db54e96e423e4",
"available": true,
"sku": "jeans_pant",
"name": "Jeans Pant",
"description": "M.S.Dhoni Special Edition Jeans Pant.",
"quantity": 1,
"price": 300,
"image": "",
"tax_in_percent": 4,
"total": 312,
"actual": 312,
"order_limit": 100,
"short_description": "M.S.Dhoni Special Edition Jeans Pant.",
"is_live": true
},
{
"id": "67076794272db54e96e423e3",
"available": true,
"sku": "t-shirt_",
"name": "T-Shirt",
"description": "M.S.Dhoni Special Edition T-Shirts.",
"quantity": 2,
"price": 200,
"image": "",
"tax_in_percent": 9,
"total": 436,
"actual": 218,
"order_limit": 100,
"short_description": "M.S.Dhoni Special Edition T-Shirts.",
"is_live": true
}
],
"cart_total_amount": 748,
"coupon_applied": false,
"products": [],
"total_saving": 0
};
// Append JSON data as string to formData
formData.append('order_req', JSON.stringify(jsondata));
// Send POST request with headers and formData
const response = await request.post('https://dev.orderbookings.com/api/order/placeorder', {
headers: {
'Content-Type': 'multipart/form-data; boundary=<calculated when request is sent>'
},
body: formData
});
const res = await response.json();
console.log(res);
});
// OrderedBy = res.data.ordered_by_name; //you will get user from this.
// Orderstatus = res.data.order_status; //order status i will get from response
// OrderId = res.data.order_id; // you will get order id
// const orderdetail = new OrderDetails(page);
// await orderdetail.navigateToOrderDetails(); //navigate to order list
// await orderdetail.toFindOrders(Orderstatus,OrderedBy); //calling method to find order by status and user
// const tableValues = await orderdetail.getTablevalues(OrderId); // calling method to get table values
// const flattenedValues = tableValues.flat();
// expect(flattenedValues.some(value => value.includes(OrderId))).toBe(true);
// await page.close();
//table values compare with the order id and trying to fetch the the data of that order from order list.
test('get values of table',async({page})=>{
const userdetail = new OrderDetails(page);
await userdetail.navigateToOrderDetails();
await userdetail.toFindOrders();
const tableValues = await userdetail.getTablevalues('670f55a814f563f755f3e2a9');
const flattenedValues = tableValues.flat();
expect(flattenedValues.some(value => value.includes('670f55a814f563f755f3e2a9'))).toBe(true);
console.log(flattenedValues);
})
//cancel order is api request to check whether the order is cancelled or not through the api request and compare with the web ui.
test('cancel Order',async({request,page})=>{
let Orderstatus;
let OrderedBy;
let Orderphone;
const response1 = await request.post('https://dev.orderbookings.com//api/order/cancelorder', {
data: {
"order_id":"6710bac8b03c253fa86cf9cd"
}
})
const res = response1.json();
await console.log(res);
OrderedBy = res.data.ordered_by_name;
Orderstatus = res.data.order_status;
Orderphone = res.data.ordered_by_phone;
const orderdetail = new OrderDetails(page);
await orderdetail.navigateToOrderDetails();
await orderdetail.toFindOrders(Orderstatus,OrderedBy); //calling method to find order by status and user
const tableValues = await orderdetail.getTablevalues(Orderphone); // calling method to get table values
const flattenedValues = tableValues.flat();
expect(flattenedValues.some(value => value.includes(Orderphone))).toBe(true);
await page.close();
} )
//category and products are unable to fetch from the api request and unable to compare with the web ui.
//from tree unable to click mens and women category and unable to fetch the products from the api request and unable to compare with the web ui
//
test('Category and Products', async ({ request,page }) => {
const catdetails = new OrderDetails(page);
await catdetails.NavigatetoCatlog();
// await page.reload();
let Category1 = await catdetails.NavigatetoMens();
let Name1 = await Category1.catnames;
let catlogViewType1 = await Category1.selecteddcattype;
let Productviewtype1 = await Category1.selecctedprodtype;
let Catislive1 = await Category1.isActive;
let merchantid = await Category1.merchatcode;
// const Catproducts1 = await Category1.Productsincluded;
//await console.log(Catproducts1);
//api request
const response = await request.get('https://dev.orderbookings.com/api/bud/919480707707');
const res = await response.json();
// await console.log(res);
let cat1 =res.data.buds[1].name;
let catlog1ViewType1 =res.data.buds[1].childview;
let cat1Productviewtype =res.data.buds[1].product_childview;
let cat1islive = res.data.buds[1].is_live;
let merchantcode =res.data.buds[1].merchantCode;
var cat2 = res.data.buds[2].name; //womens
var cat3 = res.data.buds[3].name; //kids
expect.soft(Name1).toEqual(cat1);
expect.soft(merchantid).toEqual(merchantcode)
expect.soft(catlogViewType1).toEqual(catlog1ViewType1);
expect.soft(Productviewtype1).toEqual(cat1Productviewtype);
expect.soft(Catislive1).toEqual(cat1islive);
//expect.soft(Catproducts1).toContain();
let Category2 = await catdetails.NavigatetoWomens();
const Name2 = await Category2.catnames;
const catlogViewType2 = await Category2.selecteddcattype;
const Productviewtype2 = await Category2.selecctedprodtype;
const Catislive2 = Category2.isActive;
console.log('For Womens' +Catislive2);
// const Catproducts2 = await Category2.Productsincluded;
let cat2logViewType =res.data.buds[2].childview;
let cat2Productviewtype =res.data.buds[2].product_childview;
let cat2islive = res.data.buds[2].is_live;
let merchantcode2 =res.data.buds[2].merchantCode;
expect.soft(Name2).toEqual(cat2);
expect.soft(merchantid).toEqual(merchantcode2)
expect.soft(catlogViewType2).toEqual(cat2logViewType);
expect.soft(Productviewtype2).toEqual(cat2Productviewtype);
expect.soft(Catislive2).toEqual(cat2islive);
// expect.soft(Catproducts2).toEqual(res.data.buds[2].products);
//this cat3 is kids
let Category3 = await catdetails.NavigatetoKids();
const Name3 = await Category3.catnames;
const catlogViewType3 = await Category3.selecteddcattype;
const Productviewtype3 = await Category3.selecctedprodtype;
const Catislive3 = Category3.isActive;
console.log('for kids:' +Catislive3);
//const Catproducts3 = await Category3.Productsincluded;
//api request response are in object so we need save in the letibale to compare.
let cat3ogViewType =res.data.buds[3].childview;
let cat3Productviewtype =res.data.buds[3].product_childview;
let cat3islive = res.data.buds[3].is_live;
let merchantcode3 =res.data.buds[3].merchantCode;
expect.soft(Name3).toEqual(cat3);
expect.soft(merchantid).toEqual(merchantcode3);
expect.soft(catlogViewType3).toEqual(cat3ogViewType);
expect.soft(Productviewtype3).toEqual(cat3Productviewtype);
expect.soft(Catislive3).toEqual(cat3islive);
//expect.soft(Catproducts3).toContain(res.data.buds[3].products);
})