const {test, expect} =require('@playwright/test') import { LoginPage } from '../pages/LoginPage'; import { OrderPage } from '../pages/OrderPage'; import { AppConfig } from '../pages/AppConfig'; import { CouponPage } from '../pages/Couponpage'; import { UserPage } from '../pages/UserPage'; import { CatlogPage } from '../pages/CatlogPage'; import { ProductPage } from '../pages/ProductPage'; //dont put commented code in repo //its better to give discription for the steps you are following in comments //add the ids of manual testcases in test.describe also suggest if the testcase is from regression suit or not and add tags respectively const baseURL="https://dev.orderbookings.com/api"; // Validate Orders by UserID(In regression suite) test('TC_API_01: Validate Get Orders API by User ID)',async ({request,page})=>{ // Get Request and store response const response = await request.get(baseURL+'/order/syncOrders?user_id=670766e4272db54e96e423e0&phone=919480111222&lastupdatetime=0&merchantCode=919480707707&role=ROLE_TYPE_MERCHANT'); const res = await response.json(); // Navigate to login page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); // Navigate to order page and search const order = new OrderPage(page); await order.textBoxSearch('ORDER_STATUS_COMPLETE', 'Shubya'); //Assertions expect.soft(order.orderName).toContain(res.data[0].ordered_by_name); expect.soft(order.orderEmail).toContain(res.data[0].ordered_by_email); expect.soft(order.orderPhone).toContain((res.data[0].ordered_by_address.phone).toString()); expect.soft(order.orderCost).toContain((res.data[0].order_cost).toString()); expect.soft(order.orderQty).toContain((res.data[0].ordered_items_qty[0]).toString()); }) //Validate App Config Page (In regression suite) test('TC-API-11: complete AppConfig page to check API',async ({page,request})=>{ // Navigate to login page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); // Navigate to App Config Page const config = new AppConfig(page); await config.functionalityAppConfig('UAE dirham (د.إ;)','7','5', '400', '35', '9565456737', 'City','Tamil Nadu'); //get request and response const response = await request.get(baseURL+'/config/919480707707?merchantCode=919480707707'); const res = await response.json(); //Assertions expect.soft(config.merchantCode).toContain(res.data.merchantCode); const cancellationTillResponse = await page.locator(config.cancellationTillAPI).inputValue(); expect.soft(cancellationTillResponse).toContain((res.data.cancellation_till).toString()); const minimumCartPrizeResponse = await page.locator(config.minimumCartPrizeAPI).inputValue(); expect.soft( minimumCartPrizeResponse).toContain((res.data.minimum_cart_price).toString()); const deliveryChargeResponse = await page.locator(config.deliveryChargeAPI).inputValue(); expect.soft( deliveryChargeResponse).toContain((res.data.delivery_charge).toString()); }) //Validate API Testing to get coupon details as user(In Regression Suite) test('TC_API_16: APITesting_Coupon Get Details as User',async ({request,page})=>{ //Get request and response const response = await request.get(baseURL+'/available-coupon/670e14cf14f563f755f3e2a1/919480707707'); const res = await response.json(); //Navigate to Login Page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to coupon page const coupon = new CouponPage(page); await coupon.viewCoupon(); //Assertions expect.soft(coupon.shortDescription).toContain(res.data[1].name); expect.soft(coupon.descriptionCheck).toContain(res.data[1].description); expect.soft(coupon.internalCouponValue).toContain(res.data[1].code); expect.soft(coupon.couponCode).toContain(res.data[1].campaign_code); }) //Validate Coupon details as Guest(In Regression Suite) test('TC_API_16: APITesting_Coupon Get Details as Guest',async ({request,page})=>{ //get request and response const response = await request.get(baseURL+'/available-coupon-guest/919480707707'); const res = await response.json(); //Navigate to login Page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to coupon page const coupon = new CouponPage(page); await coupon.viewCoupon(); //Assertions expect.soft(coupon.shortDescriptionGuest).toContain(res.data[0].name); expect.soft(coupon.descriptionCheckGuest).toContain(res.data[0].description); expect.soft(coupon.internalCouponValueGuest).toContain(res.data[0].code); expect.soft(coupon.couponCodeGuest).toContain(res.data[0].campaign_code); }) //get order by order id and compare with web ui in the order list.(In Regression Suite) test('TC_API_06: GET ORDER BY ORDER_ID',async ({request,page})=>{ //Get request and response const response1 = await request.get(baseURL+'/order/getorder/670e249314f563f755f3e2a5'); const res = await response1.json(); //Navigate to Login Page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to order page const order = new OrderPage(page); await order.textBoxSearch('ORDER_STATUS_PENDING', 'DAYA'); //Assertions expect.soft(order.userid).toContain(res.data.id); //id expect.soft(order.username).toContain(res.data.ordered_by_name); //name expect.soft(order.useremail).toContain(res.data.ordered_by_email); //email expect.soft(order.userphone).toContain(res.data.ordered_by_phone); //phone const element = await page.locator(order.userorderitems); const text = await element.textContent(); expect(text).toContain(res.data.ordered_items[0]); //order items expect.soft(order.orderqty).toContain((res.data.ordered_items_qty[0]).toString()); // order qty await page.close(); }) //get order by order id and compare with web ui in the order list.(In Regression Suite) test('TC_API_10: GET USER Details',async ({request,page})=>{ //Get request and response const response2 = await request.get(baseURL+'/user/userreg?phone=919480111111&merchantCode=919480707707'); const res = await response2.json(); //Navigate to login page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to user page const user = new UserPage(page); await user.userAPI(); //Assertions expect.soft(user.userNameAPI).toContain(res.data.name); expect.soft(user.userPhoneAPI).toContain(res.data.phone); expect.soft(user.userEmailAPI).toContain(res.data.email); expect.soft(user.merchantCode).toContain(res.data.merchantCode); expect.soft(user.addressAPI).toContain(res.data.area[0]); expect.soft(user.addressAPI).toContain(res.data.area[1]); expect.soft(user.addressAPI).toContain(res.data.area[2]); await page.close(); }) //Validate Categories(In Regression Suite) test('TC-API-12: Get Categories and products',async ({page,request})=>{ //Main Page Element locating //Get request and response const response = await request.get(baseURL+'/bud/919480707707'); const res = await response.json(); //Navigate to Login Page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to categories Page const catlog = new CatlogPage(page); await catlog.clickCatalogButton(); //Assertions const obaBudView = page.locator('//select[@id="oba_bud_view"]'); const obaProductView = page.locator('//select[@id="oba_product_view"]'); const budValue = await obaBudView.inputValue(); const productValue = await obaProductView.inputValue(); expect.soft(budValue).toContain(res.data.buds[0].childview); expect.soft(productValue).toContain(res.data.buds[0].product_childview); // Mens Page //Navigate to Login Page await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to Catlog Page await catlog.clickCatalogButton(); let Category1 = await catlog.NavigateToMens(); //Initialize values 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; 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 //Assertions 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); // Womens Page //Initialize values let Category2 = await catlog.NavigateToWomens(); const Name2 = await Category2.catnames; const catlogViewType2 = await Category2.selecteddcattype; const Productviewtype2 = await Category2.selecctedprodtype; const Catislive2 = Category2.isActive; 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; //Assertions 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); //this cat3 is kids let Category3 = await catlog.NavigateToKids(); const Name3 = await Category3.catnames; const catlogViewType3 = await Category3.selecteddcattype; const Productviewtype3 = await Category3.selecctedprodtype; const Catislive3 = Category3.isActive; 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; //Assertions 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); }) //Get products(In regression suite) test('TC-API-12: Get Products',async ({request,page})=>{ //Get request and response const response = await request.get(baseURL+'/bud/919480707707'); const res = await response.json(); //Navigate to Login Page const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to product page const product = new ProductPage(page); await product.clickProductlistButton(); //Assertions const productName = await page.textContent("//td[normalize-space()='T-Shirt']"); expect.soft(productName.trim()).toContain(res.data.products[0].name.trim()); expect.soft(product.priceAPI).toContain((res.data.products[0].price).toString()); expect.soft(product.quantityAPI).toContain((res.data.products[0].quantity).toString()); const productBoolean = { availableAPI: await page.textContent("//td[normalize-space()='true']") }; expect.soft(productBoolean.availableAPI.trim()).toBe(String(res.data.products[0].available)); expect.soft(product.orderlimitAPI).toContain((res.data.products[0].order_limit).toString()); }) //Complete address list process(In regression suite) test('TC_API-02,03,01,17: Complete Address API',async({page,request})=>{ let resourceId; // 1. Post Response const postResponse = await request.post(baseURL+'/user/addnewaddress',{ data: { "addressLine1": "35", "addressLine2": "Mount Main Road ", "city": "Chennai", "stateOrProvince": "Tamil Nadu", "postalCode": "123111", "phone": "919480111111", "deliveryInstructions": null, "isDefault": true, "user_id": "670e14cf14f563f755f3e2a1", "title": "test address", "area": "Chennai" }, }); //Navigate to login const login = new LoginPage(page); await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to user const user = new UserPage(page); await user.addressListAPI(); expect(postResponse.status()).toBe(200); const postResponseBody = await postResponse.json(); // Validate response body expect(postResponseBody.data).toHaveProperty('id'); // Assuming the API returns an `id` for the new resource resourceId = postResponseBody.data.id; //Assertion for post expect.soft(user.addressList).toContain(postResponseBody.data.addressLine1); expect.soft(user.addressList).toContain(postResponseBody.data.addressLine2); expect.soft(user.addressList).toContain(postResponseBody.data.stateOrProvince); expect.soft(user.addressList).toContain((postResponseBody.data.postalCode).toString()); //2. Get address list const getResponse = await request.get(baseURL+'/user/addresslist?user_id=670e14cf14f563f755f3e2a1'); const getResponseBody = await getResponse.json(); //Navigate to Login Page await login.gotoLoginPage(); await login.loginWithCrtPassword(); await page.waitForTimeout(5000); //Navigate to User Page await user.addressListAPI(); //Assertions expect.soft(user.addressList).toContain(getResponseBody.data[1].addressLine1); expect.soft(user.addressList).toContain(getResponseBody.data[1].addressLine2); expect.soft(user.addressList).toContain(getResponseBody.data[1].stateOrProvince); expect.soft(user.addressList).toContain((getResponseBody.data[1].postalCode).toString()); //3.Patch Request const patchResponse = await request.patch(baseURL+'/user/updateaddress',{ data: { "addressLine1": "35", "addressLine2": "Mount Kitchen Main Road", "city": "", "stateOrProvince": "Tamil Nadu", "postalCode": "123111", "phone": "91948011111", "deliveryInstructions": null, "isDefault": true, "user_id": "670e14cf14f563f755f3e2a1", "title": "test address", "area": "Chennai", "address_id": resourceId }, }); const patchResponseBody = await patchResponse.json(); //Navigate to Login Page await login.gotoLoginPage(); await login.loginWithCrtPassword(); //Navigate to user page await user.addressListAPI(); //Assertions expect.soft(user.addressPatch).toContain(patchResponseBody.data.addressLine1); expect.soft(user.addressPatch).toContain(patchResponseBody.data.addressLine2); expect.soft(user.addressPatch).toContain(patchResponseBody.data.stateOrProvince); expect.soft(user.addressPatch).toContain((patchResponseBody.data.postalCode).toString()); // 4. Delete Request const deleteResponse = await request.delete(baseURL+'/user/deleteaddress', { data:{ "user_id": "670e14cf14f563f755f3e2a1", "address_id": resourceId, } }); // Validate DELETE response expect(deleteResponse.status()).toBe(200); // Typically, HTTP 200 or 204 is expected for successful deletions const deleteResponseBody = await deleteResponse.text(); }) test('TC-API-03,17: Post and Delete Address API',async({request})=>{ // 1. Post Response const postResponse = await request.post(baseURL+'/user/addnewaddress',{ data: { "addressLine1": "52", "addressLine2": "25", "city": "", "stateOrProvince": "", "postalCode": "123123", "phone": "919480111111", "deliveryInstructions": null, "isDefault": false, "user_id": "670e14cf14f563f755f3e2a1", "title": "test address", "area": "Chennai" }, }); expect(postResponse.status()).toBe(200); const postResponseBody = await postResponse.json(); // Parse the response body // Validate response body expect(postResponseBody.data).toHaveProperty('id'); // Assuming the API returns an `id` for the new resource const resourceId = postResponseBody.data.id; // 2. Delete Request const deleteResponse = await request.delete(baseURL+'/user/deleteaddress', { data:{ "user_id": "670e14cf14f563f755f3e2a1", "address_id": resourceId, } }); // Validate DELETE response expect(deleteResponse.status()).toBe(200); const deleteResponseBody = await deleteResponse.text(); }) /*--------------------------------------------------------------------------------------------------------------------*/ //Order Page cannot be automated, since the API datas are missing, as it is continued from place order, products are missing