├── Ajio.java ├── Azure.java ├── BigBasket.java ├── CrmCloud.java ├── Honda.java ├── MakeMyTrip.java ├── Myntra.java ├── Nyka.java ├── PepperFry.java ├── README.md └── Snapdeal.java /Ajio.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Keys; 9 | import org.openqa.selenium.UnexpectedAlertBehaviour; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.chrome.ChromeDriver; 12 | import org.openqa.selenium.chrome.ChromeOptions; 13 | import org.openqa.selenium.interactions.Actions; 14 | import org.openqa.selenium.remote.CapabilityType; 15 | import org.openqa.selenium.remote.DesiredCapabilities; 16 | import org.openqa.selenium.remote.RemoteWebDriver; 17 | import org.openqa.selenium.support.ui.ExpectedConditions; 18 | import org.openqa.selenium.support.ui.WebDriverWait; 19 | 20 | public class Ajio { 21 | 22 | public static RemoteWebDriver driver; 23 | public static void main(String[] args) throws InterruptedException { 24 | 25 | 26 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 27 | System.setProperty("webdriver.chrome.silentOutput", "true"); 28 | 29 | ChromeOptions options = new ChromeOptions(); 30 | options.addArguments("--disable-notifications"); 31 | 32 | DesiredCapabilities cap = new DesiredCapabilities(); 33 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 34 | options.merge(cap); 35 | 36 | driver = new ChromeDriver(options); 37 | Actions action = new Actions(driver); 38 | WebDriverWait wait = new WebDriverWait(driver, 30); 39 | 40 | 41 | driver.get("https://www.ajio.com/shop/sale"); 42 | driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS); 43 | driver.manage().window().maximize(); 44 | Thread.sleep(20000); 45 | 46 | //2) Enter Bags in the Search field and Select Bags in Women Handbags 47 | WebElement search = driver.findElementByXPath("//input[@placeholder = 'Search AJIO']"); 48 | action.click(search).build().perform(); 49 | search.sendKeys("Bags"); 50 | WebElement WomenBags = driver.findElementByXPath("(//span[text() = 'Women Handbags'])[1]"); 51 | wait.until(ExpectedConditions.elementToBeClickable(WomenBags)); 52 | action.click(WomenBags).build().perform(); 53 | 54 | //System.out.println("Bags are searched"); 55 | Thread.sleep(10000); 56 | 57 | //3) Click on five grid and Select SORT BY as "What's New" 58 | WebElement fiveGrid = driver.findElementByXPath("//div[@class = 'five-grid']"); 59 | action.click(fiveGrid).build().perform(); 60 | Thread.sleep(5000); 61 | 62 | //4) Enter Price Range Min as 2000 and Max as 5000 63 | driver.findElementByXPath("//span[text() = 'price']").click(); 64 | 65 | WebElement minPrice = driver.findElementByXPath("//input[@id = 'minPrice']"); 66 | WebElement maxPrice = driver.findElementByXPath("//input[@id = 'maxPrice']"); 67 | 68 | wait.until(ExpectedConditions.visibilityOf(minPrice)); 69 | 70 | minPrice.sendKeys("2000"); 71 | maxPrice.sendKeys("5000"); 72 | 73 | driver.findElementByXPath("(//button[@type = 'submit'])[2]").click(); 74 | //System.out.println("Product filtered with Price range"); 75 | 76 | //5) Click on the product "Puma Ferrari LS Shoulder Bag" 77 | 78 | driver.findElementByXPath("//img[contains(@alt,'Ferrari LS Shoulder Bag')]").click(); 79 | //System.out.println("Puma Bag selected"); 80 | Thread.sleep(10000); 81 | 82 | Set windows = driver.getWindowHandles(); 83 | List windowsList = new ArrayList(windows); 84 | driver.switchTo().window(windowsList.get(1)); 85 | System.out.println("User Navigated to new Window"); 86 | System.out.println(driver.getTitle()); 87 | 88 | 89 | //6) Verify the Coupon code for the price above 2690 is applicable for your product, 90 | //if applicable the get the Coupon Code and Calculate the discount price for the coupon 91 | WebElement eleBagPrice = driver.findElementByXPath("//div[@class='prod-sp']"); 92 | String BagPriceStr = eleBagPrice.getText(); 93 | Integer BagPrice = Integer.parseInt(BagPriceStr.replaceAll("\\D", "")); 94 | System.out.println("Bag Price is "+ BagPrice); 95 | 96 | WebElement elePromoPrice = driver.findElementByXPath("//div[@class='promo-desc']"); 97 | String strPromoPrice = elePromoPrice.getText(); 98 | //System.out.println(strPromoPrice); 99 | Integer DiscountPercentage = Integer.parseInt(strPromoPrice.replaceAll("\\D", "").substring(0, 2)); 100 | Integer PromoPrice = Integer.parseInt(strPromoPrice.replaceAll("\\D", "").substring(2, 6)); //Because replacing all the non integers give the percentage and price alone. Discount can never be 3 digits - 100%, hence always this code gives a 6 digit number 101 | 102 | System.out.println("Promotional Price Limit is " +PromoPrice); 103 | //System.out.println("Discount Percentage is " +DiscountPercentage); 104 | int intPriceBeforeCheckout = 0; 105 | if (BagPrice>PromoPrice) { 106 | System.out.println("Product Applicable for Discount"); 107 | double DiscountedPrice = BagPrice - (DiscountPercentage*BagPrice/100); 108 | intPriceBeforeCheckout= (int)Math.round(DiscountedPrice); 109 | System.out.println("Bag Price after Discount is " + intPriceBeforeCheckout); 110 | 111 | } 112 | else 113 | { 114 | System.out.println("Product Not Applicable for Discount"); 115 | } 116 | 117 | 118 | //7) Check the availability of the product for pincode 560043, 119 | //print the expected delivery date if it is available 120 | WebElement enterPincode = driver.findElementByXPath("//span[contains(text(),'Enter pin-code')]"); 121 | action.click(enterPincode).build().perform(); 122 | 123 | WebElement pincodePopup = driver.findElementByXPath("//input[@name='pincode']"); 124 | wait.until(ExpectedConditions.elementToBeClickable(pincodePopup)); 125 | 126 | pincodePopup.sendKeys("560043", Keys.ENTER); 127 | 128 | String EstimatedDelivery = driver.findElementByXPath("//div[contains(@class,'edd-pincode-msg-details')]").getText(); 129 | System.out.println("Estimated Delivery date is " +EstimatedDelivery); 130 | 131 | 132 | //8) Click on Other Informations under Product Details and 133 | //Print the Customer Care address, phone and email 134 | WebElement moreInformation = driver.findElementByXPath("//div[@class='other-info-toggle']"); 135 | moreInformation.click(); 136 | //System.out.println("More information about the Product is displayed"); 137 | 138 | WebElement CustomerCare = driver.findElementByXPath("//span[text()='Customer Care Address']//following::span[@class='other-info']"); 139 | System.out.println(CustomerCare.getText()); 140 | 141 | 142 | //9) Click on ADD TO BAG and then GO TO BAG 143 | driver.findElementByXPath("//span[text()='ADD TO BAG']").click(); 144 | //System.out.println("Product Added to Bag"); 145 | Thread.sleep(10000); 146 | WebElement eleGoToBag = driver.findElementByXPath("//span[text()='GO TO BAG']"); 147 | wait.until(ExpectedConditions.elementToBeClickable(eleGoToBag)); 148 | 149 | action.click(eleGoToBag).build().perform(); 150 | //System.out.println("User navigates to Cart page"); 151 | 152 | //10) Check the Order Total before apply coupon 153 | WebElement eleOrderTotal = driver.findElementByXPath("//span[text()='Order Total']//following-sibling::span"); 154 | String strOrderTotal = eleOrderTotal.getText(); 155 | 156 | Double doubleOrderTotal = Double.parseDouble(strOrderTotal.replaceAll("\\D", "")); 157 | int OrderTotal = (int) Math.round(doubleOrderTotal); 158 | System.out.println(doubleOrderTotal); 159 | System.out.println("Order Total of the Product is "+OrderTotal); 160 | 161 | //11) Enter Coupon Code and Click Apply 162 | WebElement eleCouponCode = driver.findElementByXPath("//input[@id='EPIC']"); 163 | action.click(eleCouponCode).build().perform(); 164 | 165 | driver.findElementByXPath("//button[text()='Apply']").click(); 166 | //System.out.println("Coupon Code Applied"); 167 | 168 | //12) Verify the Coupon Savings amount(round off if it in decimal) under Order Summary 169 | //and the matches the amount calculated in Product details 170 | WebElement elePriceAfterDiscount = driver.findElementByXPath("//div[contains(@class,'net-price best-price-strip')]"); 171 | String strPriceAfterDiscount = elePriceAfterDiscount.getText(); 172 | System.out.println(strPriceAfterDiscount); 173 | Double PriceAfterDiscount = Double.parseDouble(strPriceAfterDiscount.replaceAll("\\D", "")); 174 | int intPriceAfterCheckout = (int) Math.round(PriceAfterDiscount); 175 | System.out.println("Price After Discount is " +intPriceAfterCheckout); 176 | 177 | if(intPriceAfterCheckout == intPriceBeforeCheckout) 178 | { 179 | System.out.println("Price Before Checkout and Price After Checkout is a match"); 180 | } 181 | 182 | //13) Click on Delete and Delete the item from Bag 183 | 184 | driver.findElementByXPath("//div[text()='delete-btn'").click(); 185 | 186 | //14) Close all the browsers 187 | driver.quit(); 188 | 189 | 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /Azure.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.io.File; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.UnexpectedAlertBehaviour; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.remote.CapabilityType; 14 | import org.openqa.selenium.remote.DesiredCapabilities; 15 | import org.openqa.selenium.remote.RemoteWebDriver; 16 | import org.openqa.selenium.support.ui.ExpectedConditions; 17 | import org.openqa.selenium.support.ui.Select; 18 | import org.openqa.selenium.support.ui.WebDriverWait; 19 | 20 | public class Azure { 21 | 22 | public static RemoteWebDriver driver; 23 | 24 | public static void main(String[] args) throws InterruptedException { 25 | 26 | 27 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 28 | System.setProperty("webdriver.chrome.silentOutput", "true"); 29 | 30 | ChromeOptions options = new ChromeOptions(); 31 | options.addArguments("--disable-notifications"); 32 | 33 | DesiredCapabilities cap = new DesiredCapabilities(); 34 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 35 | options.merge(cap); 36 | 37 | driver = new ChromeDriver(options); 38 | Actions action = new Actions(driver); 39 | WebDriverWait wait = new WebDriverWait(driver, 30); 40 | 41 | 42 | driver.get("https://azure.microsoft.com/en-in/"); 43 | driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS); 44 | driver.manage().window().maximize(); 45 | Thread.sleep(20000); 46 | System.out.println("User Enters Home Screen"); 47 | 48 | WebElement elePricing = driver.findElementByLinkText("Pricing"); 49 | action.click(elePricing).build().perform(); 50 | Thread.sleep(5000); 51 | System.out.println("Pricing Clicked"); 52 | 53 | driver.findElementByLinkText("Pricing calculator").click();; 54 | Thread.sleep(5000); 55 | System.out.println("User Navigates to Pricing Calculator page"); 56 | 57 | driver.findElementByXPath("//button[text()='Containers']").click(); 58 | 59 | System.out.println("Containers clicked"); 60 | 61 | 62 | //5) Select Container Instances 63 | WebElement eleContainerInstances = driver.findElementByXPath("(//span[text()='Container Instances'])[3]"); 64 | wait.until(ExpectedConditions.elementToBeClickable(eleContainerInstances)); 65 | action.click(eleContainerInstances).build().perform(); 66 | System.out.println("Container Instances Selected "); 67 | 68 | //6) Click on Container Instance Added View 69 | WebElement ContainerInstanceView = driver.findElementByXPath("//span[@class='module-summary']"); 70 | System.out.println("Container Instance Added View is "+ContainerInstanceView.getText()); 71 | 72 | //7) Select Region as "South India" 73 | WebElement eleRegion = driver.findElementByXPath("//select[@name='region']"); 74 | Select Region = new Select(eleRegion); 75 | Region.selectByVisibleText("South India"); 76 | System.out.println("Region selected is South India"); 77 | 78 | //8) Set the Duration as 180000 seconds 79 | WebElement eleDuration = driver.findElementByXPath("//input[@name='seconds']"); 80 | eleDuration.clear(); 81 | eleDuration.sendKeys("180000"); 82 | 83 | //9) Select the Memory as 4GB 84 | WebElement eleMemory = driver.findElementByXPath("//select[@name='memory']"); 85 | Select selMemory = new Select(eleMemory); 86 | selMemory.selectByValue("4"); 87 | 88 | //10) Enable SHOW DEV/TEST PRICING 89 | WebElement eleToggle1 = driver.findElementByXPath("(//div[@class='toggler-slide '])[1]"); 90 | action.click(eleToggle1).build().perform(); 91 | 92 | //11) Select Indian Rupee as currency 93 | WebElement eleCurrency = driver.findElementByXPath("//select[@class='select currency-dropdown']"); 94 | 95 | Select selCurrency = new Select(eleCurrency); 96 | selCurrency.selectByValue("INR"); 97 | 98 | //12) Print the Estimated monthly price 99 | 100 | WebElement eleMonthlyPrice = driver.findElementByXPath("(//span[text()= 'Monthly cost']//following::span[@class='numeric'])[3]"); 101 | String MonthlyPrice = eleMonthlyPrice.getText(); 102 | System.out.println("Estimated Monthly Price is " +MonthlyPrice); 103 | 104 | //13) Click on Export to download the estimate as excel 105 | WebElement eleExport = driver.findElementByXPath("//button[text()='Export']"); 106 | action.click(eleExport).build().perform(); 107 | System.out.println("Estimates Exported Successfully"); 108 | File Export1 = new File("C:\\Users\\praveenram.ravi\\Downloads\\ExportedEstimate(1).xlsx"); 109 | if(Export1.exists()) 110 | { 111 | System.out.println("Export is successful"); 112 | } 113 | else 114 | { 115 | System.out.println("Export is not successful"); 116 | } 117 | 118 | 119 | //14) Navigate to Example Scenarios and Select CI/CD for Containers 120 | action.moveToElement(driver.findElementByXPath("//a[text()='Example Scenarios']")).click().build().perform(); 121 | System.out.println("User Navigated to Example Scenarios"); 122 | driver.findElementByXPath("//span[text()='CI/CD for Containers']").click(); 123 | System.out.println("CI/CD for containers selected"); 124 | 125 | 126 | //15) Click Add to Estimate 127 | WebElement eleAddToEstimate = driver.findElementByXPath("//button[text()='Add to estimate']"); 128 | wait.until(ExpectedConditions.elementToBeClickable(eleAddToEstimate)); 129 | action.moveToElement(eleAddToEstimate).click().build().perform(); 130 | 131 | System.out.println("Added to Estimates"); 132 | 133 | //16) Change the Currency as Indian Rupee 134 | 135 | WebElement eleCurrency1 = driver.findElementByXPath("//select[@class='select currency-dropdown']"); 136 | Select Currency1 = new Select(eleCurrency1); 137 | Currency1.selectByValue("INR"); 138 | System.out.println("Indian Rupees Selected"); 139 | 140 | //17) Enable SHOW DEV/TEST PRICING 141 | action.moveToElement(driver.findElementByXPath("//div[contains(@class,'toggler-slide')]")).click().build().perform(); 142 | System.out.println("SHOW DEV/TEST PRICING clicked"); 143 | 144 | //18) Export the Estimate 145 | action.moveToElement(driver.findElementByXPath("//button[text()='Export']")).click().build().perform();; 146 | File Export2 = new File("C:\\Users\\praveenram.ravi\\Downloads\\ExportedEstimate(1).xlsx"); 147 | if(Export2.exists()) 148 | { 149 | System.out.println("Export is successful"); 150 | } 151 | else 152 | { 153 | System.out.println("Export is not successful"); 154 | } 155 | 156 | driver.quit(); 157 | 158 | 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /BigBasket.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Alert; 9 | import org.openqa.selenium.By; 10 | import org.openqa.selenium.Keys; 11 | import org.openqa.selenium.WebDriver; 12 | import org.openqa.selenium.WebElement; 13 | import org.openqa.selenium.chrome.ChromeDriver; 14 | import org.openqa.selenium.chrome.ChromeOptions; 15 | import org.openqa.selenium.interactions.Actions; 16 | import org.openqa.selenium.remote.RemoteWebDriver; 17 | import org.openqa.selenium.support.ui.ExpectedConditions; 18 | import org.openqa.selenium.support.ui.Select; 19 | import org.openqa.selenium.support.ui.WebDriverWait; 20 | 21 | 22 | 23 | 24 | public class BigBasket { 25 | public static RemoteWebDriver driver; 26 | public static void main(String[] args) throws InterruptedException { 27 | 28 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 29 | System.setProperty("webdriver.chrome.silentOutput", "true"); 30 | 31 | ChromeOptions options = new ChromeOptions(); 32 | options.addArguments("--disable-notifications"); 33 | 34 | driver = new ChromeDriver(options); 35 | Actions action = new Actions(driver); 36 | WebDriverWait wait = new WebDriverWait(driver, 30); 37 | 38 | //Browser Set up 39 | 40 | 41 | 42 | driver.get("https://www.bigbasket.com/"); 43 | 44 | driver.manage().window().maximize(); 45 | driver.manage().timeouts().implicitlyWait(20000, TimeUnit.SECONDS); 46 | Thread.sleep(5000); 47 | 48 | System.out.println("User enters Bigbasket Home page"); 49 | 50 | //Actions Builder 51 | 52 | action.moveToElement(driver.findElementByXPath("//a[text()=' Shop by Category ']")).build().perform(); 53 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Foodgrains, Oil & Masala"))); 54 | 55 | action.moveToElement(driver.findElementByLinkText("Foodgrains, Oil & Masala")).build().perform(); 56 | System.out.println("Foodgrains, Oil and Masala selected"); 57 | 58 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Rice & Rice Products"))); 59 | action.moveToElement(driver.findElementByXPath("(//a[text()= 'Rice & Rice Products'])[2]")).build().perform(); 60 | System.out.println("Rice and Rice Products selected"); 61 | 62 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Boiled & Steam Rice"))); 63 | action.moveToElement(driver.findElementByXPath("(//a[text()= 'Boiled & Steam Rice'])[2]")).build().perform(); 64 | driver.findElementByXPath("(//a[text()= 'Boiled & Steam Rice'])[2]").click(); 65 | 66 | 67 | driver.findElementByXPath("(//label//span[text()='bb Royal'])[1]").click(); 68 | Thread.sleep(3000); 69 | driver.findElementByXPath("(//a[contains(text(),'Ponni Boiled Rice - Super')]/following::button[@type='button'])[1]").click(); 70 | driver.findElementByXPath("(//ul[@class='dropdown-menu drop-select']//span[text()='5 kg'])[3]").click(); 71 | 72 | String ricePriceText = driver.findElementByXPath("(//a[contains(text(),'Ponni Boiled Rice - Super')]/following::span[@class='discnt-price']//span)[1]").getText(); 73 | System.out.println("Price of the Rice Pack: " + ricePriceText); 74 | int ricePriceNumber = Integer.parseInt(ricePriceText); 75 | 76 | driver.findElementByXPath("//a[contains(text(),'Ponni Boiled Rice - Super Premium')]/following::button[@qa='add'][1]").click(); 77 | 78 | 79 | try { 80 | driver.findElementByLinkText("Continue").click(); 81 | } catch (Exception e) { 82 | System.out.println("Location popup not displayed."); 83 | e.printStackTrace(); 84 | } 85 | 86 | Thread.sleep(3000); 87 | 88 | driver.findElementByXPath("//input[@qa='searchBar']").sendKeys("Dal", Keys.ENTER); 89 | Thread.sleep(5000); 90 | 91 | driver.findElementByXPath("(//a[contains(text(),'Thuvaram Paruppu')])[1]/following::span[2]").click(); 92 | driver.findElementByXPath("(//a[contains(text(),'Thuvaram Paruppu')])[1]/following::span[2]/following::span[text()='2 kg'][1]").click(); 93 | 94 | driver.findElementByXPath("(//a[contains(text(),'Thuvaram Paruppu')])[1]/following::input[@type='text'][1]").clear(); 95 | driver.findElementByXPath("(//a[contains(text(),'Thuvaram Paruppu')])[1]/following::input[@type='text'][1]").sendKeys("2"); 96 | 97 | String dalPriceText = driver.findElementByXPath("((//a[contains(text(),'Thuvaram Paruppu')])[1]/following::span[@class='discnt-price']//span)[1]").getText(); 98 | System.out.println("Price of Dal: " + dalPriceText); 99 | int dalPriceNumber = Integer.parseInt(dalPriceText); 100 | 101 | // Adding to the Cart 102 | driver.findElementByXPath("((//a[contains(text(),'Thuvaram Paruppu')])[1]/following::span[@class='discnt-price']//span/following::button)[1]").click(); 103 | 104 | try { 105 | driver.findElementByXPath("//div[@class='toast toast-success']//div[@class='toast-title']").getText(); 106 | } catch (Exception e) { 107 | System.out.println("Success message not displayed."); 108 | e.printStackTrace(); 109 | } 110 | 111 | Thread.sleep(5000); 112 | 113 | action.moveToElement(driver.findElementById("totalNumberOfCartItems")).build().perform(); 114 | 115 | Thread.sleep(5000); 116 | 117 | // Manipulating the Price details and validating 118 | String riceString = driver.findElementByXPath("(//div[@qa='pcsMB'])[1]").getText(); 119 | String riceQtyStr = riceString.substring(0, 1); 120 | double riceQtyNumber = Double.parseDouble(riceQtyStr); 121 | System.out.println("Quantity of Rice: " + riceQtyNumber); 122 | 123 | String dalQtyStr = driver.findElementByXPath("(//div[@qa='pcsMB'])[2]").getText(); 124 | dalQtyStr = dalQtyStr.substring(0, 1); 125 | double dalQtyNumber = Double.parseDouble(dalQtyStr); 126 | System.out.println("Quantity of Dal: " + dalQtyNumber); 127 | 128 | String ricePriceCart = driver.findElementByXPath("(//span[@qa='priceMB'])[1]").getText(); 129 | double riceTotal = Double.parseDouble(ricePriceCart); 130 | riceTotal = riceTotal * riceQtyNumber; 131 | 132 | String dalPriceCart = driver.findElementByXPath("(//span[@qa='priceMB'])[2]").getText(); 133 | double dalTotal = Double.parseDouble(dalPriceCart); 134 | dalTotal = dalTotal * dalQtyNumber; 135 | 136 | String subTotalStr = driver.findElementByXPath("//span[@qa='subTotalMB']").getText(); 137 | double subTotalNum = Double.parseDouble(subTotalStr); 138 | 139 | Thread.sleep(3000); 140 | 141 | if (subTotalNum == riceTotal + dalTotal) { 142 | System.out.println("Sub Total is correct: " + subTotalNum); 143 | } else { 144 | System.out.println("Sub Total is wrong: " + subTotalNum); 145 | } 146 | 147 | Thread.sleep(3000); 148 | 149 | // Reducing the quantity of Dal to 1 150 | driver.findElementByXPath("(//button[@qa='decQtyMB'])[2]").click(); 151 | Thread.sleep(3000); 152 | 153 | // Again getting the Dal quantity and price to validate the sub total 154 | String dalQtyStr2 = driver.findElementByXPath("(//div[@qa='pcsMB'])[2]").getText(); 155 | dalQtyStr = dalQtyStr2.substring(0, 1); 156 | double dalQtyNumber2 = Double.parseDouble(dalQtyStr); 157 | System.out.println("Quantity of Dal after change: " + dalQtyNumber2); 158 | 159 | String dalPriceCart2 = driver.findElementByXPath("(//span[@qa='priceMB'])[2]").getText(); 160 | double dalTotal2 = Double.parseDouble(dalPriceCart2); 161 | dalTotal2 = dalTotal2 * dalQtyNumber2; 162 | 163 | String subTotalStr2 = driver.findElementByXPath("//span[@qa='subTotalMB']").getText(); 164 | double subTotalNum2 = Double.parseDouble(subTotalStr2); 165 | 166 | Thread.sleep(3000); 167 | 168 | if (subTotalNum2 == riceTotal + dalTotal2) { 169 | System.out.println("Sub Total is correct after change: " + subTotalNum2); 170 | } else { 171 | System.out.println("Sub Total is wrong: " + subTotalNum2); 172 | } 173 | 174 | driver.close(); 175 | 176 | 177 | 178 | 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /CrmCloud.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.UnexpectedAlertBehaviour; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.chrome.ChromeOptions; 10 | import org.openqa.selenium.interactions.Actions; 11 | import org.openqa.selenium.remote.CapabilityType; 12 | import org.openqa.selenium.remote.DesiredCapabilities; 13 | import org.openqa.selenium.remote.RemoteWebDriver; 14 | import org.openqa.selenium.support.ui.ExpectedConditions; 15 | import org.openqa.selenium.support.ui.Select; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | public class CrmCloud { 19 | 20 | public static RemoteWebDriver driver; 21 | public static void main(String[] args) throws InterruptedException { 22 | 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 24 | System.setProperty("webdriver.chrome.silentOutput", "true"); 25 | 26 | ChromeOptions options = new ChromeOptions(); 27 | options.addArguments("--disable-notifications"); 28 | 29 | DesiredCapabilities cap = new DesiredCapabilities(); 30 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 31 | options.merge(cap); 32 | 33 | driver = new ChromeDriver(options); 34 | Actions action = new Actions(driver); 35 | WebDriverWait wait = new WebDriverWait(driver, 30); 36 | 37 | //1) Go to https://demo.1crmcloud.com/ 38 | driver.get("https://demo.1crmcloud.com/"); 39 | 40 | 41 | //2) Give username as admin and password as admin 42 | 43 | driver.findElementById("login_user").sendKeys("admin"); 44 | driver.findElementById("login_pass").sendKeys("admin"); 45 | 46 | //3) Choose theme as Claro Theme 47 | Select theme = new Select(driver.findElementById("login_theme")); 48 | System.out.println("Drop down selected"); 49 | theme.selectByVisibleText("Claro Theme"); 50 | System.out.println("Claro Theme selected"); 51 | 52 | driver.findElementByXPath("//span[text()='Login']").click(); 53 | System.out.println("Logged in"); 54 | 55 | driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); 56 | driver.manage().window().maximize(); 57 | 58 | //4) Click on Sales and Marketting 59 | 60 | WebElement SalesAndMarketing = driver.findElementByXPath("//div[text()='Sales & Marketing']"); 61 | SalesAndMarketing.click(); 62 | System.out.println("Sales and Marketing Selected"); 63 | Thread.sleep(10000); 64 | 65 | //5) Click Create contact 66 | driver.findElementByXPath("//div[text()='Create Contact']").click(); 67 | System.out.println("User navigated to Create Contact Page"); 68 | 69 | 70 | Thread.sleep(10000); 71 | 72 | //6) Select Title and type First name, Last Name, Email and Phone Numbers 73 | 74 | Actions builder = new Actions(driver); 75 | WebElement eleTitle = driver.findElementById("DetailFormsalutation-input"); 76 | wait.until(ExpectedConditions.elementToBeClickable(eleTitle)); 77 | builder.click(eleTitle).build().perform(); 78 | Thread.sleep(2000); 79 | 80 | WebElement eleMrs = driver.findElementByXPath("//div[text()='Prof.']"); 81 | wait.until(ExpectedConditions.elementToBeClickable(eleMrs)); 82 | builder.click(eleMrs).build().perform(); 83 | System.out.println("Salutation selected"); 84 | 85 | driver.findElementById("DetailFormfirst_name-input").sendKeys("Praveenram"); 86 | driver.findElementById("DetailFormlast_name-input").sendKeys("Ravi"); 87 | 88 | driver.findElementById("DetailFormemail1-input").sendKeys("clikbypravee@gmail.com"); 89 | driver.findElementById("DetailFormphone_mobile-input").sendKeys("9003188294"); 90 | 91 | //7) Select Lead Source as "Public Relations" 92 | WebElement leadSource = driver.findElementById("DetailFormlead_source-input"); 93 | builder.click(leadSource).build().perform(); 94 | Thread.sleep(2000); 95 | 96 | WebElement Lead_Source = driver.findElementByXPath("//div[text()='Public Relations']"); 97 | builder.click(Lead_Source).build().perform(); 98 | Thread.sleep(2000); 99 | System.out.println("Public relations selected"); 100 | 101 | 102 | //8) Select Business Roles as "Sales" 103 | WebElement BusRole = driver.findElementById("DetailFormbusiness_role-input"); 104 | builder.click(BusRole).build().perform(); 105 | Thread.sleep(2000); 106 | 107 | WebElement BusinessRoles = driver.findElementByXPath("//div[text()='Sales']"); 108 | builder.click(BusinessRoles).build().perform(); 109 | System.out.println("Business Role Selected"); 110 | 111 | //9) Fill the Primary Address, City, State, Country and Postal Code and click Save 112 | 113 | driver.findElementById("DetailFormprimary_address_street-input").sendKeys("Tambaram"); 114 | driver.findElementById("DetailFormprimary_address_city-input").sendKeys("Chennai"); 115 | driver.findElementById("DetailFormprimary_address_state-input").sendKeys("Tamilnadu"); 116 | driver.findElementById("DetailFormprimary_address_country-input").sendKeys("India", Keys.ARROW_DOWN, Keys.ENTER); 117 | driver.findElementById("DetailFormprimary_address_postalcode-input").sendKeys("600045"); 118 | driver.findElementByXPath("(//span[text()='Save'])[2]").click(); 119 | System.out.println("Form Saved"); 120 | 121 | Thread.sleep(5000); 122 | 123 | String PageTitle = driver.getTitle(); 124 | System.out.println("Page Title is "+PageTitle); 125 | 126 | //10) Mouse over on Today's Activities and click Meetings 127 | 128 | WebElement TodaysActivities = driver.findElementByLinkText("Today's Activities"); 129 | wait.until(ExpectedConditions.elementToBeClickable(TodaysActivities)); 130 | builder.moveToElement(TodaysActivities).build().perform(); 131 | Thread.sleep(1000); 132 | 133 | WebElement Meetings = driver.findElementByXPath("//div[(contains(text(),'Meetings'))]"); 134 | wait.until(ExpectedConditions.elementToBeClickable(Meetings)); 135 | builder.click(Meetings).build().perform(); 136 | Thread.sleep(3000); 137 | 138 | //11) Click Create 139 | driver.findElementByLinkText("Create").click(); 140 | 141 | //12) Type Subject as "Project Status" , Status as "Planned" 142 | driver.findElementById("DetailFormname-input").sendKeys("Project Status"); 143 | WebElement MeetingStatus = driver.findElementById("DetailFormstatus-input"); 144 | builder.click(MeetingStatus).build().perform(); 145 | Thread.sleep(2000); 146 | 147 | WebElement currentStatus = driver.findElementByXPath("//div[text()='Planned']"); 148 | builder.click(currentStatus).build().perform(); 149 | Thread.sleep(2000); 150 | 151 | System.out.println("Meeting Scheduled"); 152 | 153 | //13) Start Date & Time as tomorrow 3 pm and Duration as 1hr 154 | driver.findElementById("DetailFormdate_start").click(); 155 | WebElement tomorrow = driver.findElementByXPath("//div[@class='grid-cell number-cell text-right day inside current selected quiet responsive']/following::div[1]"); 156 | wait.until(ExpectedConditions.elementToBeClickable(tomorrow)); 157 | tomorrow.click(); 158 | System.out.println("Meeting scheduled for tomorrow"); 159 | WebElement Time = driver.findElementByXPath("//div[@id='DetailFormdate_start-calendar-text']//input[@class='input-text']"); 160 | wait.until(ExpectedConditions.visibilityOf(Time)); 161 | Time.clear(); 162 | Time.sendKeys("3:00pm", Keys.ENTER); 163 | driver.findElementById("DetailFormduration-time").clear(); 164 | driver.findElementById("DetailFormduration-time").sendKeys("1hr",Keys.TAB); 165 | System.out.println("Meeting at 3 PM for one hour"); 166 | //14) Click Add paricipants, add your created Contact name and click Save 167 | driver.findElementByXPath("//span[text()=' Add Participants']").click(); 168 | 169 | driver.findElementByXPath("//div[@id='app-search-text']//input[1]").sendKeys("Praveenram"); 170 | Thread.sleep(3000); 171 | WebElement Contact = driver.findElementByXPath("//div[@id='app-search-list']//div[(contains(text(),'Sample Fname Lname'))]"); 172 | wait.until(ExpectedConditions.visibilityOf(Contact)); 173 | builder.click(Contact).build().perform(); 174 | Thread.sleep(3000); 175 | 176 | driver.findElementById("DetailForm_save2-label").click(); 177 | Thread.sleep(2000); 178 | 179 | //15) Go to Sales and Marketting-->Contacts 180 | builder.moveToElement(SalesAndMarketing).build().perform(); 181 | 182 | WebElement SMContact = driver.findElementByXPath("//div[text()='Contacts']"); 183 | wait.until(ExpectedConditions.visibilityOf(SMContact)); 184 | builder.click(SMContact).build().perform(); 185 | Thread.sleep(2000); 186 | 187 | //16) search the lead Name and click the name from the result 188 | WebElement Search = driver.findElementById("filter_text"); 189 | Search.sendKeys("Sample Fname Lname",Keys.ENTER); 190 | Thread.sleep(5000); 191 | driver.findElementByXPath("//span[@class='detailLink']//a[1]").click(); 192 | 193 | //17) Check weather the Meeting is assigned to the contact under Activities Section. 194 | 195 | WebElement meetingRecord = driver.findElementByXPath("(//span[@id='subpanel-activities']/ancestor::div[@id='DetailForm-subpanels']//a[contains(text(),'Project Status')])[1]"); 196 | 197 | if (meetingRecord.isDisplayed()) { 198 | System.out.println("Meeting is assigned for the Contact."); 199 | } else { 200 | System.out.println("Meeting is not available for the Contact."); 201 | } 202 | 203 | 204 | 205 | 206 | 207 | 208 | } 209 | 210 | } 211 | -------------------------------------------------------------------------------- /Honda.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.remote.RemoteWebDriver; 14 | import org.openqa.selenium.support.ui.ExpectedConditions; 15 | import org.openqa.selenium.support.ui.Select; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | public class Honda { 19 | public static RemoteWebDriver driver; 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 24 | System.setProperty("webdriver.chrome.silentOutput", "true"); 25 | 26 | ChromeOptions options = new ChromeOptions(); 27 | options.addArguments("--disable-notifications"); 28 | 29 | driver = new ChromeDriver(options); 30 | Actions action = new Actions(driver); 31 | WebDriverWait wait = new WebDriverWait(driver, 30); 32 | 33 | //Browser Set up 34 | 35 | 36 | 37 | driver.get("https://www.honda2wheelersindia.com/"); 38 | 39 | driver.manage().window().maximize(); 40 | driver.manage().timeouts().implicitlyWait(30000, TimeUnit.SECONDS); 41 | Thread.sleep(5000); 42 | 43 | System.out.println("User enters Honda Home page"); 44 | driver.findElementByXPath("//button[@class='close']").click(); 45 | 46 | System.out.println("Pop out closed"); 47 | 48 | driver.findElementByLinkText("Scooter").click(); 49 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']"))); 50 | 51 | driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']").click(); 52 | 53 | System.out.println("Dio Selected"); 54 | 55 | driver.findElementByLinkText("Specifications").click(); 56 | System.out.println("Specifications for DIO displayed"); 57 | 58 | Thread.sleep(10000); 59 | WebElement Engine = driver.findElementByXPath("//a[@name='2']"); 60 | action.moveToElement(Engine).perform(); 61 | 62 | System.out.println("Engine specifications selected"); 63 | 64 | WebElement webele1 = driver.findElementByXPath("//span[text()='Displacement']/following::span[1]"); 65 | String Diodisplacement1 = webele1.getText().replaceAll("//D", "").substring(0, 3); 66 | System.out.println("Diodisplacement1 " + Diodisplacement1); 67 | double DioDisplacement = Double.parseDouble(Diodisplacement1); 68 | System.out.println("Displacement of Dio Scooter is " +DioDisplacement); 69 | 70 | //to get Activa's details 71 | 72 | driver.findElementByLinkText("Scooter").click(); 73 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']"))); 74 | 75 | driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']").click(); 76 | 77 | System.out.println("Activa Selected"); 78 | 79 | driver.findElementByLinkText("Specifications").click(); 80 | System.out.println("Specifications for Activa displayed"); 81 | 82 | Thread.sleep(10000); 83 | WebElement ActivaEngine = driver.findElementByXPath("//a[@name='4']"); 84 | action.moveToElement(ActivaEngine).perform(); 85 | 86 | System.out.println("Activa Engine specifications selected"); 87 | 88 | WebElement webele2 = driver.findElementByXPath("//span[text()='Displacement']/following::span[1]"); 89 | System.out.println(webele2.getText()); 90 | String ActivaDisplacement1 = webele2.getText().replaceAll("//D", "").substring(0, 3); 91 | System.out.println("Activa Displacement is "+ActivaDisplacement1); 92 | 93 | double ActivaDisplacement = Double.parseDouble(ActivaDisplacement1); 94 | System.out.println("Displacement of Activa Scooter is " +ActivaDisplacement); 95 | 96 | //compare the displacement 97 | if(DioDisplacement>ActivaDisplacement) 98 | { 99 | System.out.println("Dio displacement is Better"); 100 | } 101 | else 102 | { 103 | System.out.println("Activa Displacement is Better"); 104 | } 105 | 106 | // Click FAQ from Menu 107 | driver.findElementByLinkText("FAQ").click(); 108 | 109 | // Click Activa 125 BS-VI under Browse By Product 110 | WebElement eleBSVI = driver.findElementByLinkText("Activa 125 BS-VI"); 111 | wait.until(ExpectedConditions.visibilityOf(eleBSVI)); 112 | eleBSVI.click(); 113 | 114 | // Click Vehicle Price 115 | WebElement eleVprice = driver.findElementByXPath("//a[text()=' Vehicle Price']"); 116 | wait.until(ExpectedConditions.visibilityOf(eleVprice)); 117 | eleVprice.click(); 118 | 119 | // Make sure Activa 125 BS-VI selected and click submit 120 | 121 | WebElement eleScooter = driver.findElementById("ModelID6"); 122 | wait.until(ExpectedConditions.visibilityOf(eleScooter)); 123 | Select dropdown = new Select(eleScooter); 124 | WebElement firstSelectedOption = dropdown.getFirstSelectedOption(); 125 | String model = firstSelectedOption.getText(); 126 | 127 | if(model.contains("Activa 125 BS-VI")) 128 | driver.findElementByXPath("//button[@id='submit6']").click(); 129 | 130 | // click the price link 131 | WebElement priceLink = driver.findElementByLinkText("Click here to know the price of Activa 125 BS-VI."); 132 | wait.until(ExpectedConditions.elementToBeClickable(priceLink)); 133 | priceLink.click(); 134 | 135 | // Go to the new Window and select the state as Tamil Nadu and city as Chennai 136 | Set winSet = driver.getWindowHandles(); 137 | List winList = new ArrayList(winSet); 138 | driver.switchTo().window(winList.get(1)); 139 | 140 | WebElement eleState = driver.findElementById("StateID"); 141 | Select state = new Select(eleState); 142 | state.selectByVisibleText("Tamil Nadu"); 143 | 144 | WebElement eleCity = driver.findElementById("CityID"); 145 | wait.until(ExpectedConditions.elementToBeClickable(eleCity)); 146 | Select city = new Select(eleCity); 147 | city.selectByVisibleText("Chennai"); 148 | 149 | // Click Search 150 | WebElement eleSearch = driver.findElementByXPath("//button[text()='Search']"); 151 | wait.until(ExpectedConditions.elementToBeClickable(eleSearch)); 152 | eleSearch.click(); 153 | 154 | // Print all the 3 models and their prices 155 | WebElement table = driver.findElementById("gvshow"); 156 | List rows = table.findElements(By.tagName("td")); 157 | 158 | for (WebElement eachmodel : rows) 159 | { 160 | System.out.println(eachmodel.getText()); 161 | } 162 | 163 | // Close all Browsers 164 | driver.quit();; 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /MakeMyTrip.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.text.DateFormat; 4 | import java.text.SimpleDateFormat; 5 | import java.time.LocalDate; 6 | import java.time.Month; 7 | import java.util.ArrayList; 8 | import java.util.Calendar; 9 | import java.util.Date; 10 | import java.util.List; 11 | import java.util.Set; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | import org.openqa.selenium.By; 15 | import org.openqa.selenium.Keys; 16 | import org.openqa.selenium.WebElement; 17 | import org.openqa.selenium.chrome.ChromeDriver; 18 | import org.openqa.selenium.chrome.ChromeOptions; 19 | import org.openqa.selenium.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.WebDriverWait; 21 | 22 | public class MakeMyTrip { 23 | 24 | public static void main(String[] args) throws InterruptedException { 25 | 26 | 27 | ChromeOptions options = new ChromeOptions(); 28 | options.addArguments("--disable-notifications"); 29 | 30 | //Browser Set up 31 | 32 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 33 | ChromeDriver driver = new ChromeDriver(options); 34 | WebDriverWait wait = new WebDriverWait(driver, 30); 35 | 36 | 37 | // Invoke the Browser 38 | driver.get("https://www.makemytrip.com/"); 39 | driver.manage().window().maximize(); 40 | driver.manage().timeouts().implicitlyWait(20000, TimeUnit.SECONDS); 41 | 42 | //Click on Hotels 43 | driver.findElementByXPath("//span[text()='Hotels']").click(); 44 | System.out.println("Navigated to Hotels Page"); 45 | Thread.sleep(3000); 46 | 47 | //Entering the city name as Goa 48 | driver.findElementById("city").click(); 49 | driver.findElementByXPath("//input[@class='react-autosuggest__input react-autosuggest__input--open']").sendKeys("Goa", Keys.TAB); 50 | 51 | //LocalDate function is to get the current date - DD-MM-YYYY in a string format 52 | String datestamp = LocalDate.now().toString(); 53 | System.out.println("Current date is "+datestamp); 54 | //substring function to get the date from that timestamp 55 | String date1 = datestamp.substring(8, 10); 56 | int date = Integer.parseInt(date1)+5; 57 | //substring function to get the month from that datestamp 58 | String month = datestamp.substring(5, 7); 59 | //Converting the received datastamp into int 60 | int monthInt = Integer.parseUnsignedInt(month); 61 | //getting the next Month by adding 1 62 | int nextMonth = monthInt+1; 63 | System.out.println("Next Month is " + nextMonth); 64 | String nextMonthString = Month.of(nextMonth).toString(); 65 | nextMonthString = nextMonthString.substring(0, 1)+nextMonthString.substring(1, nextMonthString.length()).toLowerCase(); 66 | 67 | /* 68 | * // //get current date time with Date() Date date = new Date(); // //Get only 69 | * the date(and not month,year,time,etc) DateFormat dateFormat = new 70 | * SimpleDateFormat("mm"); // // Now format the date String today= 71 | * dateFormat.format(date); int today1 = Integer.parseInt(today); int tommorow = 72 | * Integer.parseInt(today)+1; // Print the tommorow's date 73 | * System.out.println(today1); System.out.println(tommorow); 74 | */ 75 | 76 | 77 | WebElement webElement1 = driver.findElementByXPath("//div[text()='"+nextMonthString+"']/ancestor::div[@class='DayPicker-Month']//div[text()='"+date+"']"); 78 | String startDate = webElement1.getText(); 79 | System.out.println("Stay starts on " +startDate); 80 | webElement1.click(); 81 | 82 | int oneWeek = Integer.parseInt(startDate); 83 | int nextWeek = oneWeek+7; 84 | 85 | 86 | WebElement webElement2 = driver.findElementByXPath("//div[text()='"+nextMonthString+"']/ancestor::div[@class='DayPicker-Month']//div[text()='"+nextWeek+"']"); 87 | System.out.println("End date is on "+webElement2.getText()); 88 | webElement2.click(); 89 | 90 | driver.findElementById("guest").click(); 91 | driver.findElementByXPath("(//li[text()='2'])[1]").click(); 92 | driver.findElementByXPath("(//li[text()='2'])[2]").click(); 93 | driver.findElementByXPath("//button[text()='APPLY']").click(); 94 | System.out.println("Selected the number of guests"); 95 | 96 | driver.findElementByXPath("//button[text()='Search']").click(); 97 | System.out.println("Searching for rooms"); 98 | 99 | //clicking the black screen that appears after search button click 100 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='mmBackdrop wholeBlack']"))); 101 | driver.findElementByXPath("//div[@class='mmBackdrop wholeBlack']").click(); 102 | 103 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[text()='Baga']"))); 104 | driver.findElementByXPath("//label[text()='Baga']").click(); 105 | System.out.println("Baga Selected"); 106 | 107 | 108 | 109 | driver.findElementByXPath("//label[text()='5 Star']").click(); 110 | System.out.println("5 star hotels displayed"); 111 | 112 | Thread.sleep(5000); 113 | 114 | driver.findElementByXPath("(//div[contains(@class, 'listingRow')])[1]").click(); 115 | System.out.println("First hotel in the list is selected"); 116 | 117 | Set windowSet = driver.getWindowHandles(); 118 | List windowList = new ArrayList(windowSet); 119 | 120 | driver.switchTo().window(windowList.get(1)); 121 | System.out.println("New window title is "+driver.getTitle()); 122 | 123 | 124 | driver.findElementByXPath("(//span[text() = 'MORE OPTIONS'])[1]").click(); 125 | System.out.println("EMI option selected"); 126 | 127 | driver.findElementByXPath("(//span[text() = 'SELECT'])[1]").click(); 128 | System.out.println("Selected 3 months option for EMI"); 129 | 130 | driver.findElementByXPath("//span[@class='close']").click(); 131 | System.out.println("Closed the EMI window"); 132 | 133 | System.out.println("Page Title is "+driver.getTitle()); 134 | 135 | driver.close(); 136 | System.out.println("Hotels Page closed"); 137 | driver.switchTo().window(windowList.get(0)); 138 | System.out.println("Main Page title is "+driver.getTitle()); 139 | driver.close(); 140 | 141 | System.out.println("Main Page Closed"); 142 | 143 | 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /Myntra.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.Alert; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeDriver; 11 | import org.openqa.selenium.chrome.ChromeOptions; 12 | import org.openqa.selenium.interactions.Actions; 13 | 14 | public class Myntra { 15 | 16 | public static void main(String[] args) throws InterruptedException { 17 | 18 | //Browser Set up 19 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 20 | ChromeDriver driver = new ChromeDriver(); 21 | driver.get("http://www.myntra.com/"); 22 | driver.manage().window().maximize(); 23 | driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); 24 | 25 | //mouse over option on Women and select Jackets and coats 26 | Actions action = new Actions(driver); 27 | action.moveToElement(driver.findElementByXPath("//a[@data-group='women']")).perform(); 28 | driver.findElementByLinkText("Jackets & Coats").click(); 29 | 30 | driver.manage().timeouts().implicitlyWait(20000, TimeUnit.SECONDS); 31 | 32 | //To disable the notification 33 | ChromeOptions options = new ChromeOptions(); 34 | options.addArguments("--disable-notifications"); 35 | 36 | //Getting the count of all Products 37 | String text = driver.findElementByClassName("title-count").getText(); 38 | String text1 = text.replaceAll("\\D", ""); 39 | int FinalCount = Integer.parseInt(text1); 40 | 41 | //Displaying total count 42 | System.out.println("************************************************************************************************" ); 43 | System.out.println("********************** Total Count of dresses in this page is " +FinalCount+ " *************************"); 44 | System.out.println("************************************************************************************************" ); 45 | 46 | //Conversion of string to Integer 47 | String JacketsCounttext = driver.findElementByXPath("(//span[@class='categories-num'])[1]").getText(); 48 | String CoatsCounttext = driver.findElementByXPath("(//span[@class='categories-num'])[2]").getText(); 49 | 50 | int JacketsCount = Integer.parseInt(JacketsCounttext.replaceAll("\\D", "")); 51 | int CoatsCount = Integer.parseInt(CoatsCounttext.replaceAll("\\D", "")); 52 | 53 | //Displaying the Jackets Count and Coats Count 54 | System.out.println("************************************************************************************************" ); 55 | System.out.println("************************** Total Count of Jackets in this page is " +JacketsCount+ " *************************"); 56 | System.out.println("************************** Total Count of Coats in this page is " +CoatsCount+ " *************************"); 57 | System.out.println("************************************************************************************************" ); 58 | 59 | //Validating the total count 60 | if(FinalCount==(JacketsCount+CoatsCount)) 61 | { 62 | System.out.println("************* Number of Jackets and Number of Coats sum up the Final Count**********************"); 63 | } 64 | else 65 | { 66 | System.out.println("********************** Number of Jackets and Number of Coats doesn't sum up the Final Count****************************"); 67 | } 68 | 69 | //Select Coats check box 70 | driver.findElementByXPath("//Label[text()='Coats']").click(); 71 | Thread.sleep(5000); 72 | System.out.println("******************************** COATS SELECTED ************************************************"); 73 | 74 | String numberOfCoats = driver.findElementByClassName("title-count").getText(); 75 | 76 | int FinalNumberOfCoats = Integer.parseInt(numberOfCoats.replaceAll("\\D", "")); 77 | 78 | System.out.println("********************************* NUMBER OF COATS DISPLAYED IS "+FinalNumberOfCoats+ " *****************************"); 79 | 80 | //Selecting More Brands and selecting MANGO 81 | driver.findElementByXPath("//div[@class='brand-more']").click(); 82 | driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS); 83 | driver.findElementByClassName("FilterDirectory-searchInput").sendKeys("MANGO"); 84 | driver.findElementByXPath("(//input[@value='MANGO']/parent::label)[2]").click(); 85 | driver.findElementByXPath("//span[contains(@class,'FilterDirectory-close')]").click(); 86 | Thread.sleep(10000); 87 | 88 | int count=0; 89 | List listOfBrandName = driver.findElementsByXPath("//div[@class='product-productMetaInfo']//h3[1]"); 90 | for (WebElement brand : listOfBrandName) { 91 | String brandName = brand.getText(); 92 | if (brandName.equalsIgnoreCase("MANGO")) { 93 | count=count+1; 94 | } 95 | } 96 | if (count==listOfBrandName.size()) { 97 | System.out.println("******************************* ALL Products are of Brand MANGO ******************************"); 98 | } else { 99 | System.out.println("Not MANGO Products"); 100 | } 101 | 102 | Actions sort = new Actions(driver); 103 | WebElement sortDropDown = driver.findElementByClassName("sort-sortBy"); 104 | sort.moveToElement(sortDropDown).perform(); 105 | driver.findElementByXPath("//label[text()='Better Discount']").click(); 106 | 107 | //Sort by Better Discount 108 | WebElement ele2 = driver.findElementByXPath("//div[@class='sort-sortBy']"); 109 | action.moveToElement(ele2).perform(); 110 | driver.findElementByXPath("//ul[@class='sort-list']/li[3]/label").click(); 111 | 112 | //Find the price of first displayed item 113 | List allitemsprice = driver.findElementsByXPath("//span[@class='product-discountedPrice']"); 114 | String firstitemprice = allitemsprice.get(0).getText(); 115 | System.out.println("*************** Price of first displayed coat is: " + firstitemprice+ "****************"); 116 | 117 | //Mouse over on size of the first item 118 | WebElement ele3 = driver.findElementByXPath("//span[@class='product-discountedPrice']"); 119 | action.moveToElement(ele3).perform(); 120 | 121 | //Click on WishList Now and ensure being re-directed to login 122 | driver.findElementByXPath("//div[contains(@class,'product-actions')]/span/span").click(); 123 | String logintitle = driver.getTitle(); 124 | System.out.println("Yaaaaaayyyyyyyyy..... Back to login page: "+logintitle+ "***********************************"); 125 | 126 | //Close Browser 127 | driver.close(); 128 | 129 | 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /Nyka.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Alert; 9 | import org.openqa.selenium.By; 10 | import org.openqa.selenium.WebDriver; 11 | import org.openqa.selenium.WebElement; 12 | import org.openqa.selenium.chrome.ChromeDriver; 13 | import org.openqa.selenium.chrome.ChromeOptions; 14 | import org.openqa.selenium.interactions.Actions; 15 | import org.openqa.selenium.support.ui.ExpectedConditions; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | 19 | public class Nyka { 20 | 21 | public static void main(String[] args) throws InterruptedException { 22 | 23 | ChromeOptions options = new ChromeOptions(); 24 | options.addArguments("--disable-notifications"); 25 | 26 | 27 | //Browser Set up 28 | 29 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 30 | ChromeDriver driver = new ChromeDriver(options); 31 | driver.get("https://www.nykaa.com/"); 32 | driver.manage().window().maximize(); 33 | driver.manage().timeouts().implicitlyWait(20000, TimeUnit.SECONDS); 34 | 35 | //Mouse Over on Brands, Popular and then Loreal click 36 | Actions action = new Actions(driver); 37 | WebElement brands = driver.findElementByXPath("//a[text()='brands']"); 38 | action.moveToElement(brands).perform(); 39 | Thread.sleep(3000); 40 | WebElement Popular = driver.findElementByXPath("//a[text()='Popular']"); 41 | action.moveToElement(Popular).perform(); 42 | 43 | action.moveToElement(driver.findElementByXPath("(//li[@class = 'brand-logo menu-links']//img)[5]")).click().build().perform(); 44 | 45 | //Opens a new window 46 | //Get the Window handles in a set 47 | Set set = driver.getWindowHandles(); 48 | List windows = new ArrayList(set); 49 | 50 | //Switch to the newly opened Window 51 | driver.switchTo().window(windows.get(1)); 52 | String newPageTitle = driver.getTitle(); 53 | System.out.println(driver.getTitle()); 54 | if (newPageTitle.contains("L'Oreal Paris")) 55 | { 56 | System.out.println("Navigated to L'Oreal Paris Page"); 57 | } 58 | else 59 | { 60 | System.out.println("Try Again"); 61 | } 62 | 63 | driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); 64 | driver.findElementByXPath("(//span[text()='popularity'])[1]").click(); 65 | driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS); 66 | driver.findElementByXPath("(//span[text()='customer top rated'])[1]").click(); 67 | System.out.println("Mathavan lam solradha kettu dhan vaanguvom!!!"); 68 | 69 | driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); 70 | 71 | action.moveToElement(driver.findElementByXPath("(//label[@for='chk_Shampoo_undefined']//span)[1]")).click().build().perform(); 72 | //driver.findElementByXPath("(//label[@for='chk_Shampoo_undefined']//span)[1]").click(); 73 | System.out.println("Shampoo Clicked");System.out.println("Category Shampoo selected"); 74 | 75 | //SELECT COLOR PROTECT SHAMPOO 76 | driver.findElementByXPath("//div[@class='m-content__product-list__title']//span[contains(text(), 'Protect')]").click(); 77 | System.out.println("Clicked on Color Protect Shampoo - Already naraicha mudikku edhukku ya color'u???"); 78 | System.out.println("Navigated to Product Page - Product Page ku vandhuttom!!!"); 79 | Thread.sleep(10000); 80 | Set productWindowSet = driver.getWindowHandles(); 81 | List productWindow = new ArrayList(productWindowSet); 82 | driver.switchTo().window(productWindow.get(2)); 83 | 84 | driver.findElementByXPath("//span[contains(text(),'175')]").click(); 85 | System.out.println("175 ML bottle selected - Oru maasathukku podhum"); 86 | 87 | String PriceEvlo = driver.findElementByXPath("(//span[@class='post-card__content-price-offer'])[1]").getText(); 88 | System.out.println("Ivlo chinna Bottle ku ivlo price ah ???? " +PriceEvlo); 89 | Thread.sleep(3000); 90 | 91 | driver.findElementByXPath("//div[@class='pull-left']//button").click(); 92 | driver.findElementByXPath("//div[@class='AddBagIcon']").click(); 93 | System.out.println("Enna panradhu??? Vaangi dhana aaganum???? "); 94 | 95 | 96 | Thread.sleep(10000); 97 | String grandTotal = driver.findElementByXPath("(//div[@class='value'])[2]").getText(); 98 | System.out.println("Motha Purse um gaali... "+grandTotal.replaceAll("\\D", "")); 99 | 100 | //14) Click Proceed 101 | driver.findElementByXPath("(//button[contains(@class,'btn full')])[2]").click(); 102 | 103 | //16) Print the warning message (delay in shipment) 104 | System.out.println("Warning Message : "+driver.findElementByXPath("//div[@class='message']").getText()); 105 | 106 | //17) Close all windows 107 | driver.quit(); 108 | 109 | 110 | 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /PepperFry.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.apache.commons.io.FileUtils; 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.JavascriptExecutor; 10 | import org.openqa.selenium.Keys; 11 | import org.openqa.selenium.OutputType; 12 | import org.openqa.selenium.UnexpectedAlertBehaviour; 13 | import org.openqa.selenium.WebElement; 14 | import org.openqa.selenium.chrome.ChromeDriver; 15 | import org.openqa.selenium.chrome.ChromeOptions; 16 | import org.openqa.selenium.interactions.Actions; 17 | import org.openqa.selenium.remote.CapabilityType; 18 | import org.openqa.selenium.remote.DesiredCapabilities; 19 | import org.openqa.selenium.remote.RemoteWebDriver; 20 | import org.openqa.selenium.support.ui.ExpectedConditions; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | 23 | public class PepperFry { 24 | 25 | public static RemoteWebDriver driver; 26 | public static void main(String[] args) throws InterruptedException, IOException { 27 | 28 | 29 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 30 | System.setProperty("webdriver.chrome.silentOutput", "true"); 31 | 32 | ChromeOptions options = new ChromeOptions(); 33 | options.addArguments("--disable-notifications"); 34 | 35 | DesiredCapabilities cap = new DesiredCapabilities(); 36 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 37 | options.merge(cap); 38 | 39 | driver = new ChromeDriver(options); 40 | Actions builder = new Actions(driver); 41 | WebDriverWait wait = new WebDriverWait(driver, 30); 42 | 43 | // Get the URL 44 | driver.get("https://www.pepperfry.com/"); 45 | driver.manage().timeouts().implicitlyWait(20000, TimeUnit.SECONDS); 46 | driver.manage().window().maximize(); 47 | 48 | builder.moveToElement(driver.findElementByLinkText("Furniture")).build().perform(); 49 | builder.click(driver.findElementByLinkText("Office Chairs")).build().perform(); 50 | Thread.sleep(5000); 51 | 52 | // Setting the Height filter 53 | driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]").clear(); 54 | driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]").sendKeys("50", Keys.ENTER); 55 | 56 | Thread.sleep(8000); 57 | 58 | try { 59 | driver.findElementByXPath("//div[@id='regPopUp']//a[@class='popup-close']").click(); 60 | System.out.println("Login popup closed."); 61 | } catch (Exception e) { 62 | System.out.println("Login popup not found."); 63 | e.printStackTrace(); 64 | } 65 | 66 | // Adding to Wishlist 67 | driver.findElementByXPath("//a[contains(@data-productname,'Poise Executive Chair in Black Colour')]").click(); 68 | System.out.println("Poise Executive Chair in Black Colour added to wishlist"); 69 | 70 | //Mouse hover on Homeware and Click Pressure Cookers under Cookware 71 | WebElement eleHomeware = driver.findElementByLinkText("Homeware"); 72 | builder.moveToElement(eleHomeware).build().perform(); 73 | 74 | WebElement elePressureCooker = driver.findElementByLinkText("Pressure Cookers"); 75 | wait.until(ExpectedConditions.elementToBeClickable(elePressureCooker)); 76 | elePressureCooker.click(); 77 | 78 | // Select Prestige as Brand 79 | WebElement elePrestige = driver.findElementByXPath("//label[@for='brandsnamePrestige']"); 80 | wait.until(ExpectedConditions.elementToBeClickable(elePrestige)); 81 | elePrestige.click(); 82 | 83 | // Select Capacity as 1-3 Ltr 84 | Thread.sleep(2000); 85 | WebElement eleLtr = driver.findElementByXPath("//label[@for='capacity_db1_Ltr_-_3_Ltr']"); 86 | wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//label[@for='capacity_db1_Ltr_-_3_Ltr']"))); 87 | eleLtr.click(); 88 | 89 | // Add "Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr" to Wishlist 90 | Thread.sleep(3000); 91 | WebElement eleWish2 = driver.findElementByXPath("//a[@data-productname='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']"); 92 | wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@data-productname='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']"))); 93 | eleWish2.click(); 94 | 95 | // Verify the number of items in Wishlist 96 | Thread.sleep(2000); 97 | WebElement WishCount = driver.findElementByXPath("(//span[@class='count_alert'])[2]"); 98 | wait.until(ExpectedConditions.visibilityOf(WishCount)); 99 | String count = WishCount.getText(); 100 | System.out.println("Number of items in the Wishlist: "+count); 101 | 102 | // Navigate to Wishlist 103 | driver.findElementByXPath("//a[contains(@class,'pf-icon pf-icon-heart')]").click(); 104 | Thread.sleep(2000); 105 | 106 | // Move Pressure Cooker only to Cart from Wishlist 107 | JavascriptExecutor executor = (JavascriptExecutor)driver; 108 | executor.executeScript("arguments[0].scrollIntoView();",driver.findElementByXPath("//div[@id='cart_item_holder']//a[contains(text(),'Cooker')]/following::div[1]//a[contains(text(),'Add to Cart')]")); 109 | WebElement eleCooker = driver.findElementByXPath("//div[@id='cart_item_holder']//a[contains(text(),'Cooker')]/following::div[1]//a[contains(text(),'Add to Cart')]"); 110 | wait.until(ExpectedConditions.visibilityOf(eleCooker)); 111 | eleCooker.click(); 112 | Thread.sleep(3000); 113 | 114 | //13) Check for the availability for Pincode 600128 115 | driver.findElementByClassName("srvc_pin_text").sendKeys("600117"); 116 | Thread.sleep(2000); 117 | driver.findElementByClassName("check_available").click(); 118 | 119 | //14) Click Proceed to Pay Securely 120 | driver.findElementByClassName("proceed_cta").click(); 121 | 122 | //15 Click Place Order 123 | WebElement eleOrder = driver.findElementByLinkText("PLACE ORDER"); 124 | wait.until(ExpectedConditions.visibilityOf(eleOrder)); 125 | eleOrder.click(); 126 | 127 | //16) Capture the screenshot of the item under Order Item 128 | WebElement eleExpand = driver.findElementByXPath("(//div[@class='nCheckout__accrodian-header-right']//span)[1]"); 129 | wait.until(ExpectedConditions.visibilityOf(eleExpand)); 130 | eleExpand.click(); 131 | 132 | File screenShot = driver.findElementByXPath("//li[@data-slick-index='0']").getScreenshotAs(OutputType.FILE); 133 | FileUtils.copyFile(screenShot, new File("./snaps/image.png")); 134 | 135 | //17) Close the browser 136 | driver.close(); 137 | 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SeleniumAndJava -------------------------------------------------------------------------------- /Snapdeal.java: -------------------------------------------------------------------------------- 1 | package testCases; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.Keys; 9 | import org.openqa.selenium.UnexpectedAlertBehaviour; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.chrome.ChromeDriver; 12 | import org.openqa.selenium.chrome.ChromeOptions; 13 | import org.openqa.selenium.interactions.Actions; 14 | import org.openqa.selenium.remote.CapabilityType; 15 | import org.openqa.selenium.remote.DesiredCapabilities; 16 | import org.openqa.selenium.support.ui.ExpectedConditions; 17 | import org.openqa.selenium.support.ui.WebDriverWait; 18 | 19 | public class Snapdeal { 20 | 21 | public static ChromeDriver driver; 22 | public static void main(String[] args) throws InterruptedException { 23 | // TODO Auto-generated method stub 24 | 25 | 26 | 27 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 28 | System.setProperty("webdriver.chrome.silentOutput", "true"); 29 | 30 | ChromeOptions options = new ChromeOptions(); 31 | options.addArguments("--disable-notifications"); 32 | 33 | DesiredCapabilities cap = new DesiredCapabilities(); 34 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 35 | options.merge(cap); 36 | 37 | driver = new ChromeDriver(options); 38 | Actions action = new Actions(driver); 39 | WebDriverWait wait = new WebDriverWait(driver, 30); 40 | 41 | 42 | driver.get("https://snapdeal.com"); 43 | driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS); 44 | driver.manage().window().maximize(); 45 | 46 | 47 | WebElement ToysMain = driver.findElementByLinkText("Toys, Kids' Fashion & more"); 48 | action.moveToElement(ToysMain).build().perform(); 49 | Thread.sleep(2000); 50 | 51 | WebElement Toys = driver.findElementByXPath("//span[text()= 'Toys']"); 52 | wait.until(ExpectedConditions.elementToBeClickable(Toys)); 53 | action.click(Toys).build().perform(); 54 | 55 | System.out.println("Toys Selected"); 56 | Thread.sleep(5000); 57 | 58 | WebElement eleEducation = driver.findElementByXPath("//div[text()='Educational Toys']"); 59 | wait.until(ExpectedConditions.visibilityOf(eleEducation)).click(); 60 | 61 | 62 | WebElement eleRating = driver.findElementByXPath("(//input[@type='radio']/following-sibling::label)[1]"); 63 | wait.until(ExpectedConditions.elementToBeClickable(eleRating)).click(); 64 | Thread.sleep(2000); 65 | 66 | // Click the offer as 40-50 67 | WebElement eleOffer = driver.findElementByXPath("//input[@value='40%20-%2050']/following-sibling::label[1]"); 68 | wait.until(ExpectedConditions.elementToBeClickable(eleOffer)).click(); 69 | 70 | // Check the availability for the pincode 71 | WebElement elePin = driver.findElementByXPath("//input[@placeholder='Enter your pincode']"); 72 | wait.until(ExpectedConditions.elementToBeClickable(elePin)).sendKeys("600088"); 73 | Thread.sleep(1000); 74 | 75 | driver.findElementByXPath("//button[text()='Check']").click(); 76 | Thread.sleep(1000); 77 | 78 | // Click the Quick View of the first product 79 | WebElement firstProduct = driver.findElementByXPath("(//img[@class='product-image wooble'])[1]"); 80 | wait.until(ExpectedConditions.visibilityOf(firstProduct)); 81 | action.moveToElement(firstProduct).build().perform(); 82 | 83 | WebElement eleQuick = driver.findElementByXPath("(//div[@class='clearfix row-disc']//div)[1]"); 84 | wait.until(ExpectedConditions.visibilityOf(eleQuick)).click(); 85 | Thread.sleep(1000); 86 | 87 | //Click on View Details 88 | WebElement ViewDetails = driver.findElementByXPath("//a[contains(text(),'view details')]"); 89 | wait.until(ExpectedConditions.visibilityOf(ViewDetails)).click(); 90 | 91 | //Capture the Price of the Product and Delivery Charge 92 | WebElement ProdPrice = driver.findElementByClassName("payBlkBig"); 93 | String price = wait.until(ExpectedConditions.visibilityOf(ProdPrice)).getText(); 94 | System.out.println("Price of the product: "+price); 95 | price = price.replaceAll("\\D", ""); 96 | int Price = Integer.parseInt(price); 97 | 98 | String delivery = driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 99 | System.out.println("Delivery Charges: "+delivery); 100 | delivery = delivery.replaceAll("\\D", ""); 101 | int Delivery = Integer.parseInt(delivery); 102 | 103 | int totalCharges = Price + Delivery; 104 | System.out.println("Total charges of first product in the result: "+totalCharges); 105 | 106 | //Click on Add to Cart 107 | driver.findElementByXPath("//span[text()='add to cart']").click(); 108 | 109 | //10) Validate the You Pay amount matches the sum of (price+deliver charge) 110 | WebElement elePay = driver.findElementByXPath("//div[@class='you-pay']//span[1]"); 111 | String pay = wait.until(ExpectedConditions.visibilityOf(elePay)).getText(); 112 | System.out.println("You pay: "+pay); 113 | pay = pay.replaceAll("\\D", ""); 114 | int youPay = Integer.parseInt(pay); 115 | 116 | if(totalCharges == youPay) 117 | System.out.println("You pay amount matches with the product price + deliver charges"); 118 | else 119 | System.out.println("You pay amount does not match with the product price + deliver charges"); 120 | 121 | //11) Search for Sanitizer 122 | driver.findElementById("inputValEnter").sendKeys("Sanitizer",Keys.ENTER); 123 | 124 | //12) Click on Product "BioAyurveda Neem Power Hand Sanitizer" 125 | WebElement eleSanitizer = driver.findElementByXPath("//p[@title='BioAyurveda Neem Power Hand Sanitizer 500 mL Pack of 1']"); 126 | wait.until(ExpectedConditions.visibilityOf(eleSanitizer)).click(); 127 | 128 | Set windowHandles = driver.getWindowHandles(); 129 | ListwindowHandlesList = new ArrayList(windowHandles); 130 | driver.switchTo().window(windowHandlesList.get(1)); 131 | 132 | //13) Capture the Price and Delivery Charge 133 | WebElement elePrice1 = driver.findElementByClassName("payBlkBig"); 134 | String price1 = wait.until(ExpectedConditions.visibilityOf(elePrice1)).getText(); 135 | System.out.println("Price of the product: "+price1); 136 | price1 = price1.replaceAll("\\D", ""); 137 | int Price1 = Integer.parseInt(price1); 138 | 139 | String delivery1 = driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 140 | System.out.println("Delivery Charges: "+delivery1); 141 | delivery1 = delivery1.replaceAll("\\D", ""); 142 | int Delivery1 = Integer.parseInt(delivery1); 143 | 144 | int total2 = Price1 + Delivery1; 145 | System.out.println("Total charges of Sanitizer: "+total2); 146 | 147 | //14) Click on Add to Cart 148 | Thread.sleep(1000); 149 | //JavascriptExecutor executor = (JavascriptExecutor)driver; 150 | //executor.executeScript("scroll(0, 250)"); 151 | driver.findElementById("add-cart-button-id").click(); 152 | 153 | Thread.sleep(3000); 154 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByClassName("cartTextSpan"))); 155 | driver.findElementByClassName("cartTextSpan").click(); 156 | 157 | //15) Click on Cart 158 | WebElement eleCart = driver.findElementByClassName("cartTextSpan"); 159 | wait.until(ExpectedConditions.elementToBeClickable(eleCart)); 160 | action.click(eleCart).build().perform(); 161 | 162 | //16) Validate the Proceed to Pay matches the total amount of both the products 163 | WebElement eleProceed = driver.findElementByXPath("//input[@type='button']"); 164 | String grandTotal = wait.until(ExpectedConditions.visibilityOf(eleProceed)).getAttribute("value"); 165 | System.out.println("Proceed to Pay Amount: "+grandTotal); 166 | grandTotal = grandTotal.replaceAll("\\D", ""); 167 | int proceedPay = Integer.parseInt(grandTotal); 168 | 169 | int GrandTotal = totalCharges + total2; 170 | System.out.println("Calculated Total Amount: "+GrandTotal); 171 | 172 | if(GrandTotal == proceedPay) 173 | System.out.println("The Proceed to Pay amount matches with total amount of both products"); 174 | else 175 | System.out.println("The Proceed to Pay amount does not match with total amount of both products"); 176 | 177 | //17) Close all the windows 178 | driver.quit(); 179 | 180 | 181 | } 182 | 183 | } 184 | --------------------------------------------------------------------------------