├── README.md ├── MakeMyTrip.java ├── Myntra.java ├── Nykaa.java ├── HpStore.java ├── Azure.java ├── Snapdeal.java ├── Carwale.java ├── PepperFry.java ├── Honda.java ├── Shiksha.java └── Ajio.java /README.md: -------------------------------------------------------------------------------- 1 | # SeleniumJavaCodes -------------------------------------------------------------------------------- /MakeMyTrip.java: -------------------------------------------------------------------------------- 1 | package day3; 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.JavascriptExecutor; 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.support.ui.ExpectedConditions; 14 | import org.openqa.selenium.support.ui.Select; 15 | import org.openqa.selenium.support.ui.WebDriverWait; 16 | import org.testng.annotations.Test; 17 | 18 | public class MakeMyTrip { 19 | 20 | @Test 21 | public void roomBooking() throws InterruptedException { 22 | 23 | //1) Go to https://www.makemytrip.com/ 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 25 | ChromeOptions options = new ChromeOptions(); 26 | options.addArguments("--disable-notifications"); 27 | ChromeDriver driver = new ChromeDriver(options); 28 | driver.get("https://www.makemytrip.com/"); 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 31 | 32 | //2) Click Hotels 33 | driver.findElementByLinkText("Hotels").click(); 34 | 35 | //3) Enter city as Goa, and choose Goa, India 36 | driver.findElementByXPath("//span[text()='City / Hotel / Area / Building']").click(); 37 | driver.findElementByXPath("//input[@placeholder='Enter city/ Hotel/ Area/ Building']").sendKeys("Goa"); 38 | 39 | WebDriverWait wait = new WebDriverWait(driver,20); 40 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//p[text()='Goa, India']"))).click(); 41 | 42 | //4) Enter Check in date as Next month 15th (May 15) and Check out as start date+5 43 | driver.findElementById("checkin").click(); 44 | String checkin_date = driver.findElementByXPath("(//div[text()='15'])[2]").getText(); 45 | driver.findElementByXPath("(//div[text()='15'])[2]").click(); 46 | 47 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Select Checkout Date']"))); 48 | driver.findElementByXPath("(//div[text()='20'])[2]").click(); 49 | 50 | //5) Click on ROOMS & GUESTS and click 2 Adults and one Children(age 12). Click Apply Button. 51 | driver.findElementById("guest").click(); 52 | driver.findElementByXPath("//li[@data-cy='adults-2']").click(); 53 | driver.findElementByXPath("//li[@data-cy='children-1']").click(); 54 | 55 | Select ageSelect = new Select(driver.findElementByClassName("ageSelectBox")); 56 | ageSelect.selectByVisibleText("12"); 57 | driver.findElementByXPath("//button[text()='APPLY']").click(); 58 | 59 | //6) Click Search button 60 | driver.findElementById("hsw_search_button").click(); 61 | System.out.println("clicked search button"); 62 | Thread.sleep(1500); 63 | 64 | //7) Select locality as Baga 65 | driver.findElementByXPath("//body[contains(@class,'overlayWholeBlack')]").click(); 66 | WebElement locality = driver.findElementByXPath("//input[@type='checkbox' ]/following-sibling::label[text()='Baga']"); 67 | locality.click(); 68 | Thread.sleep(500); 69 | 70 | //8) Select 5 start in Star Category under Select Filters 71 | driver.findElementByXPath("//input[@type='checkbox' ]/following-sibling::label[text()='5 Star']").click(); 72 | String parentWindow = driver.getWindowHandle(); 73 | 74 | //9) Click on the first resulting hotel and go to the new window 75 | driver.findElementByXPath("(//p[@id='hlistpg_hotel_name'])[1]").click(); 76 | 77 | Set windowHandles_set = driver.getWindowHandles(); 78 | List windowHandles_list = new ArrayList<>(windowHandles_set); 79 | driver.switchTo().window(windowHandles_list.get(1)); 80 | 81 | //10) Print the Hotel Name 82 | String hotelName = driver.findElement(By.id("detpg_hotel_name")).getText(); 83 | System.out.println("Hotel name is -- "+hotelName); 84 | 85 | //11) Click MORE OPTIONS link and Select 3Months plan and close 86 | driver.findElementByXPath("(//span[contains(text(),'MORE OPTIONS')])[1]").click(); 87 | driver.findElementByXPath("//td[text()='3']/following-sibling::td/span").click(); 88 | driver.findElementByClassName("close").click();; 89 | Thread.sleep(500); 90 | 91 | //12) Click on BOOK THIS NOW 92 | driver.findElementByXPath("//a[text()='BOOK THIS NOW']").click(); 93 | 94 | //13) Print the Total Payable amount 95 | String totalAmt = driver.findElementById("revpg_total_payable_amt").getText(); 96 | System.out.println("Total Payable amount is -- "+totalAmt); 97 | 98 | //14) Close the browser 99 | driver.close(); 100 | 101 | } 102 | 103 | 104 | } 105 | -------------------------------------------------------------------------------- /Myntra.java: -------------------------------------------------------------------------------- 1 | package day1; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.interactions.Actions; 12 | import org.openqa.selenium.support.ui.ExpectedConditions; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | import org.testng.annotations.Test; 15 | 16 | public class Myntra { 17 | 18 | @Test 19 | public void login() throws InterruptedException { 20 | 21 | // Setting Property and diable notifications 22 | 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 24 | 25 | ChromeOptions options = new ChromeOptions(); 26 | 27 | options.addArguments("--disable-notifications"); 28 | 29 | ChromeDriver driver = new ChromeDriver(options); 30 | 31 | // 1) Launch the URL 32 | 33 | driver.get("https://www.myntra.com/"); 34 | 35 | driver.manage().window().maximize(); 36 | 37 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 38 | 39 | Thread.sleep(500); 40 | 41 | 42 | // 2) to hover on Women option and Select Jackets and coats 43 | 44 | Actions action = new Actions(driver); 45 | action.moveToElement(driver.findElementByXPath("//div[@class='desktop-navContent']//a[text()='Women']")).perform();; 46 | 47 | WebDriverWait wait = new WebDriverWait(driver,15); 48 | 49 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Jackets & Coats"))).click(); 50 | 51 | // 3) To get the total count and verify with category sum 52 | 53 | String text = driver.findElementByClassName("title-count").getText(); 54 | 55 | String count = text.replaceAll("[^0-9]", ""); 56 | 57 | int totalCount = Integer.parseInt(count); 58 | 59 | String text1 = driver.findElementByXPath("(//span[@class='categories-num'])[1]").getText(); 60 | String jack_count = text1.replaceAll("[^0-9]",""); 61 | int jacketCount = Integer.parseInt(jack_count); 62 | 63 | String text2 = driver.findElementByXPath("(//span[@class='categories-num'])[2]").getText(); 64 | String coat_count = text2.replaceAll("[^0-9]",""); 65 | int coatCount = Integer.parseInt(coat_count); 66 | 67 | System.out.println(count+" -> "+jack_count+" and "+coat_count); 68 | 69 | if(totalCount==jacketCount+coatCount) { 70 | 71 | System.out.println("Total count matches with both catagories"); 72 | } 73 | else { 74 | System.out.println("Count is not matched"); 75 | } 76 | 77 | //4) To filter Coats 78 | 79 | driver.findElementByXPath("(//div[@class='common-checkboxIndicator'])[2]").click(); 80 | 81 | 82 | // 5) CLick + More option under Brands and Filter MANGO brand 83 | 84 | driver.findElementByXPath("//div[@class='brand-more']").click(); 85 | 86 | driver.findElementByClassName("FilterDirectory-searchInput").sendKeys("MANGO"); 87 | 88 | Thread.sleep(500); 89 | 90 | driver.findElementByXPath("//span[@class='FilterDirectory-count']/following-sibling::div").click(); 91 | 92 | Thread.sleep(500); 93 | 94 | driver.findElementByXPath("//span[@class='myntraweb-sprite FilterDirectory-close sprites-remove']").click(); 95 | 96 | Thread.sleep(500); 97 | 98 | 99 | // 6) To get the brand names 100 | List brands = driver.findElementsByClassName("product-brand"); 101 | 102 | for (WebElement eachBrand : brands) { 103 | 104 | if(eachBrand.getText().equals("MANGO")) { 105 | System.out.println("Brand name is confirmed :: "+eachBrand.getText()); 106 | } 107 | else { 108 | System.out.println("Brand name is not as expected"); 109 | } 110 | } 111 | 112 | // 7) To sort By better discount 113 | Actions action1 = new Actions(driver); 114 | 115 | action1.moveToElement(driver.findElementByClassName("sort-sortBy")).perform(); 116 | 117 | driver.findElementByXPath("//label[text()='Better Discount']").click(); 118 | 119 | // 8) To get the prices in list and print the first items price 120 | List discountPrices = driver.findElementsByClassName("product-discountedPrice"); 121 | 122 | String price = discountPrices.get(0).getText(); 123 | 124 | System.out.println("Price of the first listed item is :: "+price); 125 | 126 | // 9) To hover on the first item's price 127 | Actions action2 = new Actions(driver); 128 | 129 | action2.moveToElement(driver.findElementByClassName("product-price")).perform(); 130 | 131 | driver.findElementByXPath("(//span[text()='wishlist now'])[1]").click(); 132 | 133 | // 10) Too close the browser 134 | driver.close(); 135 | } 136 | 137 | 138 | 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /Nykaa.java: -------------------------------------------------------------------------------- 1 | package day2; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.interactions.Actions; 12 | import org.openqa.selenium.support.ui.ExpectedConditions; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | import org.testng.annotations.Test; 15 | 16 | public class Nykaa { 17 | 18 | @Test 19 | public void shoping() throws InterruptedException { 20 | 21 | // Setting Property and disable notifications 22 | 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 24 | 25 | ChromeOptions options = new ChromeOptions(); 26 | 27 | options.addArguments("--disable-notifications"); 28 | 29 | ChromeDriver driver = new ChromeDriver(options); 30 | 31 | // 1) Launch the URL 32 | 33 | driver.get("https://www.nykaa.com/"); 34 | 35 | driver.manage().window().maximize(); 36 | 37 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 38 | 39 | // 2) Mouse over on Brands and Mouseover on Popular 40 | 41 | Actions action1 = new Actions(driver); 42 | 43 | action1.moveToElement(driver.findElementByXPath("//a[text()='brands']")).perform(); 44 | 45 | WebDriverWait wait = new WebDriverWait(driver,15); 46 | 47 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[text()='Popular']"))).click(); 48 | 49 | String parent_windowHandle = driver.getWindowHandle(); 50 | 51 | // 3) Click Loreal Paris brand 52 | 53 | driver.findElementByXPath("//img[@src='https://adn-static2.nykaa.com/media/wysiwyg/2019/lorealparis.png']").click(); 54 | 55 | // 4) Go to the newly opened window and check the title contains L'Oreal Paris 56 | 57 | Set windowHandles = driver.getWindowHandles(); 58 | 59 | List windowHandles_list = new ArrayList<>(windowHandles); 60 | 61 | driver.switchTo().window(windowHandles_list.get(1)); 62 | 63 | String title = driver.getTitle(); 64 | 65 | System.out.println("Title of the current window is ::"+title); 66 | 67 | if(title.contains("L'Oreal Paris")) { 68 | 69 | System.out.println("The title contains L'Oreal Paris"); 70 | } 71 | else { 72 | System.out.println("The title doesn't contain L'Oreal Paris"); 73 | } 74 | 75 | // 5) Click sort By and select customer top rated 76 | 77 | driver.findElementByXPath("//span[@class='pull-left']").click(); 78 | driver.findElementByXPath("//span[text()='customer top rated']").click(); 79 | Thread.sleep(3000); 80 | 81 | JavascriptExecutor js = (JavascriptExecutor) driver; 82 | 83 | // 6) Click Category and click Shampoo 84 | driver.findElementByXPath("//div[text()='Category']").click(); 85 | 86 | WebElement shampoo_category = driver.findElementByXPath("(//span[contains(text(), 'Shampoo')])[1]"); 87 | 88 | shampoo_category.click(); 89 | 90 | // 7) check whether the Filter is applied with Shampoo 91 | 92 | if(driver.findElementByXPath("//ul[@class='pull-left applied-filter-lists']/li").isDisplayed()) { 93 | 94 | String filter_text = driver.findElementByXPath("//ul[@class='pull-left applied-filter-lists']/li").getText(); 95 | 96 | if (filter_text.contains("Shampoo")) { 97 | 98 | System.out.println("The filter applied is :: "+filter_text); 99 | } 100 | else { 101 | System.out.println("The filter applied dont contain :: "+filter_text); 102 | } 103 | } 104 | else { 105 | 106 | System.out.println("The filter section is not showing any filters applied"); 107 | } 108 | 109 | // 8) Click on L'Oreal Paris Colour Protect Shampoo 110 | WebElement shampooToSelect = driver.findElementByXPath("//img[@src='https://images-static.nykaa.com/media/catalog/product/tr:w-276,h-276,cm-pad_resize/8/9/8901526102518_color_protect_shampoo_75ml_82.5ml__i1_1.png']"); 111 | 112 | js.executeScript("arguments[0].scrollIntoView();", shampooToSelect); 113 | 114 | shampooToSelect.click(); 115 | 116 | // 9) GO to the new window and select size as 175ml 117 | 118 | Set windowHandles2 = driver.getWindowHandles(); 119 | 120 | List windowHandles2_list = new ArrayList<>(windowHandles2); 121 | 122 | driver.switchTo().window(windowHandles2_list.get(2)); 123 | 124 | if(driver.findElementByXPath("//span[text()='175ml']").isEnabled()) { 125 | driver.findElementByXPath("//span[text()='175ml']").click(); 126 | } 127 | 128 | // 10) Print the MRP of the product 129 | 130 | String mrp_text = driver.findElementByXPath("(//div[@class='price-info']/span[2])[1]").getText(); 131 | 132 | System.out.println("The price of the product is :: "+mrp_text); 133 | 134 | // 11) Click on ADD to BAG 135 | 136 | driver.findElementByXPath("(//button[text()='ADD TO BAG'])[1]").click(); 137 | 138 | // 12) Go to Shopping Bag 139 | 140 | driver.findElementByClassName("AddToBagbox").click(); 141 | 142 | // 13) Print the Grand Total amount 143 | 144 | String grand_total = driver.findElementByXPath("//div[@class='value medium-strong']").getText(); 145 | 146 | System.out.println("The Grand total in Shopping bag is :: "+grand_total); 147 | 148 | // 14) Click Proceed 149 | 150 | driver.findElementByClassName("proceed-arrow").click(); 151 | 152 | // 15) Click on Continue as Guest 153 | 154 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//button[text()='CONTINUE AS GUEST']"))).click(); 155 | 156 | // 16) Print the warning message (delay in shipment) 157 | 158 | String warning = driver.findElementByClassName("message").getText(); 159 | 160 | System.out.println("Warning :: "+warning); 161 | 162 | // 17) Close all windows 163 | 164 | driver.quit(); 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /HpStore.java: -------------------------------------------------------------------------------- 1 | package day4; 2 | 3 | import java.util.NoSuchElementException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.interactions.Actions; 12 | import org.openqa.selenium.support.ui.ExpectedConditions; 13 | import org.openqa.selenium.support.ui.Select; 14 | import org.openqa.selenium.support.ui.WebDriverWait; 15 | import org.testng.annotations.Test; 16 | 17 | public class HpStore { 18 | 19 | @Test 20 | public void placeOrder() throws InterruptedException { 21 | 22 | // 1) Go to https://store.hp.com/in-en/ 23 | System.setProperty("webdriver.chrome.silentOutput", "true"); 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 25 | ChromeOptions options = new ChromeOptions(); 26 | options.addArguments("--disable-notifications"); 27 | ChromeDriver driver = new ChromeDriver(options); 28 | driver.get("https://store.hp.com/in-en/"); 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 31 | 32 | //driver.findElementByXPath("//button[text()='Accept Cookies']").click(); 33 | try { 34 | driver.findElementByXPath("//button[text()='Accept Cookies']").click(); 35 | } 36 | catch (NoSuchElementException exception) { 37 | System.out.println("Exception2 is catched"); 38 | } 39 | 40 | try { 41 | driver.findElementByXPath("//span[@class='optly-modal-close close-icon']").click(); 42 | } 43 | catch (NoSuchElementException exception) { 44 | System.out.println("Exception1 is catched"); 45 | } 46 | 47 | /* WebDriverWait wait = new WebDriverWait(driver,30); 48 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='inside_notify_content']"))); 49 | driver.findElementById("inside_holder").click();*/ 50 | 51 | // 2) Mouse over on Laptops menu and click on Pavilion 52 | Actions action = new Actions(driver); 53 | action.moveToElement(driver.findElementByLinkText("Laptops")).perform(); 54 | 55 | driver.findElementByLinkText("Pavilion").click(); 56 | 57 | try { 58 | driver.findElementByXPath("//div[@class='inside_closeButton fonticon icon-hclose']").click(); 59 | } 60 | catch (NoSuchElementException exception) { 61 | System.out.println("Exception3 is catched"); 62 | } 63 | 64 | try { 65 | driver.findElementByXPath("//button[text()='Accept Cookies']").click(); 66 | } 67 | catch (NoSuchElementException exception) { 68 | System.out.println("Exception2 is catched"); 69 | } 70 | 71 | try { 72 | driver.findElementByXPath("//span[@class='optly-modal-close close-icon']").click(); 73 | } 74 | catch (NoSuchElementException exception) { 75 | System.out.println("Exception1 is catched"); 76 | } 77 | 78 | // 3) Under SHOPPING OPTIONS -->Processor -->Select Intel Core i7 79 | JavascriptExecutor js = (JavascriptExecutor) driver; 80 | js.executeScript("window.scrollBy(0, 250)"); 81 | driver.findElementByXPath("(//span[text()='Processor'])[2]").click(); 82 | driver.findElementByXPath("//span[text()='Intel Core i7']").click(); 83 | Thread.sleep(3000); 84 | 85 | // 4) Hard Drive Capacity -->More than 1TB 86 | driver.findElementByXPath("//span[text()='More than 1 TB']").click(); 87 | 88 | // 5) Select Sort By: Price: Low to High 89 | js.executeScript("window.scrollBy(0, 600)"); 90 | WebElement sortBy = driver.findElementById("sorter"); 91 | WebDriverWait wait = new WebDriverWait(driver,30); 92 | wait.until(ExpectedConditions.elementToBeClickable(sortBy)).click(); 93 | Select sortBySelect = new Select(sortBy); 94 | sortBySelect.selectByVisibleText("Price : Low to High "); 95 | 96 | // 6) Print the First resulting Product Name and Price 97 | 98 | String productName = driver.findElementByXPath("(//a[@class='product-item-link'])[1]").getText(); 99 | String price = driver.findElementByXPath("(//span[@class='price-container price-final_price tax weee']//span[@class='price'])[1]").getText(); 100 | String price_pd = price.replaceAll("\\D",""); 101 | System.out.println("The first resulting product is -- "+productName+" and its price is -- "+price_pd); 102 | 103 | // 7) Click on Add to Cart 104 | driver.findElementByXPath("(//button[@title='Add To Cart'])[1]").click(); 105 | 106 | // 8) Click on Shopping Cart icon --> Click on View and Edit Cart 107 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[@class='action showcart']"))).click(); 108 | driver.findElementByXPath("//span[text()='View and edit cart']").click(); 109 | 110 | // 9) Check the Shipping Option --> Check availability at Pincode 111 | driver.findElementById("standard_delivery").click(); 112 | driver.findElementByName("pincode").sendKeys("600064"); 113 | driver.findElementByXPath("//button[text()='check']").click(); 114 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[@class='available']"))).click(); 115 | System.out.println("The delivery of status is :: "+driver.findElementByXPath("//span[@class='available']").getText()); 116 | 117 | // 10) Verify the order Total against the product price 118 | String orderTotal = driver.findElementByXPath("//tr[@class='grand totals']//strong/span").getText(); 119 | String orderAmount = orderTotal.replaceAll("\\D",""); 120 | System.out.println("Order Total amount is :: "+orderAmount); 121 | 122 | // 11) Proceed to Checkout if Order Total and Product Price matches 123 | if(price_pd.equals(orderAmount)) { 124 | System.out.println("order amount is matched"); 125 | driver.findElementById("sendIsCAC").click(); 126 | } 127 | else { 128 | System.out.println("order amount is not matched"); 129 | } 130 | 131 | // 12) Click on Place Order 132 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='place-order-primary']//span[text()='Place Order']"))).click(); 133 | 134 | // 13) Capture the Error message and Print 135 | String errorMessage = driver.findElementById("customer-email-error").getText(); 136 | System.out.println("The error message displayed is -- "+errorMessage); 137 | 138 | // 14) Close Browser 139 | driver.quit(); 140 | 141 | 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /Azure.java: -------------------------------------------------------------------------------- 1 | package day17.evaluation2; 2 | 3 | import java.io.File; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.JavascriptExecutor; 7 | import org.openqa.selenium.UnexpectedAlertBehaviour; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.remote.CapabilityType; 12 | import org.openqa.selenium.remote.DesiredCapabilities; 13 | import org.openqa.selenium.support.ui.ExpectedConditions; 14 | import org.openqa.selenium.support.ui.Select; 15 | import org.openqa.selenium.support.ui.WebDriverWait; 16 | 17 | public class Azure { 18 | 19 | public static void main(String[] args) throws InterruptedException { 20 | 21 | // 1) Go to https://azure.microsoft.com/en-in/ 22 | System.setProperty("webdriver.chrome.silentOutput", "true"); 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 24 | ChromeOptions options = new ChromeOptions(); 25 | options.addArguments("--disable-notifications"); 26 | 27 | DesiredCapabilities cap = new DesiredCapabilities(); 28 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 29 | options.merge(cap); 30 | 31 | ChromeDriver driver = new ChromeDriver(options); 32 | driver.get("https://azure.microsoft.com/en-in/"); 33 | driver.manage().window().maximize(); 34 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 35 | 36 | // 2) Click on Pricing 37 | driver.findElementByXPath("//a[text()='Pricing']").click(); 38 | 39 | // 3) Click on Pricing Calculator 40 | driver.findElementByXPath("//a[contains(text(),'Pricing calculator')]").click(); 41 | 42 | // 4) Click on Containers 43 | JavascriptExecutor js = (JavascriptExecutor)driver; 44 | WebElement container = driver.findElementByXPath("//button[text()='Containers']"); 45 | js.executeScript("arguments[0].click();", container); 46 | 47 | // 5) Select Container Instances 48 | driver.findElementByXPath("(//span[text()='Container Instances'])[3]").click(); 49 | 50 | // 6) Click on Container Instance Added View 51 | WebDriverWait wait = new WebDriverWait(driver,30); 52 | try { 53 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[text()='View']"))).click(); 54 | System.out.println("Clicked View"); 55 | } catch (Exception e) { 56 | System.out.println("Exception is catched when View try click"); 57 | } 58 | 59 | // 7) Select Region as "South India" 60 | Select regionSelect = new Select(driver.findElementByName("region")); 61 | regionSelect.selectByVisibleText("South India"); 62 | 63 | // 8) Set the Duration as 180000 seconds 64 | driver.findElementByXPath("//h5[text()='Duration']/parent::div//input[@aria-label='Seconds']").clear(); 65 | driver.findElementByXPath("//h5[text()='Duration']/parent::div//input[@aria-label='Seconds']").sendKeys("180000"); 66 | 67 | // 9) Select the Memory as 4GB 68 | Select memorySelect = new Select(driver.findElementByName("memory")); 69 | memorySelect.selectByVisibleText("4 GB"); 70 | 71 | // 10) Enable SHOW DEV/TEST PRICING 72 | WebElement toggleDevPricing = driver.findElementByXPath("//span[text()='Show Dev/Test Pricing']"); 73 | js.executeScript("arguments[0].click();", toggleDevPricing); 74 | 75 | // 11) Select Indian Rupee as currency 76 | Thread.sleep(1500); 77 | Select currencySelect = new Select(driver.findElementByXPath("//select[@class='select currency-dropdown']")); 78 | currencySelect.selectByValue("INR"); 79 | 80 | // 12) Print the Estimated monthly price 81 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//div[@class='row row-size1 column estimate-total']//span[@class='numeric']/span)[2]"))); 82 | String estMonthlyCost = driver.findElementByXPath("(//div[@class='row row-size1 column estimate-total']//span[@class='numeric']/span)[2]").getText(); 83 | System.out.println("The estimated Monthly Cost is :: "+estMonthlyCost); 84 | 85 | // 13) Click on Export to download the estimate as excel 86 | driver.findElementByXPath("//button[contains(@class,'export-button')]").click(); 87 | Thread.sleep(2000); 88 | 89 | // 14) Verify the downloded file in the local folder 90 | String fileName = "ExportedEstimate"; 91 | String filePath = "C:\\Users\\hp\\Downloads\\"+fileName+".xlsx"; 92 | File file = new File(filePath); 93 | if(file.exists()) { 94 | file.delete(); 95 | System.out.println("File Download is validated and also deleted the downloaded entry"); 96 | } 97 | else { 98 | System.out.println("File is not exists in the downloaded path"); 99 | } 100 | 101 | // 15) Navigate to Example Scenarios and Select CI/CD for Containers 102 | Thread.sleep(2000); 103 | WebElement exScenarios = driver.findElementByXPath("//a[text()='Example Scenarios']"); 104 | js.executeScript("arguments[0].click();", exScenarios); 105 | Thread.sleep(1000); 106 | WebElement ciCdContainer = driver.findElementByXPath("//span[text()='CI/CD for Containers']"); 107 | wait.until(ExpectedConditions.elementToBeClickable(ciCdContainer)); 108 | js.executeScript("arguments[0].click()",ciCdContainer); 109 | 110 | // 16) Click Add to Estimate 111 | WebElement addEstimate = driver.findElementByXPath("//button[text()='Add to estimate']"); 112 | wait.until(ExpectedConditions.elementToBeClickable(addEstimate)); 113 | js.executeScript("arguments[0].click()",addEstimate); 114 | 115 | // 17) Change the Currency as Indian Rupee 116 | Thread.sleep(500); 117 | Select currencySelect1 = new Select(driver.findElementByXPath("//select[@class='select currency-dropdown']")); 118 | currencySelect1.selectByValue("INR"); 119 | 120 | // 18) Enable SHOW DEV/TEST PRICING 121 | Thread.sleep(500); 122 | driver.findElementByXPath("//span[text()='Show Dev/Test Pricing']").click(); 123 | 124 | // 19) Export the Estimate 125 | driver.findElementByXPath("//button[contains(@class,'export-button')]").click(); 126 | Thread.sleep(2000); 127 | 128 | // 20) Verify the downloded file in the local folder 129 | 130 | if(file.exists()) { 131 | file.delete(); 132 | System.out.println("File Download is validated for CI/CD Container and also deleted the downloaded entry"); 133 | } 134 | else { 135 | System.out.println("File for CI/CD Container is not exists in the downloaded path"); 136 | } 137 | 138 | driver.quit(); 139 | 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /Snapdeal.java: -------------------------------------------------------------------------------- 1 | package day11; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | import org.openqa.selenium.Keys; 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.support.ui.ExpectedConditions; 16 | import org.openqa.selenium.support.ui.WebDriverWait; 17 | 18 | public class Snapdeal { 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | 22 | // 1) Go to https://www.snapdeal.com/ 23 | System.setProperty("webdriver.chrome.silentOutput", "true"); 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 25 | ChromeOptions options = new ChromeOptions(); 26 | options.addArguments("--disable-notifications"); 27 | ChromeDriver driver = new ChromeDriver(options); 28 | 29 | DesiredCapabilities cap = new DesiredCapabilities(); 30 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 31 | options.merge(cap); 32 | 33 | driver.get("https://www.snapdeal.com/"); 34 | driver.manage().window().maximize(); 35 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 36 | 37 | // 2) ‎Mouse over on Toys, Kids' Fashion & more and click on Toys 38 | Actions action = new Actions(driver); 39 | action.moveToElement(driver.findElementByXPath("//li[@class='navlink lnHeight']//span[contains(text(),'Toys, Kids')]")).build().perform(); 40 | 41 | // 3) Click Educational Toys in Toys & Games 42 | WebDriverWait wait = new WebDriverWait(driver,30); 43 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Educational Toys']"))).click(); 44 | 45 | // 4) Click the Customer Rating 4 star and Up 46 | WebElement ele = driver.findElementByXPath("//label[@for='avgRating-4.0']/a"); 47 | action.moveToElement(ele).click().perform(); 48 | 49 | // 5) Click the offer as 40-50 50 | Thread.sleep(500); 51 | action.moveToElement(driver.findElementByXPath("//label[@for='discount-40%20-%2050']/a")).click().perform(); 52 | //wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[text()=' 40 - 50']"))).click(); 53 | 54 | // 6) Check the availability for the pincode 55 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//input[@placeholder='Enter your pincode']"))); 56 | driver.findElementByXPath("//input[@placeholder='Enter your pincode']").sendKeys("600064"); 57 | driver.findElementByXPath("//button[@class='pincode-check']").click(); 58 | 59 | if (driver.findElementByXPath("//div[@class='sdCheckbox js-pincode-checkbox ']/following::span[@class='delivery-msg']").isDisplayed()) { 60 | System.out.println("Delivery is available"); 61 | } 62 | else { 63 | System.out.println("Delivery is not available"); 64 | } 65 | 66 | // 7) Click the Quick View of the first product 67 | WebElement ele1 = driver.findElementByXPath("(//img[@class='product-image wooble'])[1]"); 68 | action.moveToElement(ele1).build().perform(); 69 | driver.findElementByXPath("(//div[contains(text(),'Quick View')])[1]").click(); 70 | 71 | // 8) Click on View Details 72 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[contains(text(),'view details')]"))).click(); 73 | 74 | // 9) Capture the Price of the Product and Delivery Charge 75 | String price = driver.findElementByXPath("//span[@itemprop='price']").getText(); 76 | String text = driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 77 | String deliveryCharge = text.replaceAll("[^0-9]", ""); 78 | System.out.println("The Product price - "+price+" and the Delivery charge -> "+deliveryCharge); 79 | 80 | // 10) Validate the You Pay amount matches the sum of (price+deliver charge) 81 | driver.findElementByXPath("//span[text()='add to cart']").click(); 82 | String youPayAmt = driver.findElementByXPath("//div[@class='you-pay']/span").getText(); 83 | String youPay = youPayAmt.replaceAll("[^0-9]", ""); 84 | 85 | int price1 = Integer.parseInt(price); 86 | int delivery_charge = Integer.parseInt(deliveryCharge); 87 | int you_payAmt = Integer.parseInt(youPay); 88 | int totalP1 = price1+delivery_charge; 89 | if(totalP1==you_payAmt) { 90 | System.out.println("You pay amount matches the sum"); 91 | } 92 | else { 93 | System.out.println("AMount is not matched"); 94 | } 95 | 96 | // 11) Search for Sanitizer 97 | driver.findElementById("inputValEnter").sendKeys("Sanitizer",Keys.ENTER); 98 | 99 | // 12) Click on Product "BioAyurveda Neem Power Hand Sanitizer" 100 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//img[contains(@title,'BioAyurveda Neem Power')]"))); 101 | driver.findElementByXPath("//img[contains(@title,'BioAyurveda Neem Power')]").click(); 102 | 103 | /** To switch the control to New Window **/ 104 | Set windowHandles_set = driver.getWindowHandles(); 105 | List window_list = new ArrayList<>(windowHandles_set); 106 | 107 | driver.switchTo().window(window_list.get(1)); 108 | 109 | // 13) Capture the Price and Delivery Charge 110 | String sanitizerPrice = driver.findElementByXPath("//span[@itemprop='price']").getText(); 111 | String textDelivery = driver.findElementByXPath("(//span[@class='availCharges'])[2]").getText(); 112 | String deliveryChargeS = textDelivery.replaceAll("[^0-9]", ""); 113 | System.out.println("The Product price - "+sanitizerPrice+" and the Delivery charge -> "+deliveryChargeS); 114 | 115 | int price2 = Integer.parseInt(sanitizerPrice); 116 | int deliveryCharge2 = Integer.parseInt(deliveryChargeS); 117 | int totalP2 = price2+deliveryCharge2; 118 | 119 | // 14) Click on Add to Cart 120 | driver.findElementByXPath("//span[text()='add to cart']").click(); 121 | 122 | // 15) Click on Cart 123 | driver.findElementByXPath("//span[text()='Cart']").click(); 124 | 125 | // 16) Validate the Proceed to Pay matches the total amount of both the products 126 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//input[contains(@value,'PROCEED')]"))); 127 | String proceedToPayAmt = driver.findElementByXPath("//input[contains(@value,'PROCEED')]").getAttribute("value"); 128 | String totalAmount = proceedToPayAmt.replaceAll("[^0-9]", ""); 129 | 130 | int totalPay = Integer.parseInt(totalAmount); 131 | 132 | if (totalPay==totalP1+totalP2) { 133 | System.out.println("Total prices in cart matched with sum of product cost"); 134 | } 135 | else { 136 | System.out.println("Total is not matched"); 137 | } 138 | 139 | // 17) Close all the windows 140 | driver.quit(); 141 | 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /Carwale.java: -------------------------------------------------------------------------------- 1 | package day12; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.LinkedHashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Map.Entry; 9 | import java.util.Set; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import org.openqa.selenium.JavascriptExecutor; 13 | import org.openqa.selenium.UnexpectedAlertBehaviour; 14 | import org.openqa.selenium.WebElement; 15 | import org.openqa.selenium.chrome.ChromeDriver; 16 | import org.openqa.selenium.chrome.ChromeOptions; 17 | import org.openqa.selenium.interactions.Actions; 18 | import org.openqa.selenium.remote.CapabilityType; 19 | import org.openqa.selenium.remote.DesiredCapabilities; 20 | import org.openqa.selenium.support.ui.ExpectedConditions; 21 | import org.openqa.selenium.support.ui.Select; 22 | import org.openqa.selenium.support.ui.WebDriverWait; 23 | 24 | public class Carwale { 25 | 26 | public static void main(String[] args) throws InterruptedException { 27 | 28 | //1) Go to https://www.carwale.com/ 29 | System.setProperty("webdriver.chrome.silentOutput", "true"); 30 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 31 | ChromeOptions options = new ChromeOptions(); 32 | options.addArguments("--disable-notifications"); 33 | 34 | DesiredCapabilities cap = new DesiredCapabilities(); 35 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 36 | options.merge(cap); 37 | 38 | ChromeDriver driver = new ChromeDriver(options); 39 | driver.get("https://www.carwale.com/"); 40 | driver.manage().window().maximize(); 41 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 42 | 43 | //2) Click on Used 44 | driver.findElementByXPath("//li[@data-tabs='usedCars']").click(); 45 | 46 | //3) Select the City as Chennai 47 | driver.findElementByXPath("//input[@placeholder='Type to select city name, e.g. Mumbai']").sendKeys("Chennai"); 48 | driver.findElementByXPath("//a[@cityname='chennai,tamilnadu']").click(); 49 | 50 | //4) Select budget min (8L) and max(12L) and Click Search 51 | driver.findElementByXPath("//ul[@id='minPriceList']/li[text()='8 Lakh']").click(); 52 | driver.findElementByXPath("//ul[@id='maxPriceList']/li[text()='12 Lakh']").click(); 53 | Thread.sleep(500); 54 | driver.findElementById("btnFindCar").click(); 55 | 56 | //5) Select Cars with Photos under Only Show Cars With 57 | WebDriverWait wait = new WebDriverWait(driver,30); 58 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByName("CarsWithPhotos"))); 59 | driver.findElementByName("CarsWithPhotos").click(); 60 | 61 | //6) Select Manufacturer as "Hyundai" --> Creta 62 | Thread.sleep(100); 63 | driver.findElementByXPath("//input[@placeholder='Select Manufacturer']").sendKeys("Hyundai"); 64 | Thread.sleep(200); 65 | driver.findElementByXPath("//li[@data-manufacture-en='Hyundai']").click(); 66 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Creta']"))); 67 | driver.findElementByXPath("//span[text()='Creta']").click(); 68 | 69 | //7) Select Fuel Type as Petrol 70 | JavascriptExecutor js = (JavascriptExecutor) driver; 71 | js.executeScript("window.scrollBy(0, 500)"); 72 | Thread.sleep(200); 73 | driver.findElementByXPath("//div[@name='fuel']/h3").click(); 74 | driver.findElementByXPath("//li[@name='Petrol']").click(); 75 | 76 | //8) Select Best Match as "KM: Low to High" 77 | Thread.sleep(2000); 78 | Select bestMatch = new Select(driver.findElementByXPath("//select[@id='sort']")); 79 | bestMatch.selectByVisibleText("KM: Low to High"); 80 | Thread.sleep(5000); 81 | 82 | //9) Validate the Cars are listed with KMs Low to High 83 | List list_kms = driver.findElementsByXPath("//span[@class='slkms vehicle-data__item']"); 84 | List kms_actualList = new ArrayList(); 85 | 86 | for (int i = 0; i < list_kms.size(); i++) { 87 | 88 | String text = list_kms.get(i).getText(); 89 | String replaceAll = text.replaceAll("[^0-9]", ""); 90 | int kms = Integer.parseInt(replaceAll); 91 | kms_actualList.add(kms); 92 | } 93 | 94 | List kms_sortedList = new ArrayList(kms_actualList); 95 | Collections.sort(kms_sortedList); 96 | 97 | if(kms_actualList==kms_sortedList) { 98 | System.out.println("The cars are displayed from Low to high Kms"); 99 | } 100 | else { 101 | System.out.println("The cars aren't displayed from Low to high Kms"); 102 | } 103 | 104 | //10) Add the least KM ran car to Wishlist 105 | int leastKmsDriven = kms_sortedList.get(0); 106 | 107 | for (int i = 0; i < kms_sortedList.size(); i++) { 108 | 109 | if(leastKmsDriven==kms_actualList.get(i)) { 110 | 111 | Thread.sleep(1000); 112 | WebElement leastPriceCar = driver.findElementByXPath("(//li[@class='listing-adv listingContent cur-pointer card-list-container']" 113 | + "//span[contains(@class,'shortlist-icon')])["+(i+1)+"]"); 114 | JavascriptExecutor executor = (JavascriptExecutor)driver; 115 | executor.executeScript("arguments[0].click();", leastPriceCar); 116 | //leastPriceCar.click(); 117 | break; 118 | } 119 | } 120 | 121 | //11) Go to Wishlist and Click on More Details 122 | try { 123 | driver.findElementByLinkText("Don't show anymore tips").click(); 124 | } catch (Exception e) { 125 | System.out.println("Exception is catched"); 126 | } 127 | Thread.sleep(2000); 128 | driver.findElementByXPath("//li[contains(@class,'action-box shortlistBtn')]").click(); 129 | Thread.sleep(200); 130 | Actions action = new Actions(driver); 131 | action.moveToElement(driver.findElementByXPath("//a[text()='More details »']")).click().build().perform(); 132 | Thread.sleep(500); 133 | 134 | Set windowHandles_set = driver.getWindowHandles(); 135 | List win_list = new ArrayList<>(windowHandles_set); 136 | driver.switchTo().window(win_list.get(1)); 137 | 138 | //12) Print all the details under Overview 139 | Thread.sleep(3000); 140 | try { 141 | driver.findElementByLinkText("Got it").click(); 142 | System.out.println("Clicked Got it in Try block"); 143 | } 144 | catch(Exception e) { 145 | System.out.println("Exception is catched"); 146 | } 147 | driver.findElementByXPath("//li[text()='Overview']").click(); 148 | 149 | List overview1 = driver.findElementsByXPath("//div[@id='overview']//li/div[@class='equal-width text-light-grey']"); 150 | List overview2 = driver.findElementsByXPath("//div[@id='overview']//li/div[@class='equal-width dark-text']"); 151 | 152 | Map overviewDetails = new LinkedHashMap(); 153 | 154 | for (int i = 0; i < overview1.size(); i++) { 155 | 156 | String key = overview1.get(i).getText(); 157 | String value = overview2.get(i).getText(); 158 | 159 | overviewDetails.put(key, value); 160 | } 161 | System.out.println("Overview Details are:"); 162 | for (Entry eachEntry : overviewDetails.entrySet()) { 163 | System.out.println(eachEntry.getKey()+" --> "+eachEntry.getValue()); 164 | } 165 | 166 | //13) Close the browser. 167 | driver.quit(); 168 | } 169 | 170 | } 171 | -------------------------------------------------------------------------------- /PepperFry.java: -------------------------------------------------------------------------------- 1 | package day8; 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.apache.commons.io.FilenameUtils; 9 | import org.openqa.selenium.By; 10 | import org.openqa.selenium.JavascriptExecutor; 11 | import org.openqa.selenium.Keys; 12 | import org.openqa.selenium.OutputType; 13 | import org.openqa.selenium.TakesScreenshot; 14 | import org.openqa.selenium.UnexpectedAlertBehaviour; 15 | import org.openqa.selenium.WebElement; 16 | import org.openqa.selenium.chrome.ChromeDriver; 17 | import org.openqa.selenium.chrome.ChromeOptions; 18 | import org.openqa.selenium.interactions.Actions; 19 | import org.openqa.selenium.remote.CapabilityType; 20 | import org.openqa.selenium.remote.DesiredCapabilities; 21 | import org.openqa.selenium.support.ui.ExpectedConditions; 22 | import org.openqa.selenium.support.ui.WebDriverWait; 23 | 24 | public class PepperFry { 25 | 26 | public static void main(String[] args) throws InterruptedException, IOException { 27 | 28 | // 1) Go to https://www.pepperfry.com/ 29 | System.setProperty("webdriver.chrome.silentOutput", "true"); 30 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 31 | ChromeOptions options = new ChromeOptions(); 32 | 33 | /*** To handle any intermittent pop-up ***/ 34 | DesiredCapabilities cap = new DesiredCapabilities(); 35 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 36 | options.merge(cap); 37 | 38 | options.addArguments("--disable-notifications"); 39 | ChromeDriver driver = new ChromeDriver(options); 40 | driver.get("https://www.pepperfry.com/"); 41 | driver.manage().window().maximize(); 42 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 43 | 44 | WebDriverWait wait = new WebDriverWait(driver,30); 45 | wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[@class='popup-close'])[5]"))); 46 | driver.findElementByXPath("(//a[@class='popup-close'])[5]").click(); 47 | 48 | // 2) Mouse over on Furniture and click Office Chairs under Chairs 49 | Actions action = new Actions(driver); 50 | action.moveToElement(driver.findElementByLinkText("Furniture")).build().perform(); 51 | Thread.sleep(100); 52 | driver.findElementByLinkText("Office Chairs").click(); 53 | 54 | // 3) click Executive Chairs 55 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//h5[text()='Executive Chairs']"))).click(); 56 | //driver.findElementByXPath("//h5[text()='Executive Chairs']").click(); 57 | 58 | // 4) Change the minimum Height as 50 in under Dimensions 59 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]"))).clear(); 60 | driver.findElementByXPath("(//input[@class='clipFilterDimensionHeightValue'])[1]").sendKeys("50", Keys.TAB); 61 | 62 | // 5) Add "Poise Executive Chair in Black Colour" chair to Wishlist 63 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[text()='Poise Executive Chair in Black Colour']"))); 64 | JavascriptExecutor js = (JavascriptExecutor)driver; 65 | js.executeScript("arguments[0].click();", 66 | driver.findElementByXPath("(//a[text()='Poise Executive Chair in Black Colour']/following::a[@id='clip_wishlist_'])[1]")); 67 | //driver.findElementByXPath("(//a[text()='Poise Executive Chair in Black Colour']/following::a[@id='clip_wishlist_'])[1]").click(); 68 | int wish_count = 0; 69 | wish_count++; 70 | System.err.println("wish count1 "+wish_count); 71 | 72 | // 6) Mouseover on Homeware and Click Pressure Cookers under Cookware 73 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByLinkText("Homeware"))); 74 | Actions action1 = new Actions(driver); 75 | action1.moveToElement(driver.findElementByLinkText("Homeware")).build().perform(); 76 | Thread.sleep(1000); 77 | driver.findElementByXPath("//a[text()='Pressure Cookers']").click(); 78 | Thread.sleep(2000); 79 | 80 | // 7) Select Prestige as Brand 81 | wait.until(ExpectedConditions.elementToBeClickable 82 | (driver.findElementByXPath("//input[@id='brandsnamePrestige']/following::label[text()='Prestige']"))) 83 | .click(); 84 | Thread.sleep(2000); 85 | 86 | // 8) Select Capacity as 1-3 Ltr 87 | wait.until(ExpectedConditions.elementToBeClickable 88 | (driver.findElementByXPath("//input[@id='brandsnamePrestige']/following::label[text()='1 Ltr - 3 Ltr']"))) 89 | .click(); 90 | 91 | // 9) Add "Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr" to Wishlist 92 | Thread.sleep(2000); 93 | wait.until(ExpectedConditions.elementToBeClickable 94 | (driver.findElementByXPath("//a[text()='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']//following::div[3]/a"))) 95 | .click(); 96 | wish_count++; 97 | System.err.println("wish count2 "+wish_count); 98 | 99 | // 10) Verify the number of items in Wishlist 100 | Thread.sleep(2000); 101 | int wishcount = Integer.parseInt(driver.findElementByXPath("//div[@class='wishlist_bar']//span").getText()); 102 | 103 | if(wish_count == wishcount) { 104 | System.out.println("verified wish count as : "+wishcount); 105 | } 106 | else { 107 | System.out.println("Wish count is not matched"); 108 | } 109 | 110 | // 11) Navigate to Wishlist 111 | driver.findElementByXPath("//div[@class='wishlist_bar']/a").click(); 112 | 113 | // 12) Move Pressure Cooker only to Cart from Wishlist 114 | Thread.sleep(2000); 115 | driver.findElementByXPath 116 | ("//a[text()='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr By...']//following::a[text()='Add to Cart']") 117 | .click(); 118 | 119 | // 13) Check for the availability for Pincode 600128 120 | Thread.sleep(2000); 121 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//input[@class='srvc_pin_text']"))).clear(); 122 | driver.findElementByXPath("//input[@class='srvc_pin_text']").sendKeys("600128"); 123 | 124 | driver.findElementByXPath("//a[text()='Check']").click(); 125 | 126 | // 14) Click Proceed to Pay Securely 127 | Thread.sleep(500); 128 | driver.findElementByXPath("//a[contains(text(),'Proceed to pay securely')]").click(); 129 | 130 | // 15 Click Proceed to Pay 131 | Thread.sleep(500); 132 | wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[text()='PLACE ORDER'])[1]"))).click(); 133 | 134 | // 16) Capture the screenshot of the item under Order Item 135 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementById("ordersummary_accordian_header"))).click(); 136 | Thread.sleep(1000); 137 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//li[@class='onepge_ordersummary slick-slide slick-current slick-active']/figure"))); 138 | 139 | WebElement orderSummary = driver.findElementByXPath("//li[@class='onepge_ordersummary slick-slide slick-current slick-active']/figure"); 140 | File srcFile = orderSummary.getScreenshotAs(OutputType.FILE); 141 | File destFile = new File("./ScreenShots/pepperFry_orders.png"); 142 | FileUtils.copyFile(srcFile, destFile); 143 | 144 | Thread.sleep(500); 145 | 146 | // 17) Close the browser 147 | driver.manage().deleteAllCookies(); 148 | driver.quit(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Honda.java: -------------------------------------------------------------------------------- 1 | package day7; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.NoSuchElementException; 6 | import java.util.Set; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.openqa.selenium.By; 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.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 | 20 | public static void main(String[] args) throws InterruptedException { 21 | 22 | // 1) Go to https://www.honda2wheelersindia.com/ 23 | System.setProperty("webdriver.chrome.silentOutput", "true"); 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 25 | ChromeOptions options = new ChromeOptions(); 26 | options.addArguments("--disable-notifications"); 27 | ChromeDriver driver = new ChromeDriver(options); 28 | driver.get("https://www.honda2wheelersindia.com/"); 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); 31 | 32 | /* 33 | * Adding Try catch block for handling 34 | * intermittent pop-up 35 | */ 36 | WebDriverWait wait = new WebDriverWait(driver,30); 37 | try { 38 | driver.findElementByXPath("//button[@class='close']").click(); 39 | } catch (NoSuchElementException e) { 40 | System.out.println("No such pop-up is present in the home page"); 41 | } 42 | // 2) Click on scooters and click dio 43 | driver.findElementByLinkText("Scooter").click(); 44 | Thread.sleep(500); 45 | driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']/parent::a").click(); 46 | 47 | // 3) Click on Specifications and mouseover on ENGINE 48 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Specifications"))).click(); 49 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByLinkText("ENGINE"))); 50 | Actions action = new Actions(driver); 51 | action.moveToElement(driver.findElementByLinkText("ENGINE")).build().perform(); 52 | 53 | // 4) Get Displacement value 54 | String field_name_dio = driver.findElementByXPath("//div[@class='engine part-2 axx']//li[3]/span[1]").getText(); 55 | String field_value_dio = driver.findElementByXPath("//div[@class='engine part-2 axx']//li[3]/span[2]").getText(); 56 | //String field_value_dio1 = field_name_dio.replaceAll("c", ""); 57 | float dio_displacement = Float.parseFloat(field_value_dio.replaceAll("c","")); 58 | System.out.println("The "+field_name_dio+" value of dio scooter is = "+field_value_dio); 59 | 60 | // 5) Go to Scooters and click Activa 125 61 | driver.findElementByLinkText("Scooter").click(); 62 | driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']/parent::a").click(); 63 | 64 | // 6) Click on Specifications and mouseover on ENGINE 65 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Specifications"))).click(); 66 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByLinkText("ENGINE"))); 67 | Actions action2 = new Actions(driver); 68 | action2.moveToElement(driver.findElementByLinkText("ENGINE")).build().perform(); 69 | 70 | // 7) Get Displacement value 71 | String field_name_activa = driver.findElementByXPath("//div[@class='engine part-4 axx']//li[3]/span[1]").getText(); 72 | String field_value_activa = driver.findElementByXPath("//div[@class='engine part-4 axx']//li[3]/span[2]").getText(); 73 | //String field_value_activa1 = field_value_activa.replaceAll("c", ""); 74 | float activa_displacement = Float.parseFloat(field_value_activa.replaceAll("c","")); 75 | System.out.println("The "+field_name_activa+" value of Activa scooter is = "+field_value_activa); 76 | 77 | // 8) Compare Displacement of Dio and Activa 125 and print the Scooter name having better Displacement. 78 | if(activa_displacement>dio_displacement) { 79 | System.out.println("Activa 125 have better displacement than dio"); 80 | } 81 | else if(activa_displacement windowHandles_set = driver.getWindowHandles(); 115 | List windowHandles_list = new ArrayList<>(windowHandles_set); 116 | driver.switchTo().window(windowHandles_list.get(1)); 117 | 118 | Select stateSelection = new Select(driver.findElementById("StateID")); 119 | Select citySelection = new Select(driver.findElementById("CityID")); 120 | 121 | stateSelection.selectByVisibleText("Tamil Nadu"); 122 | Thread.sleep(500); 123 | citySelection.selectByVisibleText("Chennai"); 124 | 125 | // 15) Click Search 126 | driver.findElementByXPath("//button[text()='Search']").click(); 127 | 128 | // 16) Print all the 3 models and their prices 129 | /* First row has 3 cells, Hence taking values from Cell2 and Cell3 130 | * remaining rows has only 2 cells for model and Price 131 | * */ 132 | WebElement table = driver.findElementByXPath("//table[@id='gvshow']/tbody"); 133 | List rows = table.findElements(By.tagName("tr")); 134 | for (int i = 0; i < rows.size(); i++) { 135 | String model, price; 136 | List cell = rows.get(i).findElements(By.tagName("td")); 137 | if(i==0) { 138 | model = cell.get(1).getText(); 139 | price = cell.get(2).getText(); 140 | } 141 | else { 142 | model = cell.get(0).getText(); 143 | price = cell.get(1).getText(); 144 | } 145 | System.out.println("Model -> "+model+" Price -> "+price); 146 | } 147 | 148 | // 17) Close the Browser 149 | driver.quit(); 150 | 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /Shiksha.java: -------------------------------------------------------------------------------- 1 | package day13; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.JavascriptExecutor; 7 | import org.openqa.selenium.UnexpectedAlertBehaviour; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.interactions.Actions; 12 | import org.openqa.selenium.remote.CapabilityType; 13 | import org.openqa.selenium.remote.DesiredCapabilities; 14 | import org.openqa.selenium.support.ui.Select; 15 | 16 | public class Shiksha { 17 | 18 | public static void main(String[] args) throws InterruptedException { 19 | 20 | // 1) Go to https://studyabroad.shiksha.com/ 21 | System.setProperty("webdriver.chrome.silentOutput", "true"); 22 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 23 | ChromeOptions options = new ChromeOptions(); 24 | options.addArguments("--disable-notifications"); 25 | 26 | DesiredCapabilities cap = new DesiredCapabilities(); 27 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 28 | options.merge(cap); 29 | 30 | ChromeDriver driver = new ChromeDriver(options); 31 | driver.get("https://studyabroad.shiksha.com/"); 32 | driver.manage().window().maximize(); 33 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 34 | 35 | // 2) Mouse over on Colleges and click MS in Computer Science &Engg under MS Colleges 36 | Actions action = new Actions(driver); 37 | action.moveToElement(driver.findElementByXPath("//label[@for='sm3' and text()='Colleges ']")).build().perform(); 38 | 39 | driver.findElementByLinkText("MS in Computer Science &Engg").click(); 40 | 41 | // 3) Select GRE under Exam Accepted and Score 300 & Below 42 | driver.findElementByXPath("//p[text()='GRE']/preceding-sibling::span").click(); 43 | Thread.sleep(500); 44 | Select score = new Select(driver.findElementByXPath("//li[@class='labelInputs active']//select[@class='score-select-field']")); 45 | score.selectByVisibleText("300 & below"); 46 | Thread.sleep(1000); 47 | 48 | // 4) Max 10 Lakhs under 1st year Total fees, USA under countries 49 | driver.findElementByXPath("//p[text()='Max 10 Lakhs']/preceding-sibling::span").click(); 50 | Thread.sleep(500); 51 | 52 | // 5) Select Sort By: Low to high 1st year total fees 53 | Select sortBy = new Select(driver.findElementById("categorySorter")); 54 | sortBy.selectByVisibleText("Low to high 1st year total fees"); 55 | Thread.sleep(2000); 56 | 57 | // 6) Click Add to compare of the College having least fees with Public University, Scholarship and Accomadation facilities 58 | try { 59 | driver.findElementByXPath("//div[@class='cokkie-box']//a[text()='OK']").click(); 60 | System.out.println("Accepted Cookies"); 61 | } catch (Exception e) { 62 | System.out.println("catched exception"); 63 | } 64 | 65 | /*List facilityList = driver.findElementsByXPath("(//div[@class='uni-course-details flLt']/div[3]//span)"); 66 | for (int i = 1; i <= facilityList.size(); i=(i+3)) { 67 | 68 | String tick1 = driver.findElementByXPath("(//div[@class='uni-course-details flLt']/div[3]//span)["+i+"]").getText(); 69 | String tick2 = driver.findElementByXPath("(//div[@class='uni-course-details flLt']/div[3]//span)["+(i+1)+"]").getText(); 70 | String tick3 = driver.findElementByXPath("(//div[@class='uni-course-details flLt']/div[3]//span)["+(i+2)+"]").getText(); 71 | //String tick1 = driver.findElementByXPath("(//div[@class='uni-course-details flLt']/div[3]//span)["+(i+3)+"]").getText(); 72 | if(tick1.equals("✔") && tick2.equals("✔") && tick3.equals("✔")) { 73 | 74 | System.out.println("3 facilities are ticked "); 75 | 76 | List eleAdd = driver.findElementsByXPath("//p[text()='Add to compare']/preceding-sibling::span"); 77 | WebElement eleAddtoCompare = eleAdd.get(i-1); 78 | JavascriptExecutor js = (JavascriptExecutor)driver; 79 | js.executeScript("arguments[0].click();", eleAddtoCompare); 80 | //driver.findElementByXPath("(//p[text()='Add to compare']/preceding-sibling::span)["+i+"]").click(); 81 | } 82 | else { 83 | System.out.println("All 3 facilities are not ticked"); 84 | } 85 | }*/ 86 | 87 | List eleUniv = driver.findElementsByXPath("//p[text()='Public university']/span"); 88 | System.out.println("university size is "+eleUniv.size()); 89 | List eleScholar = driver.findElementsByXPath("//p[text()='Scholarship']/span"); 90 | System.out.println("Scholarship size is "+eleScholar.size()); 91 | List eleAccomodation = driver.findElementsByXPath("//p[text()='Accommodation']/span"); 92 | System.out.println("Accomodation size is "+eleAccomodation.size()); 93 | for(int i=0; i eleAdd = driver.findElementsByXPath("//p[contains(text(),'compare')]/preceding-sibling::span"); 96 | Thread.sleep(2000); 97 | WebElement eleAddtoCompare = eleAdd.get(i); 98 | JavascriptExecutor js = (JavascriptExecutor)driver; 99 | js.executeScript("arguments[0].click();", eleAddtoCompare); 100 | } 101 | } 102 | 103 | // 7) Select the first college under Compare with similar colleges 104 | 105 | // 8) Click on Compare College> 106 | Thread.sleep(2000); 107 | driver.findElementByXPath("//div[@class='compare-col flLt']/a[contains(@class,'button')]").click(); 108 | 109 | // 9) Select When to Study as 2021 110 | Thread.sleep(3000); 111 | driver.findElementByXPath("(//strong[text()='2021']/preceding::span)[10]").click(); 112 | Thread.sleep(500); 113 | 114 | // 10) Select Preferred Countries as USA 115 | driver.findElementByXPath("//div[text()='Preferred Countries']/following-sibling::div").click(); 116 | Thread.sleep(200); 117 | driver.findElementByXPath("//li[@class='ctry-row']//label[contains(@for,'USA')]/span").click(); 118 | 119 | // 11) Select Level of Study as Masters 120 | Thread.sleep(200); 121 | driver.findElementByXPath("//label[contains(@for,'Masters')]/span").click(); 122 | 123 | // 12) Select Preferred Course as MS 124 | Thread.sleep(200); 125 | driver.findElementByXPath("//div[text()='Preferred Course']/following-sibling::div").click(); 126 | Thread.sleep(200); 127 | driver.findElementByXPath("//div[@class='city-lr prefCourse']//li[text()='MS']").click(); 128 | 129 | // 13) Select Specialization as "Computer Science & Engineering" 130 | Thread.sleep(500); 131 | driver.findElementByXPath("//div[text()='Preferred Specialisations']/following-sibling::div").click(); 132 | driver.findElementByXPath("//li[text()='Computer Science & Engineering']").click(); 133 | 134 | // 14) Click on Sign Up 135 | WebElement signUp = driver.findElementById("signup"); 136 | JavascriptExecutor js = (JavascriptExecutor)driver; 137 | js.executeScript("arguments[0].click();", signUp); 138 | 139 | // 15) Print all the warning messages displayed on the screen for missed mandatory fields 140 | List warningMsg = driver.findElementsByXPath("//div[@class='helper-text' and contains(text(),'Please')]"); 141 | 142 | for (WebElement warning : warningMsg) { 143 | 144 | String warningText = warning.getText(); 145 | System.out.println("The warning messages are :: "+warningText); 146 | } 147 | 148 | // 14) Close the Browser 149 | driver.quit(); 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /Ajio.java: -------------------------------------------------------------------------------- 1 | package day16.evaluation1; 2 | 3 | import static org.testng.Assert.expectThrows; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import org.openqa.selenium.By; 11 | import org.openqa.selenium.JavascriptExecutor; 12 | import org.openqa.selenium.Keys; 13 | import org.openqa.selenium.UnexpectedAlertBehaviour; 14 | import org.openqa.selenium.WebElement; 15 | import org.openqa.selenium.chrome.ChromeDriver; 16 | import org.openqa.selenium.chrome.ChromeOptions; 17 | import org.openqa.selenium.remote.CapabilityType; 18 | import org.openqa.selenium.remote.DesiredCapabilities; 19 | import org.openqa.selenium.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.Select; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | 23 | public class Ajio { 24 | 25 | public static void main(String[] args) throws InterruptedException { 26 | 27 | // 1)Go to https://www.ajio.com/ 28 | System.setProperty("webdriver.chrome.silentOutput", "true"); 29 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 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 | ChromeDriver driver = new ChromeDriver(options); 38 | driver.get("https://www.ajio.com/shop/sale"); 39 | driver.manage().window().maximize(); 40 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 41 | 42 | try { 43 | driver.findElementByXPath("//div[@class='ic-close-quickview']").click(); 44 | System.out.println("closed quick view pop-up"); 45 | } catch (Exception e) { 46 | System.out.println("exception catched"); 47 | } 48 | 49 | // 2) Enter Bags in the Search field and Select Bags in Women Handbags 50 | driver.findElementByXPath("//input[@placeholder='Search AJIO']").sendKeys("Bags", Keys.ENTER); 51 | driver.findElementByXPath("//label[@for='Women']").click(); 52 | Thread.sleep(500); 53 | JavascriptExecutor js = (JavascriptExecutor)driver; 54 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//label[@for='Women - Handbags']")); 55 | //driver.findElementByXPath("//label[@for='Women - Handbags']").click(); 56 | //driver.findElementByXPath("(//span[text()='Women Handbags'])[1]").click(); 57 | Thread.sleep(1000); 58 | // 3) Click on five grid and Select SORT BY as "What's New" 59 | driver.findElementByXPath("//div[@class='five-grid']").click(); 60 | Select sortBy = new Select(driver.findElementByXPath("//div[@class='filter-dropdown']/select")); 61 | sortBy.selectByVisibleText("What's New"); 62 | 63 | // 4) Enter Price Range Min as 2000 and Max as 5000 64 | driver.findElementByXPath("//span[text()='price']").click(); 65 | driver.findElementById("minPrice").sendKeys("2000"); 66 | driver.findElementById("maxPrice").sendKeys("5000", Keys.ENTER); 67 | //driver.findElementByXPath("//button[@class='rilrtl-button ic-toparw']").click(); 68 | Thread.sleep(500); 69 | 70 | // 5) Click on thefive-gridproduct "Puma Ferrari LS Shoulder Bag" 71 | WebDriverWait wait = new WebDriverWait(driver,30); 72 | // wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[text()='Ferrari LS Shoulder Bag']/parent::div"))); 73 | WebElement elePuma = driver.findElementByXPath("//div[text()='Ferrari LS Shoulder Bag']/parent::div"); 74 | js.executeScript("arguments[0].scrollIntoView(true);",elePuma); 75 | js.executeScript("arguments[0].click();", elePuma); 76 | Thread.sleep(1000); 77 | 78 | Set windowHandles_set = driver.getWindowHandles(); 79 | List win_list = new ArrayList(windowHandles_set); 80 | driver.switchTo().window(win_list.get(1)); 81 | 82 | // 6) Verify the Coupon code for the price above 2690 is applicable for your product, if applicable the get the Coupon Code and Calculate the discount price for the coupon 83 | 84 | /*** get the MRP to validate the coupon availability ***/ 85 | String pdtMrp = driver.findElementByXPath("//div[@class='prod-sp']").getText().replaceAll("[^0-9]", ""); 86 | int mrp = Integer.parseInt(pdtMrp); 87 | String coupCode = ""; 88 | //Double mrp = Double.parseDouble(pdtMrp); 89 | if (mrp>=2690) { 90 | System.out.println("Coupon is applicable"); 91 | coupCode = driver.findElementByXPath("//div[@class='promo-title']").getText().replaceAll("\n", ""); 92 | String couponCode = coupCode.substring(8); 93 | System.out.println("Actual Coupon code is - "+couponCode); 94 | } else { 95 | System.out.println("Coupon is not applicable"); 96 | } 97 | 98 | String discountText = driver.findElementByXPath("//div[@class='promo-discounted-price']/span").getText().replaceAll("[^0-9]", ""); 99 | double discountPrice = Double.parseDouble(discountText); 100 | int discountApplied = (int) (mrp-discountPrice); 101 | System.out.println("The Discounted amount is :: "+discountApplied); 102 | 103 | // 7) Check the availability of the product for pincode 560043, print the expected delivery date if it is available 104 | driver.findElementByXPath("//span[contains(text(),'Enter pin-code')]").click(); 105 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByName("pincode"))); 106 | driver.findElementByName("pincode").sendKeys("560043",Keys.ENTER); 107 | 108 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[contains(@class,'edd-pincode-msg-details')]"))); 109 | String msgDeliverytext = driver.findElementByXPath("//div[contains(@class,'edd-pincode-msg-details')]").getText(); 110 | System.out.println(msgDeliverytext); 111 | 112 | // 8) Click on Other Informations under Product Details and Print the Customer Care address, phone and email 113 | driver.findElementByClassName("other-info-toggle").click(); 114 | Thread.sleep(500); 115 | 116 | String cusCareText = driver.findElementByXPath("//span[text()='Customer Care Address']").getText(); 117 | String cusCareDetails = driver.findElementByXPath("//span[text()='Customer Care Address']//following-sibling::span[@class='other-info']").getText(); 118 | System.out.println(cusCareText+" --> "+cusCareDetails); 119 | 120 | // 9) Click on ADD TO BAG and then GO TO BAG 121 | driver.findElementByXPath("//span[text()='ADD TO BAG']").click(); 122 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='GO TO BAG']"))).click(); 123 | 124 | // 10) Check the Order Total before apply coupon 125 | String orderTotal = driver.findElementByXPath("(//section[@id='orderTotal']/span)[2]").getText().replaceAll("[^0-9]", ""); 126 | Double orderTotAmt = Double.parseDouble(orderTotal); 127 | 128 | if (orderTotAmt==mrp) { 129 | System.out.println("order total is validated"); 130 | } else { 131 | System.out.println("order total differs in cart"); 132 | } 133 | 134 | // 11) Enter Coup.on Code and Click Apply 135 | driver.findElement(By.id("couponCodeInput")).sendKeys(coupCode); 136 | driver.findElementByXPath("//button[text()='Apply']").click(); 137 | 138 | 139 | // 12) Verify the Coupon Savings amount(round off if it in decimal) under Order Summary and the matches the amount calculated in Product details 140 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//span[@class='price-value discount-price'])[2]"))); 141 | String couponSaveAmount = driver.findElementByXPath("(//span[@class='price-value discount-price'])[2]").getText().replaceAll("[^0-9.]", ""); 142 | double couponSave = Double.parseDouble(couponSaveAmount); 143 | int couponSaveRound = (int) Math.round(couponSave); 144 | if (couponSaveRound==discountApplied) { 145 | System.out.println("The discount Amount Matches"); 146 | } else { 147 | System.out.println("The discounted Amount differs"); 148 | } 149 | 150 | // 13) Click on Delete and Delete the item from Bag 151 | driver.findElementByXPath("//div[@class='delete-btn']").click(); 152 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[text()='DELETE']"))).click(); 153 | 154 | // 14) Close all the browsers 155 | driver.quit(); 156 | 157 | 158 | } 159 | 160 | } 161 | --------------------------------------------------------------------------------