import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase import static com.kms.katalon.core.testdata.TestDataFactory.findTestData import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile import com.kms.katalon.core.model.FailureHandling as FailureHandling import com.kms.katalon.core.testcase.TestCase as TestCase import com.kms.katalon.core.testdata.TestData as TestData import com.kms.katalon.core.testobject.TestObject as TestObject import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI import internal.GlobalVariable as GlobalVariable import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory import java.math.RoundingMode as RoundingMode import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject WebUI.openBrowser('') WebUI.setViewPortSize(1360, 978) WebUI.deleteAllCookies() /* Inital Navigation to Product Page */ WebUI.callTestCase(findTestCase('Functions/LandingPage/Stage_Prod_Dev_Navigation'), [:], FailureHandling.STOP_ON_FAILURE) /* Now saving the Product name and saving into a Variable pdp_product_name and then printing it in the Logs */ WebUI.verifyElementPresent(findTestObject('Page_PDP/PDP_Product_Name'), 0) pdp_product_name = WebUI.getText(findTestObject('Page_PDP/PDP_Product_Name')) WebUI.println('The Product Name is : ' + pdp_product_name) /* Now saving the type of Product showing up on PDP page into a Variable pdp_product_type and then printing it in the Logs */ WebUI.verifyElementPresent(findTestObject('Page_PDP/PDP_Product_Type'), 0) pdp_product_type = WebUI.getText(findTestObject('Page_PDP/PDP_Product_Type')).replace('/', '') WebUI.println('The Product Type is : ' + pdp_product_type) /* Now saving the type of Product showing up on PDP page into a Variable pdp_product_type and then printing it in the Logs */ WebUI.verifyElementPresent(findTestObject('Page_PDP/Product_Color_PDP'), 0) pdp_color_type = WebUI.getText(findTestObject('Page_PDP/Product_Color_PDP')) WebUI.println('The Product Color is : ' + pdp_color_type) WebUI.verifyElementNotClickable(findTestObject('Page_PDP/Button_Add_to_Cart_Button_Disabled')) /* Using JavaScript to Click on the Object Dynamically_Selecting_First_Available_Size*/ WebUI.callTestCase(findTestCase('Functions/PDP/Selecting_1st_Size_Dynamically_on_PDP'), [:], FailureHandling.STOP_ON_FAILURE) /* Checking if the Product is on Sale, If it is on Sale the Script will pickup the Sale Price otherwise it will take Normal Price */ BigDecimal pdp_product_price if (WebUI.verifyElementPresent(findTestObject('Page_PDP/Product_Price/Sale_Price'), 5, FailureHandling.OPTIONAL)) { pdp_product_price_1 = WebUI.getText(findTestObject('Page_PDP/Product_Price/Product_Price_After_Sale')).replace( '$', '') pdp_product_price = new BigDecimal(pdp_product_price_1) assert pdp_product_price != '0.00' assert pdp_product_price != '0' WebUI.println('The Product is on Sale and Sale Price is : ' + pdp_product_price) } else { pdp_product_price_1 = WebUI.getText(findTestObject('Page_PDP/Product_Price/Product_Price_No_Sale')).replace( '$', '') pdp_product_price = new BigDecimal(pdp_product_price_1) assert pdp_product_price != '0.00' assert pdp_product_price != '0' WebUI.println('The Product is not on Sale and Price is : ' + pdp_product_price) } /* Saving Current Quantity to current_pdp_quantity_1 and then validating if it is equal to 1 */ current_pdp_quantity_1 = WebUI.getAttribute(findTestObject('Page_PDP/PDP_Product_Quantity'), 'value') assert current_pdp_quantity_1.equals('1') BigDecimal current_pdp_quantity = new BigDecimal(current_pdp_quantity_1) WebUI.takeScreenshot() WebUI.println('The current quantity on PDP Page is : ' + current_pdp_quantity) /*Next Statement will generate a random number between 1 and 10 and based on that number it will click on the + button on the PDP Page */ Select_Increment_PDP_Quantity_1 = (new Random().nextInt((10 - 1) + 1) + 1) WebUI.println('The random number for clicks on + button given by Script is : ' + Select_Increment_PDP_Quantity_1) for (int Increase_PDP_Quantity = 0; Increase_PDP_Quantity < Select_Increment_PDP_Quantity_1; Increase_PDP_Quantity++) { WebUI.click(findTestObject('Page_PDP/Button_Increase_Cart_Quantity_By_1')) WebUI.takeScreenshot() WebUI.delay(1) } def Select_Increment_PDP_Quantity = Select_Increment_PDP_Quantity_1.toInteger() WebUI.println('The Select_Increment_Quantity after convering all the Increment Operation : ' + Select_Increment_PDP_Quantity) /* Saving Current Quantity to current_pdp_quantity_after_increment and then validating if it is equal to the expected_pdp_quantity_after_increment. To do that it would also need to Calcualte expected_pdp_quantity_after_increment */ current_pdp_quantity_after_increment_1 = WebUI.getAttribute(findTestObject('Page_PDP/PDP_Product_Quantity'), 'value') /* Converting current_pdp_quantity_after_increment_1 to BigDecimal */ BigDecimal current_pdp_quantity_after_increment = new BigDecimal(current_pdp_quantity_after_increment_1) WebUI.println('The current PDP quantity after increment is : ' + current_pdp_quantity_after_increment) /* Calculating expected_pdp_quantity_after_increment */ expected_pdp_quantity_after_increment_1 = current_pdp_quantity.plus(Select_Increment_PDP_Quantity) /* Converting expected_pdp_quantity_after_increment_1 to BigDecimal*/ BigDecimal expected_pdp_quantity_after_increment = new BigDecimal(expected_pdp_quantity_after_increment_1) WebUI.println('The expected pdp quantity after increment should be : ' + expected_pdp_quantity_after_increment) /* Asserting if the current_pdp_quantity_after_increment is equalt to expected_pdp_quantity_after_increment */ assert current_pdp_quantity_after_increment.equals(expected_pdp_quantity_after_increment) /*Next Statement will generate a random number between 1 and value of Select_Increment_Quantity and based on that number it will click on the - button */ Select_decrement_PDP_Quantity_1 = (new Random().nextInt((Select_Increment_PDP_Quantity - 1) + 1) + 1) WebUI.println('The random number for clicks on - button given by Script is : ' + Select_decrement_PDP_Quantity_1) for (int Decrease_Quantity = 0; Decrease_Quantity < Select_decrement_PDP_Quantity_1; Decrease_Quantity++) { WebUI.click(findTestObject('Page_PDP/Button_Decrease_Cart_Quantity_By_1')) WebUI.takeScreenshot() WebUI.delay(1) } def Select_decrement_PDP_Quantity = Select_decrement_PDP_Quantity_1.toInteger() WebUI.println('The Select_decrement_PDP_Quantity after convering all the decrement Operation : ' + Select_decrement_PDP_Quantity) /* Saving Current Quantity to current_pdp_quantity_after_decrement and then validating if it is equal to the expected_pdp_quantity_after_decrement. To do that it would also need to Calcualte expected_pdp_quantity_after_decrement */ current_pdp_quantity_after_decrement_1 = WebUI.getAttribute(findTestObject('Page_PDP/PDP_Product_Quantity'), 'value') /* Converting current_pdp_quantity_after_decrement_1 to BigDecimal */ BigDecimal current_pdp_quantity_after_decrement = new BigDecimal(current_pdp_quantity_after_decrement_1) WebUI.println('The current PDP quantity after decrement is : ' + current_pdp_quantity_after_decrement_1) /* Calculating expected_pdp_quantity_after_decrement */ expected_pdp_quantity_after_decrement_1 = current_pdp_quantity_after_increment.minus(Select_decrement_PDP_Quantity) /* Converting expected_pdp_quantity_after_decrement_1 to BigDecimal*/ BigDecimal expected_pdp_quantity_after_decrement = new BigDecimal(expected_pdp_quantity_after_decrement_1) WebUI.println('The expected pdp quantity after decrement should be : ' + expected_pdp_quantity_after_decrement) /* Asserting if the current_pdp_quantity_after_decrement is equal to expected_pdp_quantity_after_decrement */ assert current_pdp_quantity_after_decrement.equals(expected_pdp_quantity_after_decrement) WebUI.callTestCase(findTestCase('Smoke Test - Jenkins/1_Test'), [:], FailureHandling.STOP_ON_FAILURE) /* The Script will generate a random numnber and if the randmon number is even then it will click on edit Cart and navigate to the Cart page otherwise it will direclty go to checkout page by clicking Checkout button */ int NavigatetoCart = ((org.apache.commons.lang.RandomStringUtils.randomNumeric(1)) as int) BigDecimal slideoutcart_expected_total if ((NavigatetoCart % 2) != 0) { WebUI.println('The Random Number generated by Script is odd so the script will not click on edit Cart to navigate to the Cart page, It will direclty go to checkout page by clicking Checkout button') WebUI.println('The script will calculate expected subtotal by multiplying current_pdp_quantity_after_decrement with pdp_product_price ') WebUI.println('The current_pdp_quantity_after_decrement is ' + current_pdp_quantity_after_decrement) WebUI.println('The pdp_product_price from PDP page is ' + pdp_product_price) slideoutcart_expected_total_before_rounding = pdp_product_price.multiply(current_pdp_quantity_after_decrement) WebUI.println('The expected total on Slideout Cart should be ( before rounding ): ' + slideoutcart_expected_total_before_rounding) slideoutcart_expected_total_1 = new BigDecimal(slideoutcart_expected_total_before_rounding) slideoutcart_expected_total = slideoutcart_expected_total_1.setScale(2, RoundingMode.DOWN) WebUI.println('The expected total on Slideout Cart should be ( after rounding ) : ' + slideoutcart_expected_total) long startTime_3 = System.currentTimeMillis(); WebUI.click(findTestObject('Page_PDP/Slide_Out_Cart/Checkout_Button')) WebUI.waitForPageLoad(0) long endTime_3 = System.currentTimeMillis(); long elapsedTime_3 = endTime_3 - startTime_3 ; def LoadTimeInSeconds_3 = (elapsedTime_3 / 1000) System.out.println("Total Time in seconds taken to land on customer information page from Slide out Cart is - " + LoadTimeInSeconds_3); } BigDecimal expected_total_item_wise_after_decrement if ((NavigatetoCart % 2) == 0) { println('The Random Number generated by Script is Even and is : ' + NavigatetoCart) long startTime_4 = System.currentTimeMillis(); WebUI.click(findTestObject('Page_PDP/Slide_Out_Cart/Cart_Edit_Link')) WebUI.waitForPageLoad(0) long endTime_4 = System.currentTimeMillis(); long elapsedTime_4 = endTime_4 - startTime_4 ; def LoadTimeInSeconds_4 = (elapsedTime_4 / 1000) System.out.println("Total Time in seconds taken to land on cart page from Slide out Cart is - " + LoadTimeInSeconds_4); /* Starting Shopping Cart page */ WebUI.delay(GlobalVariable.ShortDelay) /* Performing Cart Page Verifications */ WebUI.callTestCase(findTestCase('Functions/Cart/Cart_Page_Verification'), [:], FailureHandling.STOP_ON_FAILURE) /* Testing if the Product added to Cart is same as on PDP Page */ shopping_cart_product_name = WebUI.getText(findTestObject('Shopping_Cart_Page/Cart Item Name')) CustomKeywords.'kms.turing.katalon.plugins.assertj.StringAssert.equals'(shopping_cart_product_name, pdp_product_name, false, 'Testing Product Name on Customer Information Page', FailureHandling.STOP_ON_FAILURE) /* Testing if the Quantity on Shopping Cart page is same as of PDP Page */ current_quantity_shopping_cart_1 = WebUI.getAttribute(findTestObject('Shopping_Cart_Page/Shopping_Cart_Product_Quantity'), 'value') BigDecimal current_quantity_shopping_cart = new BigDecimal(current_quantity_shopping_cart_1) assert current_quantity_shopping_cart.equals(current_pdp_quantity_after_decrement) WebUI.println('The current quantity on Shopping Cart Page is : ' + current_quantity_shopping_cart) /* Saving the Item total on Shopping Cart page to total_item_wise and then validating if it is equal to expected_total_item_wise total */ total_item_wise_1 = WebUI.getText(findTestObject('Shopping_Cart_Page/Total_Item_Wise')).replace('$', '') /* total_item_wise_0 = total_item_wise_1.replace('.00', '') */ BigDecimal total_item_wise = new BigDecimal(total_item_wise_1) /* Calculating expected_total_item_wise */ expected_total_item_wise_1 = pdp_product_price.multiply(current_pdp_quantity_after_decrement) /* Converting expected_pdp_quantity_after_decrement_1 to BigDecimal*/ BigDecimal expected_total_item_wise_00 = new BigDecimal(expected_total_item_wise_1) WebUI.println('The expected_total_item_wise should be (This is before any rounding off) : ' + expected_total_item_wise_00) /* Converting expected_total_item_wise_00 into 2 decimal places */ expected_total_item_wise = expected_total_item_wise_00.setScale(2, RoundingMode.DOWN) WebUI.println('The expected_total_item_wise should be (This is after rounding off) : ' + expected_total_item_wise) /* Checking if the total_item_wise is equal to expected_total_item_wise*/ assert total_item_wise.equals(expected_total_item_wise) WebUI.println('Total Item for selected item on Shopping Cart Page is : ' + total_item_wise) /*Next Statement will generate a random number between 1 and 10 and based on that number it will click on the + button */ Select_Cart_Increment_Quantity_1 = (new Random().nextInt((10 - 1) + 1) + 1) WebUI.println('The random number for clicks on + button given by Script is (before converting to BigDecimal): ' + Select_Cart_Increment_Quantity_1) for (int Increase_Cart_Quantity = 0; Increase_Cart_Quantity < Select_Cart_Increment_Quantity_1; Increase_Cart_Quantity++) { WebUI.click(findTestObject('Shopping_Cart_Page/Button_Increase_Quantity')) WebUI.takeScreenshot() WebUI.delay(1) } /* BigDecimal Select_Increment_Quantity = new BigDecimal(Select_Increment_Quantity_1) */ def Select_Cart_Increment_Quantity = Select_Cart_Increment_Quantity_1.toInteger() WebUI.println('The Select_Cart_Increment_Quantity after converting to BigDecimal is : ' + Select_Cart_Increment_Quantity) /* The script will click on Update Cart button to See if the Update to Quantity is getting reflected on Shopping Cart page in terms of Quantity and Price */ WebUI.click(findTestObject('Shopping_Cart_Page/Button_Update_Cart')) /* Saving Current Quantity on Shopping Cart Page to current_quantity_shopping_cart and then validating if it is equal to the expected Quantity after the Increment Quantity Step */ current_quantity_shopping_cart_after_increment_1 = WebUI.getAttribute(findTestObject('Shopping_Cart_Page/Shopping_Cart_Product_Quantity'), 'value') BigDecimal current_quantity_shopping_cart_after_increment = new BigDecimal(current_quantity_shopping_cart_after_increment_1) WebUI.println('The Current Quantity after increment is : ' + current_quantity_shopping_cart_after_increment) /* Finding expected quantity by adding current_quantity_shopping_cart + Select_Increment_Quantity */ expected_quantity_shopping_cart_after_increment_1 = current_quantity_shopping_cart.plus(Select_Cart_Increment_Quantity) BigDecimal expected_quantity_shopping_cart_after_increment = new BigDecimal(expected_quantity_shopping_cart_after_increment_1) WebUI.println('The expected_quantity should be : ' + expected_quantity_shopping_cart_after_increment) /* Determinig if Quantity after increment is equal to Expected Quantity after increment */ assert current_quantity_shopping_cart_after_increment.equals(expected_quantity_shopping_cart_after_increment) /* Now verifying if the Price is showing up correctly after increment. To do that the Script will grab the Value of price on the Shopping Cart page */ total_item_wise_after_increment_1 = WebUI.getText(findTestObject('Shopping_Cart_Page/Total_Item_Wise')).replace('$', '') BigDecimal total_item_wise_after_increment = new BigDecimal(total_item_wise_after_increment_1) WebUI.println('Total for the Item on Shopping Cart Page after increment is : ' + total_item_wise_after_increment) /* The Script will now calcuate the Expected total. To do that the Script will mulltiply total_item_wise by expected_quantity_shopping_cart_after_increment */ expected_total_item_wise_after_increment_1 = pdp_product_price.multiply(expected_quantity_shopping_cart_after_increment) WebUI.println('The expected total after increment should be (This is before any rounding off) and before making it BigDecimal : ' + expected_total_item_wise_after_increment_1) BigDecimal expected_total_item_wise_after_increment_0 = new BigDecimal(expected_total_item_wise_after_increment_1) WebUI.println('The expected total after increment should be (This is before any rounding off) : ' + expected_total_item_wise_after_increment_0) /* Converting expected_total_item_wise_after_increment_0 into 2 decimal places */ expected_total_item_wise_after_increment = expected_total_item_wise_after_increment_0.setScale(2, RoundingMode.DOWN) WebUI.println('The expected total item wise after increment should be (This is after rounding off) : ' + expected_total_item_wise_after_increment) /* The Script will now verify if expected total item wise is equal to what showing up on the Shopping Cart page */ assert expected_total_item_wise_after_increment.equals(total_item_wise_after_increment) /*Next Statement will generate a random number between 1 and Select_Cart_Increment_Quantity and based on that number it will click on the + button */ Select_Cart_Decrement_Quantity_1 = (new Random().nextInt((Select_Cart_Increment_Quantity - 1) + 1) + 1) WebUI.println('The random number for clicks on - button given by Script is (before converting to BigDecimal): ' + Select_Cart_Decrement_Quantity_1) for (int Decrease_Cart_Quantity = 0; Decrease_Cart_Quantity < Select_Cart_Decrement_Quantity_1; Decrease_Cart_Quantity++) { WebUI.click(findTestObject('Shopping_Cart_Page/Button_Decrease_Quantity')) WebUI.takeScreenshot() WebUI.delay(1) } /* BigDecimal Select_Decrement_Quantity = new BigDecimal(Select_Decrement_Quantity_1) */ def Select_Cart_Decrement_Quantity = Select_Cart_Decrement_Quantity_1.toInteger() WebUI.println('The Select_Cart_Decrement_Quantity after converting to Integer is : ' + Select_Cart_Decrement_Quantity) /* The script will click on Update Cart button to See if the Update to Quantity is getting reflected on Shopping Cart page in terms of Quantity and Price */ WebUI.click(findTestObject('Shopping_Cart_Page/Button_Update_Cart')) /* Saving Current Quantity on Shopping Cart Page to current_quantity_shopping_cart and then validating if it is equal to the expected Quantity after the Increment Quantity Step */ current_quantity_shopping_cart_after_decrement_1 = WebUI.getAttribute(findTestObject('Shopping_Cart_Page/Shopping_Cart_Product_Quantity'), 'value') BigDecimal current_quantity_shopping_cart_after_decrement = new BigDecimal(current_quantity_shopping_cart_after_decrement_1) WebUI.println('The Current Quantity after decrement is : ' + current_quantity_shopping_cart_after_decrement) /* Finding expected quantity by adding current_quantity_shopping_cart + Select_Increment_Quantity */ expected_quantity_shopping_cart_after_decrement_1 = current_quantity_shopping_cart_after_increment.minus(Select_Cart_Decrement_Quantity) BigDecimal expected_quantity_shopping_cart_after_decrement = new BigDecimal(expected_quantity_shopping_cart_after_decrement_1) WebUI.println('The expected_quantity should be : ' + expected_quantity_shopping_cart_after_decrement) /* Determinig if Quantity after decrement is equal to Expected Quantity after increment */ assert current_quantity_shopping_cart_after_decrement.equals(expected_quantity_shopping_cart_after_decrement) /* Now verifying if the Price is showing up correctly after increment. To do that the Script will grab the Value of price on the Shopping Cart page */ total_item_wise_after_decrement_1 = WebUI.getText(findTestObject('Shopping_Cart_Page/Total_Item_Wise')).replace('$', '') BigDecimal total_item_wise_after_decrement = new BigDecimal(total_item_wise_after_decrement_1) WebUI.println('Total for the Item on Shopping Cart Page after decrement is : ' + total_item_wise_after_decrement) /* The Script will now calcuate the Expected total. To do that the Script will mulltiply total_item_wise by expected_quantity_shopping_cart_after_increment */ expected_total_item_wise_after_decrement_1 = pdp_product_price.multiply(expected_quantity_shopping_cart_after_decrement) BigDecimal expected_total_item_wise_after_decrement_0 = new BigDecimal(expected_total_item_wise_after_decrement_1) WebUI.println('The expected total after decrement should be (This is before any rounding off) : ' + expected_total_item_wise_after_decrement_0) /* Converting expected_total_item_wise_after_decrement_0 into 2 decimal places */ expected_total_item_wise_after_decrement = expected_total_item_wise_after_decrement_0.setScale(2, RoundingMode.DOWN) WebUI.println('The expected total item wise after decrement should be (This is after rounding off) : ' + expected_total_item_wise_after_decrement) WebUI.println('The value of expected_total_item_wise_after_decrement is ' + expected_total_item_wise_after_decrement) /* The Script will now verify if expected total item wise is equal to what showing up on the Shopping Cart page */ assert expected_total_item_wise_after_decrement.equals(total_item_wise_after_decrement) WebUI.takeScreenshot() long startTime_5 = System.currentTimeMillis(); WebUI.callTestCase(findTestCase('Functions/Cart/Click_Continue_to_Checkout'), [:], FailureHandling.STOP_ON_FAILURE) WebUI.waitForPageLoad(0) long endTime_5 = System.currentTimeMillis(); long elapsedTime_5 = endTime_5 - startTime_5 ; def LoadTimeInSeconds_5 = (elapsedTime_5 / 1000) System.out.println("Total Time in seconds taken to land on checkout page from Cart page is - " + LoadTimeInSeconds_5); } WebUI.callTestCase(findTestCase('Smoke Test - Jenkins/2_Test'), [:], FailureHandling.STOP_ON_FAILURE) String useremail if (GlobalVariable.Gmail_Address_Use) { String useremail_1 = ('webtest+' + System.currentTimeMillis()) + '@Gmail.com' useremail = new String(useremail_1) WebUI.setText(findTestObject('Customer_Information_Page/Field_Email'), useremail) WebUI.delay(GlobalVariable.ShortDelay) publishuseremail = WebUI.concatenate(((['The email address used in above step is ', useremail]) as String[])) } if (GlobalVariable._Email_Address_Use) { String useremail_1 = 'mr.bean' + '@fakedomain.com' useremail = new String(useremail_1) WebUI.setText(findTestObject('Customer_Information_Page/Field_Email'), useremail) WebUI.delay(GlobalVariable.ShortDelay) publishuseremail = WebUI.concatenate(((['The email address used in above step is ', useremail]) as String[])) } if (GlobalVariable.Mailinator_Email_Address_Use) { def email_beginning = org.apache.commons.lang.RandomStringUtils.randomAlphabetic(12) String useremail_1 = email_beginning + '@mailinator.com' useremail = new String(useremail_1) WebUI.setText(findTestObject('Customer_Information_Page/Field_Email'), useremail) WebUI.delay(GlobalVariable.ShortDelay) publishuseremail = WebUI.concatenate(((['The email address used in above step is ', useremail]) as String[])) } /* Setting up connection to the DB to get First Name */ /* Connection globalConnection = null ResultSet First_Name */ getFirst_Name = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.getGlobalConnection'() /* Quering database to get the First Name */ First_Name = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.executeQuery'(getFirst_Name, 'SELECT FirstName FROM FirstNameLastName ORDER BY RAND() LIMIT 1') /* Moving the Result Set cursor to the Next Cell */ First_Name.next() /* Converting to String */ String First_NameFromDatabase = First_Name.getString(1) /* Using the converted Output to Fill the First Name Field */ WebUI.sendKeys(findTestObject('Customer_Information_Page/Field_First_Name'), First_NameFromDatabase) /* Adding to console incase someone needs to see it */ println('The First Name used in the Field_First_Name is : ' + First_NameFromDatabase) CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.closeConnection'(getFirst_Name) WebUI.delay(GlobalVariable.ShortDelay) /* Setting up connection to the DB to get Last Name */ getLast_Name = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.getGlobalConnection'() /* Quering database to get the Last Name */ Last_Name = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.executeQuery'(getLast_Name, 'SELECT LastName FROM FirstNameLastName ORDER BY RAND() LIMIT 1;') /* Moving the Result Set cursor to the Next Cell */ Last_Name.next() /* Converting to String */ String Last_NameFromDatabase = Last_Name.getString(1) /* Using the converted Output to Fill the Last Name Field */ WebUI.sendKeys(findTestObject('Customer_Information_Page/Field_Last_Name'), Last_NameFromDatabase) /* Adding to console incase someone needs to see it */ println('The Last Name used in the Field_Last_Name is : ' + Last_NameFromDatabase) CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.closeConnection'(getLast_Name) WebUI.delay(GlobalVariable.ShortDelay) /* The Script will generate a random numnber and if the randmon number is even then it will add data to the optional field of Company and if it is odd then it will not fill that out. */ int decide1 = ((org.apache.commons.lang.RandomStringUtils.randomNumeric(1)) as int) if ((decide1 % 2) != 0) { println('The Random Number generated by Script is odd so the script will not fill the Company Information field with data.') } if ((decide1 % 2) == 0) { println('The Random Number generated by Script is Even and is : ' + decide1) getCompany_Information = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.getGlobalConnection'() Company_Information = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.executeQuery'(getCompany_Information, 'Select * from Company_Data ORDER BY RAND() LIMIT 1;') Company_Information.next() String Company_InformationFromDatabase = Company_Information.getString(1) WebUI.sendKeys(findTestObject('Customer_Information_Page/Field_Company_Information'), Company_InformationFromDatabase) CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.closeConnection'(getCompany_Information) } /* The Script will generate a random numnber and if the randmon number is even then it will add data to the optional field of Apartment and if it is odd then it will not fill that out. */ int decide2 = ((org.apache.commons.lang.RandomStringUtils.randomNumeric(1)) as int) if ((decide2 % 2) != 0) { println('The Random Number generated by Script is odd so the script will not fill the Apartment Number Field with data.') } if ((decide2 % 2) == 0) { println('The Random Number generated by Script is Even and is : ' + decide2) def suitenumber = org.apache.commons.lang.RandomStringUtils.randomNumeric(3) WebUI.sendKeys(findTestObject('Customer_Information_Page/Field_Apartment_Suite'), suitenumber) } WebUI.click(findTestObject('Customer_Information_Page/Field_Company_Information')) WebUI.delay(GlobalVariable.ShortDelay) /* Generating Google Suggestion to fill in the Shipping Address Section */ WebUI.callTestCase(findTestCase('Functions/CIP/Shipping_Address_Google_Suggestion_Generate'), [:], FailureHandling.STOP_ON_FAILURE) getshipping_phone_number = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.getGlobalConnection'() shipping_phone_number = CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.executeQuery'(getshipping_phone_number, 'SELECT FLOOR(RAND()*(9999999999-1+1)+1);') shipping_phone_number.next() String shippingphone_number = shipping_phone_number.getString(1) WebUI.setText(findTestObject('Customer_Information_Page/Field_Phone'), shippingphone_number) CustomKeywords.'com.katalon.plugin.keyword.connection.DatabaseKeywords.closeConnection'(getshipping_phone_number) WebUI.takeScreenshot() WebUI.scrollToPosition(900, 900) WebUI.delay(GlobalVariable.LongDelay) /* cip_product_name_1 = WebUI.getText(findTestObject('Customer_Information_Page/Product_Name')) */ cip_product_name_1 = WebUI.getAttribute(findTestObject('Customer_Information_Page/Product_Name'), 'textContent', FailureHandling.STOP_ON_FAILURE).trim() not_run: assert pdp_product_name.equals(cip_product_name_1) CustomKeywords.'kms.turing.katalon.plugins.assertj.StringAssert.equals'(cip_product_name_1, pdp_product_name, false, 'Testing Product Name on Customer Information Page', FailureHandling.STOP_ON_FAILURE) String js = 'return document.querySelector(\'td.product__price>span.order-summary__emphasis\').innerText' String cip_product_price_with_dollar = WebUI.executeJavaScript(js, null) WebUI.println('The cip_product_price is : ' + cip_product_price_with_dollar) cip_product_price = cip_product_price_with_dollar.replace('$', '') BigDecimal cip_product_price_1 = new BigDecimal(cip_product_price) /* Saving the product price on the Customer Information page into varibale cip_product_price_1 . The Variable value will be saved without $ ' */ /* cip_product_price = WebUI.getText(findTestObject('Customer_Information_Page/Product_Price')).replace(/\$/, '') */ /* cip_product_price = WebUI.getText(findTestObject('Customer_Information_Page/Product_Price')).replace('$', '') */ /* cip_product_price = WebUI.getAttribute(findTestObject('Customer_Information_Page/Product_Price'), FailureHandling.STOP_ON_FAILURE).replace('$', '') */ /* Converting the value of cip_product_price_1 to BigDecimal ' */ /* BigDecimal cip_product_price_1 = new BigDecimal(cip_product_price) */ if ((NavigatetoCart % 2) != 0) { println('The Random Number generated by Script to decide if it should go to Cart page or not was odd so the script didnt went to Cart page, So the cip_product_price_1 will be matched with ') assert cip_product_price_1.equals(slideoutcart_expected_total) } if ((NavigatetoCart % 2) == 0) { println('The Random Number generated by Script to decide if it should go to Cart page or not was even so it went to cart page and the calculation of expected_total_item_wise_after_decrement was done at Cart page itself') assert cip_product_price_1.equals(expected_total_item_wise_after_decrement) } /* WebUI.println('The Item Price on the Customer Information Page is : ' + cip_product_price_1) */ cip_subtotal_1 = WebUI.getText(findTestObject('Customer_Information_Page/Subtotal_Value')).replace('$', '') BigDecimal cip_subtotal = new BigDecimal(cip_subtotal_1) if ((NavigatetoCart % 2) != 0) { println('The Random Number generated by Script to decide if it should go to Cart page or not was odd so the script didnt went to Cart page, So the cip_subtotal will be matched with slideoutcart_expected_total') assert cip_subtotal.equals(slideoutcart_expected_total) } if ((NavigatetoCart % 2) == 0) { println('The Random Number generated by Script to decide if it should go to Cart page or not was even so it went to cart page and the calculation of expected_total_item_wise_after_decrement was done at Cart page itself') assert cip_subtotal.equals(expected_total_item_wise_after_decrement) } WebUI.println('The Value for Subtotal Field should be : ' + cip_subtotal_1) shipping_value = WebUI.getText(findTestObject('Customer_Information_Page/Shipping_Value')) shipping_value = WebUI.getAttribute(findTestObject('Customer_Information_Page/Shipping_Value'), 'textContent', FailureHandling.STOP_ON_FAILURE).trim() System.out.println(shipping_value) assert shipping_value.equals('Calculated at next step') /* Clicking on Continue to Shipping Method Page */ WebUI.callTestCase(findTestCase('Functions/CIP/Click_Continue_To_Shipping_Method'), [:], FailureHandling.STOP_ON_FAILURE) WebUI.delay(GlobalVariable.LongDelay) WebUI.callTestCase(findTestCase('Smoke Test - Jenkins/3_Test'), [:], FailureHandling.STOP_ON_FAILURE) smp_useremail = WebUI.getText(findTestObject('Shipping_Method_Page/User_Email_Address')) WebUI.verifyEqual(smp_useremail, useremail) if (GlobalVariable.IsRegionCA) { if (pdp_product_price >= 50) { WebUI.verifyElementText(findTestObject('Shipping_Method_Page/CA_Shipping/Shipping_Text_Free Shipping Over 50.00'), 'Free Shipping Over $50.00') } WebUI.verifyElementText(findTestObject('Shipping_Method_Page/CA_Shipping/Shipping_Text_Canadian Regular 5-7 Business Days'), 'Canadian Regular 5-7 Business Days') WebUI.verifyElementText(findTestObject('Shipping_Method_Page/CA_Shipping/Shipping_Text_Canadian Express 2-3 Business Days'), 'Canadian Express 2-3 Business Days') } if (GlobalVariable.IsRegionUS) { if (pdp_product_price >= 50) { WebUI.verifyElementText(findTestObject('Shipping_Method_Page/US_Shipping/Shipping_Text_Free Shipping Over 50'), 'Free Shipping Over $50.00') } WebUI.verifyElementText(findTestObject('Shipping_Method_Page/US_Shipping/Shipping_Text_US Expedited 2-3 Business Days'), 'US Expedited 2-3 Business Days') WebUI.verifyElementText(findTestObject('Shipping_Method_Page/US_Shipping/Shipping_Text_US Regular 5-7 Business Days'), 'US Regular 5-7 Business Days') WebUI.verifyElementText(findTestObject('Shipping_Method_Page/US_Shipping/Shipping_Text_US Express 1-2 Business Days'), 'US Express 1-2 Business Days') } WebUI.callTestCase(findTestCase('Smoke Test - Jenkins/4_Test'), [:], FailureHandling.STOP_ON_FAILURE) WebUI.switchToFrame(findTestObject('Payments_Page/iframe_Cardholder_name'), 30) cardholdername = WebUI.concatenate((([First_NameFromDatabase, ' ', Last_NameFromDatabase]) as String[])) WebUI.setText(findTestObject('Payments_Page/Field_Cardholder_Name'), cardholdername) publishcardholdername = WebUI.concatenate(((['The card holder name used in the above step is', ' ', cardholdername]) as String[])) WebUI.comment(publishcardholdername) WebUI.switchToDefaultContent() WebUI.callTestCase(findTestCase('Smoke Test - Jenkins/5_Test'), [:], FailureHandling.STOP_ON_FAILURE)