exports.ProductPage= class ProductPage { constructor(page) { this.page = page; //Locators for Product Page this.productsButton = "//span[normalize-space()='Products']"; this.productListButton= "//a[normalize-space()='Product List']"; this.addProductButton="//a[normalize-space()='Add Product']"; this.productName="//input[@id='oba_product_name']"; this.productPrize="//input[@id='oba_product_price']"; this.managedRadioButton="//input[@id='managed']"; this.unmanagedRadioButton="//input[@id='unmanaged']"; this.productQuantityValue="//input[@id='oba_product_quantity']"; this.orderLimit="//input[@id='oba_product_order_limit']"; this.taxIn="//input[@id='oba_product_tax']"; this.productAvailableCheck="//input[@name='isAvailable']"; this.isLiveCheck="//input[@name='isLive']"; this.shortDescription="//textarea[@id='oba_product_short_description']"; this.productDescription="//textarea[@name='editor-html-code']"; this.productImage="#edit_image"; this.uploadImage="#oba_product_input_display"; this.productlistSearchBox="//input[@id='oba_product_search']"; this.searchBox="//i[@class='fa fa-lg fa-fw fa-search']"; this.editButton="//i[@class='fa fa-lg fa-edit']"; this.edittButton="//a[@class='btn btn-primary']"; this.saveButton="//button[@class='btn btn-primary btn-block']"; this.deleteButton="//i[@class='fa fa-lg fa-trash']"; this.searchProduct="//input[@id='oba_product_search']"; this.searchButton="//button[@id='oba_product_search_btn']"; //API Validation this.nameAPI="//td[normalize-space()='T-Shirt']"; this.priceAPI="//b[normalize-space()='200']"; this.quantityAPI="//td[normalize-space()='79971']"; this.availableAPI="//td[normalize-space()='true']"; this.orderlimitAPI="//td[normalize-space()='100']"; //Delete the Product from product list after assertion this.editButtonAssertion="//tbody/tr[2]/td[7]/div[1]/a[1]"; this.deleteButtonAssertion="(//a[@class='btn btn-primary'])[2]"; this.deleteitAssertion="//button[@class='swal2-confirm swal2-styled']"; } // Check Product button async clickProductsButton(){ await this.page.locator(this.productsButton).click(); } //Check ProductListButton async clickProductlistButton(){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.productListButton).click(); } //Check Add Product Button async clickAddProductButton(){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.addProductButton).click(); } //Complete Add Product Functionality async addProductFunctionality(productName, productPrize, productQuantity, orderLimitvalue, taxin, shortDescription){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.addProductButton).click(); await this.page.locator(this.productName).fill(productName); await this.page.locator(this.productPrize).fill(productPrize); await this.page.locator(this.managedRadioButton).check(); await this.page.locator(this.productQuantityValue).fill(productQuantity); await this.page.locator(this.orderLimit).fill(orderLimitvalue); await this.page.locator(this.taxIn).fill(taxin); await this.page.locator(this.productAvailableCheck).check(); await this.page.locator(this.isLiveCheck).check(); await this.page.locator(this.shortDescription).fill(shortDescription); await this.page.waitForSelector('.CodeMirror'); await this.page.evaluate(() => { const codeMirrorElement = document.querySelector('.CodeMirror'); codeMirrorElement.CodeMirror.setValue('Yummy! Delicious Biriyani Taste the Beauty of Kanyakumari'); }); await this.page.locator(this.productImage).click(); await this.page.locator(this.uploadImage).setInputFiles("./pages/TestData/Biriyani.jpg"); await this.page.locator(this.saveButton).click(); } // Add Product functionality and delete it async addProductFunctionalityDelete(productName, productPrize, productQuantity, orderLimitvalue, taxin, shortDescription){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.addProductButton).click(); await this.page.locator(this.productName).fill(productName); await this.page.locator(this.productPrize).fill(productPrize); await this.page.locator(this.managedRadioButton).check(); await this.page.locator(this.productQuantityValue).fill(productQuantity); await this.page.locator(this.orderLimit).fill(orderLimitvalue); await this.page.locator(this.taxIn).fill(taxin); await this.page.locator(this.productAvailableCheck).check(); await this.page.locator(this.isLiveCheck).check(); await this.page.locator(this.shortDescription).fill(shortDescription); await this.page.waitForSelector('.CodeMirror'); await this.page.evaluate(() => { const codeMirrorElement = document.querySelector('.CodeMirror'); codeMirrorElement.CodeMirror.setValue('Yummy! Delicious Taste, LifteTime Settlement'); }); await this.page.locator(this.productImage).click(); await this.page.locator(this.uploadImage).setInputFiles("./pages/TestData/Biriyani.jpg"); await this.page.locator(this.deleteButton).click(); } async addProductFunctionalityForAll(productName, productPrize, productQuantity, orderLimitvalue, taxin, shortDescription){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.addProductButton).click(); await this.page.locator(this.productName).fill(productName); await this.page.locator(this.productPrize).fill(productPrize); await this.page.locator(this.managedRadioButton).check(); await this.page.locator(this.productQuantityValue).fill(productQuantity); await this.page.locator(this.orderLimit).fill(orderLimitvalue); await this.page.locator(this.taxIn).fill(taxin); await this.page.locator(this.productAvailableCheck).check(); await this.page.locator(this.isLiveCheck).check(); await this.page.locator(this.shortDescription).fill(shortDescription); await this.page.waitForSelector('.CodeMirror'); await this.page.evaluate(() => { const codeMirrorElement = document.querySelector('.CodeMirror'); codeMirrorElement.CodeMirror.setValue('Yummy! Delicious Taste, LifteTime Settlement'); }); await this.page.locator(this.saveButton).click(); } async addProductFunctionalityUnmanaged(productName, productPrize, orderLimitvalue, taxin, shortDescription){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.addProductButton).click(); await this.page.locator(this.productName).fill(productName); await this.page.locator(this.productPrize).fill(productPrize); await this.page.locator(this.unmanagedRadioButton).check(); await this.page.locator(this.orderLimit).fill(orderLimitvalue); await this.page.locator(this.taxIn).fill(taxin); await this.page.locator(this.shortDescription).fill(shortDescription); await this.page.waitForSelector('.CodeMirror'); await this.page.evaluate(() => { const codeMirrorElement = document.querySelector('.CodeMirror'); codeMirrorElement.CodeMirror.setValue('Crispy Chicken Tandori'); }); await this.page.locator(this.productImage).click(); await this.page.locator(this.uploadImage).setInputFiles("./pages/TestData/Tandori.jpg"); await this.page.locator(this.saveButton).click(); } async addProductFunctionality1(productName, productPrize, productQuantity, orderLimitvalue, taxin, shortDescription){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.addProductButton).click(); await this.page.locator(this.productName).fill(productName); await this.page.locator(this.productPrize).fill(productPrize); await this.page.locator(this.managedRadioButton).check(); await this.page.locator(this.productQuantityValue).fill(productQuantity); await this.page.locator(this.orderLimit).fill(orderLimitvalue); await this.page.locator(this.taxIn).fill(taxin); await this.page.locator(this.productAvailableCheck).check(); await this.page.locator(this.isLiveCheck).check(); await this.page.locator(this.shortDescription).fill(shortDescription); await this.page.waitForSelector('.CodeMirror'); await this.page.evaluate(() => { const codeMirrorElement = document.querySelector('.CodeMirror'); codeMirrorElement.CodeMirror.setValue('Yummy! Delicious Taste, LifteTime Settlement'); }); await this.page.locator(this.productImage).click(); await this.page.locator(this.uploadImage).setInputFiles("./pages/TestData/Chicken Lollipop.jpg"); await this.page.locator(this.saveButton).click(); } //Working of Search Product Button async searchProductName(productName){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.productListButton).click(); await this.page.locator(this.searchProduct).fill(productName); await this.page.locator(this.searchButton).click(); } //Working of Edit Button async editProduct(){ await this.page.locator(this.productsButton).click(); await this.page.locator(this.productListButton).click(); await this.page.locator(this.edittButton).click(); await this.page.locator(this.productAvailableCheck).click(); await this.page.locator(this.saveButton).click(); } //delete product after storing async deleteProduct(){ //Delete the Product from product list after assertion await this.page.locator(this.editButtonAssertion).click(); await this.page.locator(this.deleteButtonAssertion).click(); await this.page.waitForTimeout(5000); await this.page.locator(this.deleteitAssertion).click(); await this.page.close(); } }