├── README.md ├── day11Snapdeal.java ├── day12carwale.java ├── day13shiksha.java ├── day14zalando.java ├── day15airbnb.java ├── day16ajio.java ├── day17azure.java ├── day1myntra.java ├── day2Nykaa.java ├── day3makemytrip.java ├── day4hp.java ├── day6BigBasket.java ├── day7scooter.java └── day8pepperfry.java /README.md: -------------------------------------------------------------------------------- 1 | # Learnings -------------------------------------------------------------------------------- /day11Snapdeal.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 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.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 day11Snapdeal { 17 | 18 | public ChromeDriver driver; 19 | public WebDriverWait wait; 20 | public int prodPrice; 21 | public int delCharge; 22 | 23 | public int validatecart(int cartPriceEachProduct,String productName) 24 | { 25 | driver.findElementByXPath("(//div[@id='add-cart-button-id']/span)[1]").click(); 26 | //wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@class='you-pay']/span"))); 27 | int youPay=Integer.parseInt(driver.findElementByXPath("//div[@class='you-pay']/span").getText().replaceAll("\\D", "")); 28 | if(youPay==cartPriceEachProduct) 29 | {System.out.println("The cart price and product price is validated for" +productName);} 30 | 31 | else{System.out.println("The cart price didnt match the total product price");} 32 | driver.findElementByXPath("//span[@class='sd-icon sd-icon-delete-sign close-mess']"); 33 | return youPay; 34 | } 35 | 36 | public int price() { 37 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//span[@class='payBlkBig']"))); 38 | int prodPrice=Integer.parseInt(driver.findElementByXPath("//span[@class='payBlkBig']").getText()); 39 | System.out.println("The prodPrice is" +prodPrice); 40 | int delCharge=Integer.parseInt(driver.findElementByXPath("(//span[@class='head' and contains(text(),'Delivery in')]/following::span[@class='availCharges'])[2]").getText().replaceAll("\\D", "")); 41 | System.out.println("The delPrice is" +delCharge); 42 | return prodPrice+delCharge; 43 | } 44 | 45 | @Test 46 | public void snapdeal() throws InterruptedException 47 | { 48 | //Go to https://www.snapdeal.com/ 49 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 50 | 51 | ChromeOptions option =new ChromeOptions(); 52 | option.addArguments("--disable-notifications"); 53 | driver=new ChromeDriver(option); 54 | Actions action=new Actions(driver); 55 | wait=new WebDriverWait(driver,30); 56 | 57 | driver.get("https://www.snapdeal.com/"); 58 | driver.manage().window().maximize(); 59 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 60 | 61 | //Mouse over on Toys, Kids' Fashion & more and click on Toys 62 | action.moveToElement(driver.findElementByXPath("//span[contains(text(),\"Toys, Kids' Fashion & more\")]")).perform(); 63 | driver.findElementByXPath("//span[@class='headingText' and contains(text(),'Toys')]").click(); 64 | 65 | //Click Educational Toys in Toys & Games 66 | driver.findElementByXPath("//div[@class='sub-cat-name ' and contains(text(),'Educational Toys')]").click(); 67 | 68 | //Click the Customer Rating 4 star and Up 69 | Thread.sleep(3000); 70 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//label[@for='avgRating-4.0']"))); 71 | driver.findElementByXPath("//label[@for='avgRating-4.0']").click(); 72 | 73 | //Click the offer as 40-50 74 | Thread.sleep(3000); 75 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//label[@for='discount-40%20-%2050']"))); 76 | driver.findElementByXPath("//label[@for='discount-40%20-%2050']").click(); 77 | 78 | //filter validation 79 | if(driver.findElementByXPath("(//div[text()='Discount %: ']/a[text()='40 - 50'])[1]").isDisplayed() & driver.findElementByXPath("(//div[text()='Customer Rating: ']/a[text()='4.0'])[1]").isDisplayed()) 80 | { 81 | System.out.println("The rating and discount filter is applied successfully"); 82 | } 83 | else 84 | { 85 | System.out.println("The filter is not applied"); 86 | } 87 | 88 | //Check the availability for the pincode 89 | driver.findElementByXPath("//input[@placeholder='Enter your pincode']").sendKeys("600012"); 90 | Thread.sleep(2000); 91 | action.moveToElement(driver.findElementByXPath("//button[text()='Check']")).click().build().perform(); 92 | wait.until(ExpectedConditions.visibilityOf((driver.findElementByXPath("//input[@checked='checked']/following-sibling::label[1]")))); 93 | if (driver.findElementByXPath("//input[@checked='checked']/following-sibling::label[1]").isDisplayed()) 94 | { 95 | System.out.println("The deliver option is available to the given pincode"); 96 | } 97 | 98 | else 99 | { 100 | System.out.println("The delivery option is not available for given pincode"); 101 | } 102 | 103 | //Click the Quick View of the first product 104 | String productName=driver.findElementByXPath("(//p[@class='product-title'])[1]").getText(); 105 | Thread.sleep(3000); 106 | action.moveToElement(driver.findElementByXPath("(//picture[@class='picture-elem'])[1]")).pause(3000).perform(); 107 | driver.findElementByXPath("(//picture[@class='picture-elem'])[1]/following::div[contains(text(),'Quick View')][1]").click(); 108 | 109 | //Click on View Details 110 | Thread.sleep(3000); 111 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//a[contains(@class,'btn btn-theme-secondary')])[1]"))); 112 | action.moveToElement(driver.findElementByXPath("(//a[contains(@class,'btn btn-theme-secondary')])[1]")).click().build().perform(); 113 | Thread.sleep(3000); 114 | 115 | //Capture the Price of the Product and Delivery Charge 116 | int cartPriceFirstProduct = price(); 117 | 118 | //Add to cart 119 | int youPayFirstProduct = validatecart(cartPriceFirstProduct,productName); 120 | 121 | //Search for Sanitizer 122 | driver.findElementById("inputValEnter").sendKeys("Sanitizer",Keys.ENTER); 123 | 124 | //Click on Product "BioAyurveda Neem Power Hand Sanitizer" 125 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//p[text()='BioAyurveda Neem Power Hand Sanitizer 500 mL Pack of 1'])[1]"))); 126 | action.moveToElement(driver.findElementByXPath("(//p[text()='BioAyurveda Neem Power Hand Sanitizer 500 mL Pack of 1'])[1]")).click().build().perform(); 127 | 128 | //Capture the Price and Delivery Charge 129 | Set windowHandles = driver.getWindowHandles(); List 130 | windows=new ArrayList (windowHandles); 131 | System.out.println(windows.size()); 132 | driver.switchTo().window(windows.get(windows.size()-1)); 133 | int cartPriceSecondProduct=price(); 134 | 135 | //Click on Add to Cart 136 | driver.findElementByXPath("(//div[@id='add-cart-button-id']/span)[1]").click(); 137 | 138 | //Click on Cart 139 | Thread.sleep(3000); 140 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByClassName("cartTextSpan"))); 141 | driver.findElementByClassName("cartTextSpan").click(); 142 | 143 | //Validate the Proceed to Pay matches the total amount of both the products 144 | 145 | int carttotalAmt = Integer.parseInt(driver.findElementByXPath("//input[contains(@value,'PROCEED TO PAY')]").getAttribute("value").replaceAll("\\D", "")); 146 | 147 | if(carttotalAmt==youPayFirstProduct+cartPriceSecondProduct) 148 | 149 | { 150 | System.out.println("The TotalCart Amount is " +carttotalAmt); 151 | } 152 | 153 | else 154 | { 155 | System.out.println("There is mismatch in cart Amount"); 156 | } 157 | 158 | driver.quit(); 159 | 160 | 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /day12carwale.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 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.TreeMap; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | import org.openqa.selenium.JavascriptExecutor; 14 | import org.openqa.selenium.Keys; 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.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.Select; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | import org.testng.annotations.Test; 23 | 24 | public class day12carwale { 25 | 26 | 27 | @Test 28 | public void carwale() throws InterruptedException 29 | { 30 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 31 | ChromeOptions option=new ChromeOptions(); 32 | option.addArguments("--disable-notifications"); 33 | 34 | ChromeDriver driver=new ChromeDriver(option); 35 | WebDriverWait wait=new WebDriverWait(driver,30); 36 | Actions action=new Actions(driver); 37 | JavascriptExecutor js = (JavascriptExecutor) driver; 38 | 39 | 40 | driver.manage().window().maximize(); 41 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 42 | 43 | driver.get("https://www.carwale.com/"); 44 | 45 | //Click on Used 46 | driver.findElementByXPath("//li[@data-tabs='usedCars']").click(); 47 | 48 | //Select the City as Chennai 49 | wait.until(ExpectedConditions.visibilityOf(driver.findElementById("budgetBtn"))); 50 | driver.findElementById("usedCarsList").sendKeys("Chennai"); 51 | Thread.sleep(3000); 52 | driver.findElementById("usedCarsList").sendKeys(Keys.ARROW_DOWN,Keys.TAB); 53 | 54 | //Select budget min (8L) and max(12L) and Click Search 55 | wait.until(ExpectedConditions.visibilityOf(driver.findElementById("minInput"))); 56 | driver.findElementById("minInput").sendKeys("8",Keys.TAB); 57 | driver.findElementById("maxInput").sendKeys("12",Keys.TAB); 58 | 59 | driver.findElementById("btnFindCar").click(); 60 | 61 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//p[text()='Filters']"))); 62 | if(driver.findElementByXPath("//p[text()='Filters']").isDisplayed()) 63 | { 64 | driver.findElementByXPath("(//a[text()=\"Don't show anymore tips\"])[1]").click(); 65 | } 66 | 67 | //Select Cars with Photos under Only Show Cars With 68 | driver.findElementByXPath("//span[text()='Cars with Photos']").click(); 69 | 70 | //Select Manufacturer as "Hyundai" --> Creta 71 | 72 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//ul[@id='makesList']//span[text()=' Hyundai ']")); 73 | Thread.sleep(3000); 74 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//span[@class='model-txt' and text()='Creta']")); 75 | 76 | if((driver.findElementByXPath("//span[@class='makeModel filter-parameters' and contains(text(),'Creta')]").isDisplayed() & driver.findElementByXPath("//span[@class='close-icon filter-parameters' and contains(text(),'Cars with Photos')]").isDisplayed())); 77 | { 78 | System.out.println("The Creta and Cars with photos filter is applied successfully"); 79 | } 80 | 81 | //Select Fuel Type as Petrol 82 | js.executeScript("arguments[0].click();",driver.findElementByXPath("//li[@class='us-sprite']/span[text()='Petrol']")); 83 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//span[@parentfiltername='fuel']"))); 84 | 85 | //Select Best Match as "KM: Low to High" 86 | Select dropdown=new Select(driver.findElementById("sort")); 87 | dropdown.selectByVisibleText("KM: Low to High"); 88 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[@data-carname-id='carname']/following::span[@class='slkms vehicle-data__item']"))); 89 | 90 | //Validate the Cars are listed with KMs Low to High 91 | List kmlist = driver.findElementsByXPath("//span[@data-carname-id='carname']/following::span[@class='slkms vehicle-data__item']"); 92 | 93 | //Map to put string and int km 94 | Map map=new TreeMap(); 95 | 96 | // int km after sorting 97 | List intKmList=new ArrayList(); 98 | 99 | //int km without sorting 100 | List originalKmListint=new ArrayList(); 101 | 102 | for (WebElement eachcarkm : kmlist) { 103 | 104 | String orginalKm=eachcarkm.getText(); 105 | int eachCarkm=Integer.parseInt(eachcarkm.getText().replaceAll("\\D", "")); 106 | intKmList.add(eachCarkm); 107 | originalKmListint.add(eachCarkm); 108 | map.put(eachCarkm, orginalKm); 109 | 110 | } 111 | 112 | Collections.sort(intKmList); 113 | //comparing sorted list and original list 114 | if (intKmList.equals(originalKmListint)) 115 | { 116 | System.out.println("All the cars are sorted based on km"); 117 | } 118 | 119 | else 120 | { 121 | System.out.println("Sorting has issue"); 122 | } 123 | 124 | // To get least KM from MAP// Since using TreeMap data will be inserted in ASCII order 125 | String leastStringData = (String) map.values().toArray()[0]; 126 | System.out.println("The least Km is" +leastStringData); 127 | 128 | 129 | //Add the least KM ran car to Wishlist 130 | 131 | String LeastCarName=driver.findElementByXPath("//span[@class='slkms vehicle-data__item' and contains(text(),'"+leastStringData+"')]/preceding::span[@data-carname-id='carname']").getText(); 132 | System.out.println("The Car with least KM is" +LeastCarName); 133 | driver.findElementByXPath("//span[@class='slkms vehicle-data__item' and contains(text(),'30,000')]/preceding::span[@class='shortlist-icon--inactive shortlist']").click(); 134 | 135 | //Go to Wishlist and Click on More Details 136 | driver.findElementByXPath("//li[@class='action-box shortlistBtn']/span").click(); 137 | 138 | //Go to Wishlist and Click on More Details 139 | Thread.sleep(2000); 140 | driver.findElementByXPath("//a[contains(text(),'More details')]").click(); 141 | 142 | //Print all the details under Overview 143 | Set windowHandles = driver.getWindowHandles(); 144 | List listwin=new ArrayList (windowHandles); 145 | driver.switchTo().window(listwin.get(1)); 146 | 147 | Map mapdetails=new LinkedHashMap(); 148 | List overView = driver.findElementsByXPath("//div[@id='overview']//div[@class='equal-width text-light-grey']"); 149 | List features = driver.findElementsByXPath("//div[@id='overview']//div[@class='equal-width dark-text']"); 150 | 151 | for (int i=0;i<=overView.size()-1;i++) { 152 | 153 | mapdetails.put(overView.get(i).getText(),features.get(i).getText()); 154 | } 155 | for (Entry eachmapdata : mapdetails.entrySet()) { 156 | System.out.println(eachmapdata.getKey()+"---"+eachmapdata.getValue()); 157 | } 158 | 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /day13shiksha.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.JavascriptExecutor; 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.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.Select; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | import org.testng.annotations.Test; 15 | 16 | public class day13shiksha { 17 | 18 | public void dropdown(WebElement element,String text) 19 | { 20 | Select dropdownvalue=new Select(element); 21 | dropdownvalue.selectByVisibleText(text); 22 | } 23 | 24 | @Test 25 | public void shiksha() throws InterruptedException 26 | { 27 | //Go to https://studyabroad.shiksha.com/ 28 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 29 | ChromeOptions option=new ChromeOptions(); 30 | option.addArguments("--disable-notifications"); 31 | ChromeDriver driver=new ChromeDriver(option); 32 | driver.get("https://studyabroad.shiksha.com/"); 33 | driver.manage().window().maximize(); 34 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 35 | WebDriverWait wait=new WebDriverWait(driver,30); 36 | Actions action=new Actions(driver); 37 | JavascriptExecutor js=(JavascriptExecutor) driver; 38 | 39 | //Mouse over on Colleges and click MS in Computer Science &Engg under MS Colleges 40 | action.moveToElement(driver.findElementByXPath("//label[@class='menuTab-div fnt-wt melabel' and text()='Colleges ']")).pause(2000).perform(); 41 | driver.findElementByXPath("//a[@class='pnl_a gaTrack' and text()='MS in Computer Science &Engg']").click(); 42 | 43 | //Select GRE under Exam Accepted and Score 300 & Below 44 | driver.findElementByXPath("//form[@id='formCategoryPageFilter']//p[text()='GRE']").click(); 45 | Thread.sleep(1000); 46 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//select[@name='examsScore[]'])[1]"))); 47 | 48 | dropdown(driver.findElementByXPath("(//select[@name='examsScore[]'])[1]"),"300 & below"); 49 | //Select dropdown=new Select(driver.findElementByXPath("(//select[@name='examsScore[]'])[1]")); 50 | //dropdown.selectByVisibleText("300 & below"); 51 | 52 | //Max 10 Lakhs under 1st year Total fees, USA under countries 53 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[@id='feesFilterScrollbar']//p[text()='Max 10 Lakhs']"))); 54 | Thread.sleep(1000); 55 | driver.findElementByXPath("//div[@id='feesFilterScrollbar']//p[text()='Max 10 Lakhs']").click(); 56 | Thread.sleep(1000); 57 | js.executeScript("arguments[0].click();",driver.findElementByXPath("//a[text()='USA']/preceding::span[@class='common-sprite'][1]")); 58 | 59 | //Select Sort By: Low to high 1st year total fees 60 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementById("categorySorter"))); 61 | Thread.sleep(1000); 62 | dropdown((driver.findElementById("categorySorter")),"Low to high 1st year total fees"); 63 | Thread.sleep(1000); 64 | //Click Add to compare of the College having least fees with Public University, Scholarship and Accommodation facilities 65 | List publicUniv = driver.findElementsByXPath("(//div[@class='tuple-title']//a)"); 66 | 67 | List university = driver.findElementsByXPath("//div[@class='detail-col flLt']/p[text()='Public university']/span"); 68 | List scholarship = driver.findElementsByXPath("//div[@class='detail-col flLt']/p[text()='Scholarship']/span"); 69 | List accomodation = driver.findElementsByXPath("//div[@class='detail-col flLt']/p[text()='Accommodation']/span"); 70 | 71 | String leastClg = null; 72 | 73 | for (int i=1;i<=publicUniv.size();i++) 74 | { 75 | String univ=university.get(i).getAttribute("class"); 76 | String scholar=scholarship.get(i).getAttribute("class"); 77 | String acc=accomodation.get(i).getAttribute("class"); 78 | 79 | if(univ.equals("tick-mark") & scholar.equals("tick-mark") & acc.equals("tick-mark") ) 80 | { 81 | leastClg=publicUniv.get(i).getText(); 82 | System.out.println("The least college with all 3 facility is" +leastClg); 83 | break; 84 | } 85 | } 86 | Thread.sleep(1000); 87 | driver.findElementByXPath("(//div[@class='tuple-title']//a[text()='"+leastClg+"']/following::p[text()='Add to compare'])[1]").click(); 88 | 89 | //Select the first college under Compare with similar colleges 90 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//div[@id='recommendationDiv']//a)[1]"))); 91 | Thread.sleep(1000); 92 | driver.findElementByXPath("(//div[@id='recommendationDiv']//a)[1]").click(); 93 | 94 | //Click on Compare College> 95 | driver.findElementByXPath("//div[@class='compare-col flLt']//strong[text()=\"Compare Colleges >\"]").click(); 96 | 97 | //Select When to Study as 2021 98 | driver.findElementByXPath("//input[@name='whenPlanToGo']/following::strong[text()='2021']").click(); 99 | 100 | //Select Preferred Countries as USA 101 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[@class='placeholder' and text()='Preferred Countries']"))); 102 | Thread.sleep(1000); 103 | js.executeScript("arguments[0].click();",driver.findElementByXPath("//div[@class='placeholder' and text()='Preferred Countries']")); 104 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//label[@class='nolnht'])[1]"))); 105 | driver.findElementByXPath("(//label[@class='nolnht'])[1]").click(); 106 | driver.findElementByXPath("//a[@class='ok-btn']").click(); 107 | 108 | //Select Level of Study as Masters 109 | driver.findElementByXPath("//strong[text()='Masters']").click(); 110 | 111 | //Select Preferred Course as MS 112 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//div[@class='placeholder' and text()='Preferred Course']")); 113 | Thread.sleep(2000); 114 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//li[@datalvl='Masters' and text()='MS']"))); 115 | driver.findElementByXPath("//li[@datalvl='Masters' and text()='MS']").click(); 116 | 117 | 118 | //Select Specialization as "Computer Science & Engineering" 119 | js.executeScript("arguments[0].click();",driver.findElementByXPath("//div[@class='placeholder' and text()='Preferred Specialisations']")); 120 | driver.findElementByXPath("//li[@class='lr-row' and text()='Computer Science & Engineering']").click(); 121 | 122 | //Click on Sign Up 123 | driver.findElementByXPath("//a[contains(text(),'Sign Up')]").click(); 124 | 125 | //Print all the warning messages displayed on the screen for missed mandatory fields 126 | List warnMsgs = driver.findElementsByXPath("//div[@class='helper-text' and contains(text(),'Please')]"); 127 | for (WebElement eachWarn : warnMsgs) { 128 | if(eachWarn.getText().length()>0) { 129 | System.out.println(eachWarn.getText()); 130 | 131 | }} 132 | 133 | driver.close(); 134 | 135 | 136 | 137 | 138 | }} -------------------------------------------------------------------------------- /day14zalando.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Set; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.openqa.selenium.JavascriptExecutor; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.chrome.ChromeDriver; 12 | import org.openqa.selenium.interactions.Actions; 13 | import org.openqa.selenium.support.ui.ExpectedConditions; 14 | import org.openqa.selenium.support.ui.WebDriverWait; 15 | import org.testng.annotations.Test; 16 | 17 | public class day14zalando { 18 | 19 | @Test 20 | public void zalando() throws InterruptedException 21 | { 22 | //Go to https://www.zalando.com/ 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 24 | ChromeDriver driver=new ChromeDriver(); 25 | driver.get("https://www.zalando.com/"); 26 | 27 | //Get the Alert text and print it//Close the Alert box 28 | String alertText = driver.switchTo().alert().getText(); 29 | System.out.println("The text in the alert box is" +alertText); 30 | driver.switchTo().alert().accept(); 31 | 32 | driver.manage().window().maximize(); 33 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 34 | WebDriverWait wait=new WebDriverWait(driver,30); 35 | Actions action=new Actions(driver); 36 | JavascriptExecutor js=(JavascriptExecutor) driver; 37 | 38 | 39 | //click on Zalando.uk 40 | driver.findElementByXPath("//a[text()='Zalando.uk']").click(); 41 | Thread.sleep(3000); 42 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@id='uc-banner-text']"))); 43 | driver.findElementByXPath("//div[@id='uc-banner-text']/following::button[contains(text(),\"That’s OK\")]").click(); 44 | 45 | //Click Women--> Clothing and click Coat 46 | driver.findElementByXPath("//span[text()='Women' and @class='z-text z-navicat-header_genderText z-text-cta z-text-black']").click(); 47 | action.moveToElement(driver.findElementByXPath("//span[text()='Clothing' and @class='z-text z-navicat-header_categoryListLinkText z-text-cta z-text-black']")).pause(2000).perform(); 48 | driver.findElementByXPath("//span[text()='Coats' and @class='z-text z-text-body z-text-black']").click(); 49 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Material']"))); 50 | 51 | //Choose Material as cotton (100%) and Length as thigh-length 52 | Thread.sleep(3000); 53 | js.executeScript("arguments[0].click();",driver.findElementByXPath("//span[text()='Material']")); 54 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//span[text()='cotton (100%)']"))); 55 | Thread.sleep(2000); 56 | 57 | driver.findElementByXPath("//span[text()='cotton (100%)']").click(); 58 | driver.findElementByXPath("//button[text()='Save']").click(); 59 | 60 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Length']"))); 61 | Thread.sleep(1000); 62 | driver.findElementByXPath("//span[text()='Length']").click(); 63 | driver.findElementByXPath("//span[text()='thigh-length']").click(); 64 | driver.findElementByXPath("//button[text()='Save']").click(); 65 | 66 | //Click on Q/S designed by MANTEL - Parka coat 67 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[text()='Q/S designed by']/following-sibling::div[text()='MANTEL - Parka - navy']"))); 68 | Thread.sleep(1000); 69 | driver.findElementByXPath("//div[text()='Q/S designed by']/following-sibling::div[contains(text(),'MANTEL - Parka')]").click(); 70 | 71 | //Check the availability for Color as Olive and Size as 'M' 72 | driver.findElementByXPath("(//img[@alt='olive'])[2]").click(); 73 | Thread.sleep(2000); 74 | 75 | if (driver.findElementByXPath("//h2[text()='Out of stock']").isDisplayed()) 76 | { 77 | driver.findElementByXPath("(//img[@alt='navy'])[2]").click(); 78 | Thread.sleep(2000); 79 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Choose your size']"))); 80 | driver.findElementByXPath("//span[text()='Choose your size']").click(); 81 | driver.findElementByXPath("//span[text()='M']").click(); 82 | } 83 | 84 | else if(driver.findElementByXPath("//span[text()='Choose your size']").isDisplayed()) 85 | { 86 | driver.findElementByXPath("//span[text()='Choose your size']").click(); 87 | driver.findElementByXPath("//span[text()='M']").click(); 88 | } 89 | 90 | else 91 | { 92 | System.out.println("Both the items are out of stock"); 93 | } 94 | 95 | String standDelivery = driver.findElementByXPath("(//span[text()='Standard delivery']//following::span[@class='AtOZbZ'])[1]").getText(); 96 | System.out.println("The standardDelivery is " +standDelivery); 97 | 98 | //Add to bag only if Standard Delivery is free 99 | if(standDelivery.equalsIgnoreCase("Free")) 100 | { 101 | driver.findElementByXPath("//span[text()='Add to bag']").click(); 102 | } 103 | else 104 | { 105 | System.out.println("The standard delivery is not free"); 106 | } 107 | 108 | //Mouse over on Your Bag and Click on "Go to Bag" 109 | action.moveToElement(driver.findElementByXPath("//a[@class='z-navicat-header_navToolItemLink']/div")).pause(1000).perform(); 110 | driver.findElementByXPath("//div[@class='z-1-button__content' and text()='Go to bag']").click(); 111 | 112 | //Capture the Estimated Deliver Date and print 113 | String estDelivery = driver.findElementByXPath("//div[@data-id='delivery-estimation']/span").getText(); 114 | System.out.println("The estimated delivery date is " +estDelivery); 115 | 116 | //Mouse over on FREE DELIVERY & RETURNS*, get the tool tip text and print 117 | action.moveToElement(driver.findElementByXPath("(//a[@name='“headbanner.about.us\"']/parent::span)[1]")).perform(); 118 | String toolTipText = driver.findElementByXPath("(//a[@name='“headbanner.about.us\"']/parent::span)[1]").getAttribute("title"); 119 | System.out.println("The tooltip text is " +toolTipText); 120 | 121 | //Click on FREE DELIVERY & RETURNS 122 | driver.findElementByXPath("//a[text()='Free delivery & returns*']").click(); 123 | 124 | //Click on Start chat 125 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Start chat']/parent::button"))); 126 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//span[text()='Start chat']/parent::button")); 127 | Thread.sleep(4000); 128 | 129 | //Navigate to new window 130 | Set windowHandles = driver.getWindowHandles(); 131 | List windowId=new ArrayList (windowHandles); 132 | driver.switchTo().window(windowId.get(1)); 133 | 134 | //Enter you first name and a dummy email and click Start Chat 135 | 136 | driver.findElementById("prechat_customer_name_id").sendKeys("Testing purpose"); 137 | driver.findElementById("prechat_customer_email_id").sendKeys("test@gmail.com"); 138 | driver.findElementByXPath("//span[text()='Start Chat']").click(); 139 | 140 | //Type Hi, click Send and print thr reply message and close the chat window. 141 | 142 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//button[text()='Save Chat']"))); 143 | driver.findElementById("liveAgentChatTextArea").sendKeys("Hi"); 144 | driver.findElementByXPath("//button[text()='Send']").click(); 145 | Thread.sleep(3000); 146 | 147 | List chatMsg = driver.findElementsByXPath("//span[@class='operator']/span[@class='messageText']"); 148 | int chatSize=chatMsg.size(); 149 | System.out.println("The reply message from operator is "+chatMsg.get(chatSize-1).getText()); 150 | 151 | driver.close(); 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /day15airbnb.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.text.DateFormat; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.ArrayList; 7 | import java.util.Calendar; 8 | import java.util.Date; 9 | import java.util.LinkedHashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.Map.Entry; 13 | import java.util.Set; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | import org.openqa.selenium.JavascriptExecutor; 17 | import org.openqa.selenium.Keys; 18 | import org.openqa.selenium.WebElement; 19 | import org.openqa.selenium.chrome.ChromeDriver; 20 | import org.openqa.selenium.chrome.ChromeOptions; 21 | import org.openqa.selenium.support.ui.ExpectedConditions; 22 | import org.openqa.selenium.support.ui.WebDriverWait; 23 | import org.testng.annotations.Test; 24 | 25 | public class day15airbnb { 26 | 27 | public ChromeDriver driver; 28 | 29 | //method to click multiple times 30 | public void multipleClick(String xpath,int count) throws InterruptedException 31 | { 32 | for (int i=1;i<=count;i++) 33 | { 34 | driver.findElementByXPath(xpath).click(); 35 | Thread.sleep(500); 36 | } 37 | } 38 | 39 | @Test 40 | public void airbnb() throws InterruptedException, ParseException 41 | { 42 | //Go to https://www.airbnb.co.in/ 43 | 44 | System.setProperty("webdriver.chrome.driver","./drivers/chromedriver_win32/chromedriver.exe"); 45 | ChromeOptions option=new ChromeOptions(); 46 | option.addArguments("--disable-notifications"); 47 | driver=new ChromeDriver(option); 48 | WebDriverWait wait =new WebDriverWait(driver,30); 49 | JavascriptExecutor js=(JavascriptExecutor) driver; 50 | driver.get("https://www.airbnb.co.in/"); 51 | 52 | driver.manage().window().maximize(); 53 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 54 | 55 | wait.until(ExpectedConditions.visibilityOf(driver.findElementById("alert-box-message"))); 56 | driver.findElementByXPath("//button[@title='OK']").click(); 57 | 58 | //2) Type Coorg in location and Select Coorg, Karnataka 59 | driver.findElementByName("query").sendKeys("Coorg"); 60 | Thread.sleep(2000); 61 | driver.findElementByName("query").sendKeys(Keys.ARROW_DOWN,Keys.PAUSE,Keys.ENTER); 62 | 63 | //3) Select the Start Date as June 1st and End Date as June 5th 64 | 65 | Calendar currentMonth = Calendar.getInstance(); 66 | SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM"); 67 | // Increment month 68 | currentMonth.add(Calendar.MONTH, 1); 69 | String nextMonth = dateFormat.format(currentMonth.getTime()); 70 | System.out.println("Next month : " + dateFormat.format(currentMonth.getTime())); 71 | 72 | 73 | driver.findElementByXPath("//div[text()='"+nextMonth+" 2020']//following::table[1]//td//div[text()='1']").click(); 74 | driver.findElementByXPath("//div[text()='"+nextMonth+" 2020']//following::table[1]//td//div[text()='5']").click(); 75 | String userDate = driver.findElementByXPath("//div[text()='Check in / Check out']//following-sibling::div").getText(); 76 | System.out.println(userDate); 77 | 78 | 79 | //4) Select guests as 6 adults, 3 child and Click Search 80 | driver.findElementByXPath("//div[text()='Add guests']/parent::button").click(); 81 | multipleClick("//div[@id='searchFlow-title-label-stepper-adults']//following::button[@aria-label='increase value'][1]",6); 82 | multipleClick("//div[@id='searchFlow-title-label-stepper-children']//following::button[@aria-label='increase value'][1]",3); 83 | int userGuests=Integer.parseInt(driver.findElementByXPath("//div[text()='Guests']/following-sibling::div").getText().replaceAll("\\D", "")); 84 | System.out.println("The number of guests searched by user is "+userGuests); 85 | driver.findElementByXPath("//button[@type='submit']").click(); 86 | 87 | //5) Click Cancellation flexibility and enable the filter and Save 88 | wait.until(ExpectedConditions.visibilityOfAllElements(driver.findElementsByXPath("//div[@itemprop='itemListElement']"))); 89 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Cancellation flexibility']//ancestor::button"))); 90 | driver.findElementByXPath("//span[text()='Cancellation flexibility']//ancestor::button").click(); 91 | driver.findElementById("filterItem-switch-flexible_cancellation-true").click(); 92 | 93 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//button[@id='filterItem-switch-flexible_cancellation-true' and @aria-checked='true']"))); 94 | driver.findElementById("filter-panel-save-button").click(); 95 | Thread.sleep(1000); 96 | 97 | //6) Select Type of Place as Entire Place and Save 98 | Thread.sleep(1000); 99 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Type of place']/ancestor::button"))); 100 | driver.findElementByXPath("//span[text()='Type of place']/ancestor::button").click(); 101 | driver.findElementByXPath("//input[@name='Entire place']/following-sibling::span[@data-checkbox='true']").click(); 102 | driver.findElementById("filter-panel-save-button").click(); 103 | 104 | //7) Set Min price as 3000 and max price as 5000 105 | Thread.sleep(2000); 106 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Price']/ancestor::button"))); 107 | driver.findElementByXPath("//span[text()='Price']/ancestor::button").click(); 108 | wait.until(ExpectedConditions.visibilityOf(driver.findElementById("price_filter_min"))); 109 | Thread.sleep(2000); 110 | driver.findElementByXPath("//input[@id='price_filter_min']").sendKeys(Keys.CONTROL,Keys.chord("a")); 111 | driver.findElementByXPath("//input[@id='price_filter_min']").sendKeys(Keys.BACK_SPACE); 112 | Thread.sleep(1000); 113 | driver.findElementByXPath("//input[@id='price_filter_min']").sendKeys("3000"); 114 | driver.findElementById("price_filter_max").sendKeys(Keys.CONTROL,Keys.chord("a")); 115 | driver.findElementById("price_filter_max").sendKeys(Keys.BACK_SPACE); 116 | driver.findElementById("price_filter_max").sendKeys("5000"); 117 | 118 | //8) Click More Filters and set 3 Bedrooms and 3 Bathrooms 119 | driver.findElementByXPath("//span[text()='More filters']/parent::button").click(); 120 | Thread.sleep(1000); 121 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@id='title-label-filterItem-stepper-min_bedrooms-0']//following::button[@aria-label='increase value']"))); 122 | multipleClick("//div[@id='title-label-filterItem-stepper-min_bedrooms-0']//following::button[@aria-label='increase value']",3); 123 | Thread.sleep(500); 124 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[@id='title-label-filterItem-stepper-min_bathrooms-0']//following::button[@aria-label='increase value']"))); 125 | multipleClick("//div[@id='title-label-filterItem-stepper-min_bathrooms-0']//following::button[@aria-label='increase value']",3); 126 | 127 | //9) Check the Amenities with Kitchen, Facilities with Free parking on premisses, Property as House and Host Language as English 128 | driver.findElementByXPath("//input[@name='Kitchen']/following-sibling::span[@data-checkbox='true']").click(); 129 | driver.findElementByXPath("//input[@name='Free parking on premises']/following-sibling::span[@data-checkbox='true']").click(); 130 | driver.findElementByXPath("//input[@name='House']/following-sibling::span[@data-checkbox='true']").click(); 131 | driver.findElementByXPath("//input[@name='English']/following-sibling::span[@data-checkbox='true']").click(); 132 | 133 | // and click on Stays only when stays available 134 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//input[@name='English']/following-sibling::span[@data-checkbox='true']"))); 135 | Thread.sleep(3000); 136 | String availableStays = driver.findElementByXPath("//button[starts-with(text(),'Show')]").getText().replaceAll("\\D", ""); 137 | System.out.println(availableStays); 138 | int availableStaysint=Integer.parseInt(availableStays); 139 | System.out.println("The number of available stay is "+availableStaysint); 140 | 141 | if(availableStaysint>=1) 142 | { 143 | driver.findElementByXPath("//button[contains(text(),'Show "+availableStaysint+" stay')]").click(); 144 | } 145 | else 146 | { 147 | System.out.println("There is no stay available"); 148 | } 149 | 150 | //10) Click Prahari Nivas, the complete house 151 | 152 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@itemprop='itemListElement']"))); 153 | Thread.sleep(1000); 154 | driver.findElementByXPath("(//div[@itemprop='itemListElement']//a[contains(@aria-label,'Prahari Nivas')])[1]").click(); 155 | 156 | //to move to new window 157 | Set windowHandles = driver.getWindowHandles(); 158 | List listWindow=new ArrayList (windowHandles); 159 | driver.switchTo().window(listWindow.get(listWindow.size()-1)); 160 | 161 | 162 | //11) Click on "Show all * amenities" 163 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='Location']"))); 164 | Thread.sleep(3000); 165 | 166 | js.executeScript("arguments[0].click();",driver.findElementByXPath("(//*[contains(text(),'amenities')])[1]")); 167 | 168 | //12) Print all the Not included amenities 169 | js.executeScript("arguments[0].scrollIntoView();", driver.findElementByXPath("//*[text()='Not included']")); 170 | List unIncludedAmenities = driver.findElementsByXPath("//*[text()='Not included']//following::span[contains(text(),'Unavailable')]/following-sibling::del"); 171 | for (WebElement eachAmenities : unIncludedAmenities) { 172 | 173 | System.out.println("The unincluded Amenities are" +eachAmenities.getText()); 174 | } 175 | Thread.sleep(2000); 176 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//button[@aria-label='Close' and not(contains(@title,'Close'))]")); 177 | Thread.sleep(3000); 178 | 179 | //13) Verify the Check-in date, Check-out date and Guests 180 | String checkInDate = driver.findElementByXPath("//span[contains(text(),'night')]//preceding::span[contains(text(),'3,500')]//following::div[contains(text(),'1/2020')]").getText(); 181 | Thread.sleep(1000); 182 | String checkOutDate = driver.findElementByXPath("//span[contains(text(),'night')]//preceding::span[contains(text(),'3,500')]//following::div[contains(text(),'5/2020')]").getText(); 183 | int guests =Integer.parseInt(driver.findElementByXPath("(//label[contains(@for,'')]//following::span[contains(text(),'guests')])[1]").getText().replaceAll("\\D", "")); 184 | 185 | if(((checkInDate.equals("6/1/2020") | checkInDate.equals("06/01/2020")) & (checkOutDate.equals("6/5/2020") | checkOutDate.equals("06/05/2020")) & guests==userGuests)) 186 | { System.out.println("The checkindate,checkoutdate and number of guests are verified"); } 187 | 188 | 189 | //14) Read all the Sleeping arrangements and Print 190 | 191 | List bedRoomCount = driver.findElementsByXPath("//*[text()='Sleeping arrangements']//following::div[contains(text(),'Bedroom')]"); 192 | List bedCount = driver.findElementsByXPath("//*[text()='Sleeping arrangements']//following::div[contains(text(),'Bedroom')]/following-sibling::div"); 193 | System.out.println("The size is" +bedRoomCount.size()); 194 | int j=bedRoomCount.size()-1; 195 | 196 | Map map=new LinkedHashMap(); 197 | for (int i=0;i<=j;i++) { 198 | if(i>=3) 199 | { 200 | js.executeScript("arguments[0].click();",driver.findElementByXPath("//div[contains(@style,'right') and @class='_1mlprnc']//button")); 201 | Thread.sleep(1000); 202 | bedRoomCount.add(driver.findElementByXPath("//*[text()='Sleeping arrangements']//following::div[contains(text(),'Bedroom')]["+(i+1)+"]")); 203 | bedCount.add(driver.findElementByXPath("(//*[text()='Sleeping arrangements']//following::div[contains(text(),'Bedroom')]/following-sibling::div)["+(i+1)+"]")); 204 | } 205 | 206 | map.put(bedRoomCount.get(i).getText(),bedCount.get(i).getText()); 207 | } 208 | 209 | 210 | for (Entry eachMapData: map.entrySet()) { 211 | 212 | System.out.println("The sleeping arrangements "+eachMapData.getKey()+"-----"+eachMapData.getValue()); 213 | } 214 | 215 | //15) Close all the browsers 216 | driver.quit(); 217 | 218 | } 219 | 220 | } 221 | 222 | 223 | -------------------------------------------------------------------------------- /day16ajio.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 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.chrome.ChromeDriver; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.Select; 13 | import org.openqa.selenium.support.ui.WebDriverWait; 14 | import org.testng.annotations.Test; 15 | 16 | public class day16ajio { 17 | 18 | 19 | @Test 20 | public void test() throws InterruptedException 21 | { 22 | //www.ajio.com/shop/sale 23 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 24 | ChromeOptions option=new ChromeOptions(); 25 | option.addArguments("--disable-notifications"); 26 | ChromeDriver driver =new ChromeDriver(option); 27 | driver.get("https://www.ajio.com/shop/sale"); 28 | 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 31 | WebDriverWait wait=new WebDriverWait(driver,30); 32 | 33 | 34 | 35 | //2) Enter Bags in the Search field and Select Bags in Women Handbags 36 | driver.findElementByXPath("//input[@name='searchVal']").sendKeys("Bags"); 37 | Thread.sleep(1000); 38 | driver.findElementByXPath("//span[text()='Bags in ']/following-sibling::span[text()='Women Handbags']").click(); 39 | 40 | //3) Click on five grid and Select SORT BY as "What's New" 41 | driver.findElementByClassName("five-grid").click(); 42 | Select sort=new Select(driver.findElementByTagName("Select")); 43 | sort.selectByVisibleText("What's New"); 44 | 45 | //4) Enter Price Range Min as 2000 and Max as 5000 46 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[@class='facet-left-pane-label' and text()='price']"))); 47 | Thread.sleep(1000); 48 | driver.findElementByXPath("//span[@class='facet-left-pane-label' and text()='price']").click(); 49 | driver.findElementById("minPrice").sendKeys("2000"); 50 | driver.findElementById("maxPrice").sendKeys("5000"); 51 | driver.findElementByXPath("//div[@class='facet-min-price-filter']//button[@type='submit']").click(); 52 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//span[@class='pull-left' and text()='Rs.2000 - Rs.5000']"))); 53 | 54 | if (driver.findElementByXPath("//span[@class='pull-left' and text()='Rs.2000 - Rs.5000']").isDisplayed()) 55 | { 56 | System.out.println("The price filter is applied successfully"); 57 | } 58 | 59 | //5) Click on the product "Puma Ferrari LS Shoulder Bag" 60 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[text()='Puma']/following-sibling::div[text()='Ferrari LS Shoulder Bag']"))); 61 | Thread.sleep(1000); 62 | driver.findElementByXPath("//div[text()='Puma']/following-sibling::div[text()='Ferrari LS Shoulder Bag']").click(); 63 | 64 | Set windowHandles = driver.getWindowHandles(); 65 | List winList=new ArrayList(windowHandles); 66 | driver.switchTo().window(winList.get(winList.size()-1)); 67 | 68 | //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 69 | int sp = Integer.parseInt(driver.findElementByClassName("prod-sp").getText().replaceAll("\\D", "")); 70 | String couponCode = null; 71 | int actualDiscount = 0; 72 | if(sp>2690) 73 | { 74 | String[] split = driver.findElementByClassName("promo-title").getText().split("\\s+"); //to split based on multiple space 75 | couponCode=split[split.length-1]; 76 | System.out.println("The applicable coupon code is "+couponCode); 77 | int discountPrice=Integer.parseInt(driver.findElementByXPath("//div[@class='promo-discounted-price']//span").getText().replaceAll("\\D", "")); 78 | 79 | actualDiscount=sp-discountPrice; 80 | System.out.println("The actual discounted amount is "+ actualDiscount); 81 | 82 | } 83 | //7) Check the availability of the product for pincode 560043, print the expected delivery date if it is available 84 | driver.findElementByXPath("//div[@id='edd']//span[contains(text(),'Enter pin-code')]").click(); 85 | driver.findElementByName("pincode").sendKeys("635001"); 86 | driver.findElementByClassName("edd-pincode-modal-submit-btn").click(); 87 | 88 | if(driver.findElementByClassName("edd-message-success-details").isDisplayed()) 89 | { 90 | System.out.println("Ajio delivers to given pincode"); 91 | } 92 | else 93 | { 94 | System.out.println("Ajio doesn't deliver to this pincode"); 95 | } 96 | //8) Click on Other Informations under Product Details and Print the Customer Care address, phone and email 97 | driver.findElementByClassName("other-info-toggle").click(); 98 | String text = driver.findElementByXPath("(//span[text()='Customer Care Address']//following::span[@class='other-info'])[1]").getText(); 99 | System.out.println("The Customer Care Address,phone and email is " +text); 100 | 101 | 102 | //9) Click on ADD TO BAG and then GO TO BAG 103 | driver.findElementByXPath("//span[text()='ADD TO BAG']").click(); 104 | Thread.sleep(2000); 105 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//div[@class='ic-cart ']"))); 106 | driver.findElementByXPath("//div[@class='ic-cart ']").click(); 107 | 108 | //10) Check the Order Total before apply coupon 109 | String OrderTotal = driver.findElementByXPath("//section[@id='orderTotal']//span[@class='price-value bold-font']").getText(); 110 | int OrderTotalint =Integer.parseInt(OrderTotal.substring(0,OrderTotal.length()-3).replaceAll("\\D", "")); 111 | 112 | //11) Enter Coupon Code and Click Apply 113 | driver.findElementById("couponCodeInput").sendKeys(couponCode); 114 | driver.findElementByXPath("//button[text()='Apply']").click(); 115 | 116 | //12) Verify the Coupon Savings amount(round off if it in decimal) under Order Summary and the matches the amount calculated in Product details 117 | Float savingsAmount =Float.parseFloat(driver.findElementByXPath("//span[text()='Coupon savings']/following-sibling::span").getText().replaceAll("[^0-9.]", "").substring(1)); 118 | int roundedOffSavingAmt = Math.round(savingsAmount); 119 | System.out.println("The roundedOff savings amount is "+roundedOffSavingAmt); 120 | 121 | if(actualDiscount==roundedOffSavingAmt) 122 | { 123 | System.out.println("The savings Amount is verified"); 124 | } 125 | else 126 | { 127 | System.out.println("The savings amount doesn't match"); 128 | } 129 | //13) Click on Delete and Delete the item from Bag 130 | driver.findElementByClassName("delete-btn").click(); 131 | driver.findElementByXPath("//div[text()='DELETE']").click(); 132 | if(driver.findElementByClassName("empty-msg").isDisplayed()) 133 | { 134 | System.out.println("The product is deleted successfully"); 135 | } 136 | 137 | //14) Close all the browsers 138 | driver.quit(); 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | } 151 | } -------------------------------------------------------------------------------- /day17azure.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.openqa.selenium.JavascriptExecutor; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.chrome.ChromeOptions; 10 | import org.openqa.selenium.support.ui.ExpectedConditions; 11 | import org.openqa.selenium.support.ui.Select; 12 | import org.openqa.selenium.support.ui.WebDriverWait; 13 | import org.testng.annotations.Test; 14 | 15 | public class day17azure { 16 | 17 | 18 | @Test 19 | public void azure() 20 | { 21 | 22 | //https://github.com/TestLeafPages/Research/blob/master/PdfFileDownload.java 23 | //1) Go to https://azure.microsoft.com/en-in/ 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 25 | ChromeOptions option=new ChromeOptions(); 26 | option.addArguments("--disable-notifications"); 27 | ChromeDriver driver =new ChromeDriver(option); 28 | driver.get("https://azure.microsoft.com/en-in/"); 29 | 30 | 31 | 32 | 33 | driver.manage().window().maximize(); 34 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 35 | WebDriverWait wait=new WebDriverWait(driver,30); 36 | JavascriptExecutor js=(JavascriptExecutor) driver; 37 | 38 | //2) Click on Pricing 39 | driver.findElementById("navigation-pricing").click(); 40 | 41 | //3) Click on Pricing Calculator 42 | driver.findElementByXPath("//a[contains(text(),'Pricing calculator')]").click(); 43 | 44 | //4) Click on Containers 45 | driver.findElementByXPath("//button[@data-event-property='containers']").click(); 46 | 47 | //5) Select Container Instances 48 | driver.findElementByXPath("(//span[@class='service-heading' and text()='Container Instances'])[2]").click(); 49 | 50 | 51 | //6) Click on Container Instance Added View 52 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[text()='Container Instances added.']//a[text()='View']"))); 53 | driver.findElementByXPath("//div[text()='Container Instances added.']//a[text()='View']").click(); 54 | 55 | //7) Select Region as "South India" 56 | Select region=new Select(driver.findElementByXPath("//select[@name='region']")); 57 | region.selectByVisibleText("South India"); 58 | 59 | //8) Set the Duration as 180000 seconds 60 | driver.findElementByName("seconds").clear(); 61 | driver.findElementByName("seconds").sendKeys("80000"); 62 | 63 | //9) Select the Memory as 4GB 64 | Select memory=new Select(driver.findElementByName("memory")); 65 | memory.selectByVisibleText("4 GB"); 66 | 67 | //10) Enable SHOW DEV/TEST PRICING 68 | driver.findElementByName("devTestSelected").click(); 69 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("notification-copy"))); 70 | String pricingContent = driver.findElementByClassName("notification-copy").getText(); 71 | System.out.println("The notification content is "+pricingContent); 72 | wait.until(ExpectedConditions.invisibilityOf(driver.findElementByClassName("notification-copy"))); 73 | //11) Select Indian Rupee as currency 74 | Select currency=new Select(driver.findElementByXPath("//select[@class='select currency-dropdown']")); 75 | currency.selectByVisibleText("Indian Rupee (₹)"); 76 | 77 | //12) Print the Estimated monthly price 78 | String estimatedMonthlyCost = driver.findElementByXPath("(//h3[text()='Estimated monthly cost']//following::span[@class='numeric']/span)[2]").getText(); 79 | System.out.println("The estimated monthly cost is "+estimatedMonthlyCost); 80 | 81 | //13) Click on Export to download the estimate as excel 82 | driver.findElementByXPath("//button[@class='calculator-button button-transparent export-button']").click(); 83 | 84 | //Verify the downloded file in the local folder 85 | File containerFile = new File("C:\\Users\\sudham\\Downloads\\ExportedEstimate.xlsx"); 86 | if(containerFile.exists()) 87 | { 88 | System.out.println("Estimate Sheet Downloaded successfully"); 89 | } 90 | //14) Navigate to Example Scenarios and Select CI/CD for Containers 91 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByLinkText("Example Scenarios"))); 92 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//a[text()='Example Scenarios']")); 93 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//span[text()='CI/CD for Containers']"))); 94 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//span[text()='CI/CD for Containers']")); 95 | 96 | //15) Click Add to Estimate 97 | js.executeScript("arguments[0].click();", driver.findElementByXPath("//button[text()='Add to estimate']")); 98 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("notification-copy"))); 99 | 100 | //16) Change the Currency as Indian Rupee 101 | wait.until(ExpectedConditions.invisibilityOf(driver.findElementByClassName("notification-copy"))); 102 | Select ciCurrency=new Select(driver.findElementByXPath("//select[@class='select currency-dropdown']")); 103 | ciCurrency.selectByVisibleText("Indian Rupee (₹)"); 104 | 105 | //17) Enable SHOW DEV/TEST PRICING 106 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByName("devTestSelected"))); 107 | driver.findElementByName("devTestSelected").click(); 108 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("notification-copy"))); 109 | String ciPricingContent = driver.findElementByClassName("notification-copy").getText(); 110 | System.out.println("The notification content is "+ciPricingContent); 111 | 112 | //18) Export the Estimate 113 | wait.until(ExpectedConditions.invisibilityOf(driver.findElementByClassName("notification-copy"))); 114 | driver.findElementByXPath("//button[@class='calculator-button button-transparent export-button']").click(); 115 | File examplefile = new File("C:\\Users\\sudham\\Downloads\\ExportedEstimate.xlsx"); 116 | if(examplefile.exists()) 117 | { 118 | System.out.println("Estimate sheet Downloaded successfully"); 119 | } 120 | 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /day1myntra.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebDriver; 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 day1myntra { 17 | 18 | @Test 19 | public void myntra() throws InterruptedException 20 | { 21 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 22 | 23 | //Disable notification 24 | ChromeOptions options=new ChromeOptions(); 25 | options.addArguments("--disable-notifications"); 26 | 27 | //launch browser,load url and maximize 28 | ChromeDriver driver =new ChromeDriver(options); 29 | driver.get("https://www.myntra.com/"); 30 | driver.manage().window().maximize(); 31 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 32 | WebDriverWait wait=new WebDriverWait(driver,10); 33 | 34 | //Mousehover on women 35 | WebElement womenLink = driver.findElementByXPath("(//div[@class='desktop-navLink'])[2]//a"); 36 | Actions obj=new Actions(driver); 37 | obj.moveToElement(womenLink).perform(); 38 | driver.findElementByLinkText("Jackets & Coats").click(); 39 | 40 | //6985 items to get count alone 41 | String totalcount=driver.findElementByClassName("title-count").getText(); 42 | String count=totalcount.replaceAll("\\D", ""); 43 | int exactCount=Integer.parseInt(count); 44 | System.out.println("The count of total items is" +count); 45 | 46 | //Validate the sum of categories count matches 47 | String rawJacketCount=driver.findElementByXPath("//label[text()='Jackets']//span").getText(); 48 | int jacketsCount=Integer.parseInt(rawJacketCount.replaceAll("\\D", "")); 49 | 50 | String rawCoatCount=driver.findElementByXPath("//label[text()='Coats']//span").getText(); 51 | int coatsCount=Integer.parseInt(rawCoatCount.replaceAll("\\D", "")); 52 | 53 | System.out.println(+jacketsCount +coatsCount); 54 | if (exactCount==jacketsCount+coatsCount) 55 | { 56 | System.out.println("The count matched"); 57 | } 58 | 59 | //Check Coats.Click + More option under BRAND.Type MANGO and click checkbox.Close the pop-up x 60 | driver.findElementByXPath("//label[text()='Coats']").click(); 61 | wait.until(ExpectedConditions.textToBe(By.className("filter-summary-filter"), "Coats")); 62 | 63 | driver.findElementByClassName("brand-more").click(); 64 | driver.findElementByClassName("FilterDirectory-searchInput").sendKeys("MANGO"); 65 | driver.findElementByXPath("(//label[text()='MANGO'])[2]").click(); 66 | driver.findElementByXPath("//div[@class='FilterDirectory-titleBar']//span").click(); 67 | wait.until(ExpectedConditions.textToBe(By.xpath("(//div[@class='filter-summary-filter'])[2]"), "MANGO")); 68 | 69 | //Confirm all the Coats are of brand MANGO 70 | List products = driver.findElementsByXPath("//h3[@class='product-brand']"); 71 | int brandCount=0; 72 | for (WebElement product : products) { 73 | if(product.getText().equals("MANGO")) 74 | { 75 | brandCount=brandCount+1; 76 | }} 77 | 78 | if(brandCount==products.size()) { 79 | System.out.println("All products are Mango brands");} 80 | 81 | //Sort by Better Discount 82 | obj.moveToElement(driver.findElementByClassName("sort-sortBy")).perform(); 83 | driver.findElementByXPath("//label[text()='Better Discount']").click(); 84 | Thread.sleep(3000); 85 | 86 | // Find the price of first displayed item 87 | List price = driver.findElementsByClassName("product-discountedPrice"); 88 | System.out.println("The price of first item is " +price.get(0).getText()); 89 | 90 | //Mouse over on size of the first item 91 | obj.moveToElement(driver.findElementByXPath("(//h3[@class='product-brand'])[1]")).perform(); 92 | 93 | //Click on WishList Now 94 | driver.findElementByXPath("(//span[text()='wishlist now'])[1]").click(); 95 | driver.close(); 96 | 97 | } 98 | 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /day2Nykaa.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 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.chrome.ChromeDriver; 9 | import org.openqa.selenium.chrome.ChromeOptions; 10 | import org.openqa.selenium.interactions.Actions; 11 | import org.openqa.selenium.support.ui.ExpectedConditions; 12 | import org.openqa.selenium.support.ui.WebDriverWait; 13 | import org.testng.annotations.Test; 14 | 15 | public class day2Nykaa { 16 | 17 | public static ChromeDriver driver; 18 | 19 | public String windowmethod() 20 | { 21 | Set windowsid = driver.getWindowHandles(); 22 | List windowsidlist=new ArrayList (windowsid); 23 | int size= windowsidlist.size(); 24 | return windowsidlist.get(size-1); 25 | } 26 | 27 | @Test 28 | public void nykaa() throws InterruptedException 29 | { 30 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 31 | 32 | //disable notifications 33 | ChromeOptions options=new ChromeOptions(); 34 | options.addArguments("--disable-notifications"); 35 | 36 | //launch url 37 | driver=new ChromeDriver(options); 38 | driver.get("https://www.nykaa.com/"); 39 | driver.manage().window().maximize(); 40 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 41 | WebDriverWait wait=new WebDriverWait(driver,30); 42 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//div[@class='nw_grid_content'])[1]"))); 43 | 44 | //Mouseover on Brands and Mouseover on Popular 45 | Actions action=new Actions(driver); 46 | action.moveToElement(driver.findElementByXPath("(//li[@class='menu-dropdown-icon'])//a[1]")).perform(); 47 | action.moveToElement(driver.findElementByXPath("//a[text()='Popular']")).perform(); 48 | 49 | //Click L'Oreal Paris 50 | driver.findElementByXPath("(//li[@class='brand-logo menu-links']//img)[5]").click(); 51 | 52 | //switch to new window 53 | driver.switchTo().window(windowmethod()); 54 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[text()='SPF']"))); 55 | 56 | if ((driver.getTitle()).contains("L'Oreal Paris")) 57 | { 58 | System.out.println("The title contains L'Oreal Paris"); 59 | } 60 | 61 | //Click sort By and select customer top rated 62 | Thread.sleep(5000); 63 | driver.findElementByXPath("//span[contains(text(),'Sort')]").click(); 64 | Thread.sleep(2000); 65 | driver.findElementByXPath("//span[contains(text(),'customer top rated')]").click(); 66 | 67 | //Click Category and click Shampoo 68 | Thread.sleep(3000); 69 | driver.findElementByXPath("//div[text()='Category']").click(); 70 | driver.findElementByXPath("//label[@for='chk_Shampoo_undefined']//span[1]").click(); 71 | 72 | //check whether the Filter is applied with Shampoo 73 | if( driver.findElementByXPath("//li[text()='Shampoo']").isDisplayed()) 74 | { 75 | System.out.println("The filter is applied with Shampoo"); 76 | } 77 | 78 | //Click on L'Oreal Paris Colour Protect Shampoo 79 | driver.findElementByXPath("//span[contains(text(),'Paris Colour Protect Shampoo')]").click(); 80 | Thread.sleep(5000); 81 | //switch to new window 82 | driver.switchTo().window(windowmethod()); 83 | 84 | //GO to the new window and select size as 175ml 85 | driver.findElementByXPath("(//span[@class='size-pallets'])[2]").click(); 86 | 87 | //Print the MRP of the product 88 | String price=driver.findElementByXPath("//span[@class='mrp-tag']/following::span[2]").getText(); 89 | System.out.println("The price of the shampoo is " +price); 90 | 91 | //Click on ADD to BAG 92 | driver.findElementByXPath("//button[text()='ADD TO BAG'][1]").click(); 93 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//span[text()='Product has been added to bag.']"))); 94 | 95 | //Go to Shopping Bag 96 | 97 | driver.findElementByClassName("AddBagIcon").click(); 98 | 99 | //Print the Grand Total amount 100 | String totalAmount = driver.findElementByXPath("//div[text()='Grand Total']/following::div[1]").getText(); 101 | System.out.println("The total Amount is" +totalAmount); 102 | 103 | driver.findElementByXPath("//button[@class='btn full fill no-radius proceed ']//span").click(); 104 | 105 | //Click on Continue as Guest 106 | driver.findElementByXPath("//button[@class='btn full big']").click(); 107 | 108 | //Print the warning message (delay in shipment) 109 | String warningmsg = driver.findElementByClassName("message").getText(); 110 | System.out.println("The warning msg is "+warningmsg); 111 | 112 | //to close all windows 113 | driver.quit(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /day3makemytrip.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 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.WebDriver; 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 day3makemytrip { 19 | 20 | @Test 21 | public void makemytrip() 22 | { 23 | //launch Browser 24 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 25 | ChromeOptions options=new ChromeOptions(); 26 | options.addArguments("--diable-notifications"); 27 | ChromeDriver driver=new ChromeDriver(options); 28 | driver.get("https://www.makemytrip.com/"); 29 | driver.manage().window().maximize(); 30 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 31 | WebDriverWait wait=new WebDriverWait(driver,30); 32 | 33 | //Click Hotels 34 | driver.findElementByXPath("//span[text()='Hotels']").click(); 35 | 36 | //Enter city as Goa, and choose Goa, India 37 | String city = driver.findElementByXPath("//input[@type='text']").getAttribute("value"); 38 | if (city.contains("Goa")) 39 | { 40 | System.out.println("The selected city is" +city); 41 | } 42 | 43 | else 44 | { 45 | driver.findElementByXPath("(//input[@type='text'])[2]").sendKeys("Goa",Keys.TAB); 46 | } 47 | 48 | //Enter Check in date as Next month 15th (May 15) and Check out as start date+5 49 | driver.findElementById("checkin").click(); 50 | driver.findElementByXPath("//div[@aria-label='Fri May 15 2020']").click(); 51 | int checkIndate = Integer.parseInt(driver.findElementByXPath("//div[@aria-label='Fri May 15 2020']").getText()); 52 | int checkOutdate=checkIndate+5; 53 | driver.findElementByXPath("//div[contains(@aria-label,'May "+checkOutdate+" 2020')]").click(); 54 | 55 | //Click on ROOMS & GUESTS and click 2 Adults and one Children(age 12). Click Apply Button. 56 | driver.findElementById("guest").click(); 57 | driver.findElementByXPath("(//div[@class='addRooomDetails']//li)[2]").click(); 58 | driver.findElementByXPath("//li[@data-cy='children-1']").click(); 59 | 60 | //childage 61 | Select age=new Select(driver.findElementByXPath("//select[@class='ageSelectBox']")); 62 | age.selectByVisibleText("12"); 63 | 64 | //click on Apply 65 | driver.findElementByXPath("//button[text()='APPLY']").click(); 66 | 67 | //click on search button 68 | driver.findElementById("hsw_search_button").click(); 69 | 70 | //to ignore the overlay 71 | driver.findElementByXPath("//div[@class='mmBackdrop wholeBlack']").click(); 72 | 73 | 74 | //Select locality as Baga 75 | driver.findElementByXPath("//label[text()='Baga']").click(); 76 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//label[text()='5 Star']"))); 77 | 78 | //Select 5 start in Star Category under Select Filters 79 | driver.findElementByXPath("//label[text()='5 Star']").click(); 80 | 81 | //verification 82 | if((driver.findElementByXPath("//span[text()='Baga']").isDisplayed()) & (driver.findElementByXPath("//span[text()='5 Star hotels']").isDisplayed())) 83 | { 84 | System.out.println("Baga and 5star is selected"); 85 | } 86 | 87 | //Click on the first resulting hotel and go to the new window 88 | List hotelList = driver.findElementsById("hlistpg_hotel_name"); 89 | String firstHotel=hotelList.get(0).getText(); 90 | driver.findElementByXPath("//span[contains(text(),'"+firstHotel+"')]").click(); 91 | 92 | Set window = driver.getWindowHandles(); 93 | List windowList=new ArrayList (window); 94 | driver.switchTo().window(windowList.get(1)); 95 | 96 | //Print the Hotel Name 97 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("hotelHeaderMiddle"))); 98 | String hotelName = driver.findElementById("detpg_hotel_name").getText(); 99 | System.out.println("The selected hotel name is" +hotelName); 100 | 101 | //Click MORE OPTIONS link and Select 3Months plan and close 102 | driver.findElementByXPath("//span[text()='MORE OPTIONS']").click(); 103 | driver.findElementByXPath("//table[@class='tblEmiOption']//tbody//tr[2]//td[6]/span").click(); 104 | String verifySelected = driver.findElementByXPath("//table[@class='tblEmiOption']//tbody//tr[2]//td[6]/span").getText(); 105 | if (verifySelected.contains("SELECTED")) 106 | { 107 | System.out.println("The 3months EMI option is selected"); 108 | } 109 | driver.findElementByClassName("close").click(); 110 | 111 | //Click on BOOK THIS NOW 112 | driver.findElementByLinkText("BOOK THIS NOW").click(); 113 | 114 | //close the pop up 115 | 116 | if (driver.findElementByXPath("//div[@class='_Modal modalCont']").isDisplayed()) 117 | { 118 | driver.findElementByClassName("close").click(); 119 | System.out.println("The modal is closed"); 120 | } 121 | 122 | //Print the Total Payable amount 123 | String totalAmt=driver.findElementById("revpg_total_payable_amt").getText(); 124 | System.out.println("The booking amount is" +totalAmt); 125 | 126 | //close all the windows 127 | driver.quit(); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /day4hp.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.openqa.selenium.By; 10 | import org.openqa.selenium.Capabilities; 11 | import org.openqa.selenium.JavascriptExecutor; 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.support.events.EventFiringWebDriver; 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 | import org.testng.annotations.Test; 24 | 25 | public class day4hp { 26 | 27 | public ChromeDriver driver; 28 | public WebDriverWait wait; 29 | 30 | @Test 31 | public void hp() throws InterruptedException 32 | 33 | { 34 | 35 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 36 | ChromeOptions options = new ChromeOptions(); 37 | options.addArguments("--disable-notifications"); 38 | 39 | DesiredCapabilities cap = new DesiredCapabilities(); 40 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 41 | options.merge(cap); 42 | ChromeDriver driver = new ChromeDriver(options); 43 | WebDriverWait wait=new WebDriverWait(driver,30); 44 | 45 | driver.get("https://store.hp.com/in-en/"); 46 | driver.manage().window().maximize(); 47 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 48 | //Handler cookies alert 49 | wait.until(ExpectedConditions.visibilityOf(driver.findElementById("alert-box-title"))); 50 | 51 | driver.findElementByXPath("//div[@class='optanon-alert-box-corner-close']/button").click(); 52 | 53 | try 54 | { 55 | 56 | driver.findElement(By.xpath("//span[@class='optly-modal-close close-icon']")); 57 | } 58 | 59 | catch(Exception e) 60 | { 61 | System.out.println("The pop up didnt occur"); 62 | } 63 | 64 | 65 | //Mouse over on Laptops menu and click on Pavilion 66 | Actions action=new Actions(driver); 67 | action.moveToElement(driver.findElementByXPath("(//span[text()='Laptops'])[1]")).perform(); 68 | driver.findElementByXPath("(//span[text()='Pavilion'])[1]").click(); 69 | 70 | //wait.until(ExpectedConditions.visibilityOfAllElements(driver.findElementsByClassName("product-image-photo"))); 71 | 72 | 73 | //Under SHOPPING OPTIONS -->Processor -->Select Intel Core i7 74 | driver.findElementByXPath("(//span[text()='Processor'])[1]/following::span[1]").click(); 75 | 76 | driver.findElementByXPath("//span[text()='Intel Core i7']").click(); 77 | //js.executeScript("arguments[0].scrollIntoView();",driver.findElementByXPath("//span[text()='More than 1 TB']") ); 78 | //Hard Drive Capacity -->More than 1TB 79 | 80 | Thread.sleep(5000); 81 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[contains(@class,'closeButton')]"))); 82 | driver.findElementByXPath("//div[contains(@class,'closeButton')]").click(); 83 | driver.findElementByXPath("//span[text()='More than 1 TB']").click(); 84 | 85 | 86 | //verify filter 87 | if ((driver.findElementByClassName("filter-value").getText()).contains("Intel Core i7") & ((driver.findElementByXPath("(//span[@class='filter-value'])[2]").getText()).contains("More than 1 TB"))) 88 | {System.out.println("The filter is successful");} 89 | 90 | //Select Sort By: Price: Low to High 91 | Select dropdown=new Select(driver.findElementById("sorter")); 92 | dropdown.selectByValue("price_asc"); 93 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//label[text()='Sort By'])[1]"))); 94 | 95 | Thread.sleep(3000); 96 | //Print the First resulting Product Name and Price 97 | String prodName=driver.findElementByXPath("(//a[@class='product-item-link'])[1]").getText(); 98 | int prodPrice=Integer.parseInt((driver.findElementByXPath("(//span[@class='price-container price-final_price tax weee'])[1]//span/span").getText()).replaceAll("\\D", "")); 99 | System.out.println("The first product and price is " +prodName +prodPrice); 100 | 101 | //Click on Add to Cart 102 | Thread.sleep(3000); 103 | driver.findElementByXPath("(//span[text()='Add To Cart'])[1]").click(); 104 | wait.until(ExpectedConditions.textToBePresentInElement(driver.findElementByXPath("//span[@class='counter qty']"),"1")); 105 | 106 | //Click on Shopping Cart icon --> Click on View and Edit Cart 107 | driver.findElementByXPath("//a[@class='action showcart']").click(); 108 | driver.findElementByXPath("//a[@class='action primary viewcart']").click(); 109 | wait.until(ExpectedConditions.urlContains("checkout/cart/")); 110 | 111 | //Check the Shipping Option --> Check availability at Pincode 112 | driver.findElementByName("pincode").sendKeys("600019"); 113 | driver.findElementByXPath("//button[@class='primary standard_delivery-button']").click(); 114 | wait.until(ExpectedConditions.textToBePresentInElement(driver.findElementByXPath("//span[@class='available']"), "In stock")); 115 | 116 | //Verify the order Total against the product price 117 | int totalPrice=Integer.parseInt((driver.findElementByXPath("//table[@class='data table totals']//tr[3]//td/strong").getText()).replaceAll("\\D", "")); 118 | System.out.println(totalPrice); 119 | if(totalPrice==prodPrice) 120 | { 121 | System.out.println("The product price matched total price"); 122 | 123 | //Proceed to Checkout if Order Total and Product Price matches 124 | driver.findElementByXPath("(//span[text()='Proceed to Checkout'])[1]").click(); 125 | 126 | //Click on Place Order 127 | driver.findElementByXPath("//div[@class='place-order-primary']//span").click(); 128 | 129 | //Capture the Error message and Print 130 | driver.findElementByXPath("//div[@class='message notice']/span").getText(); 131 | 132 | //Close Browser 133 | driver.close(); 134 | } 135 | 136 | }} 137 | -------------------------------------------------------------------------------- /day6BigBasket.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.openqa.selenium.Keys; 6 | import org.openqa.selenium.StaleElementReferenceException; 7 | import org.openqa.selenium.WebElement; 8 | import org.openqa.selenium.chrome.ChromeDriver; 9 | import org.openqa.selenium.interactions.Actions; 10 | import org.openqa.selenium.support.ui.ExpectedConditions; 11 | import org.openqa.selenium.support.ui.Select; 12 | import org.openqa.selenium.support.ui.WebDriverWait; 13 | import org.testng.annotations.Test; 14 | 15 | public class day6BigBasket { 16 | 17 | public ChromeDriver driver; 18 | public Actions action; 19 | 20 | //method to add items in cart 21 | public void addToCart(String product,Float price) 22 | { 23 | driver.findElementByXPath("(//a[contains(text(),'"+product+"')]/following::div[@class='delivery-opt']//button[contains(text(),'Add')])[1]").click(); 24 | if (driver.findElementByXPath("//div[@class='toast-title']").isDisplayed()) { 25 | System.out.println(product+ " added to cart succefully"); 26 | driver.findElementByClassName("toast-close-button").click();}} 27 | 28 | //method to validate the cart items with quantity 29 | public Float cartValidation(String product,Float price) { 30 | action.moveToElement(driver.findElementByXPath("//span[@title='Your Basket']")).pause(2000).perform(); 31 | String[] eachqty=driver.findElementByXPath("//div[@class='product-name']/a[contains(text(),'"+product+"')]/following::div[1]").getText().split(" "); 32 | int intqty=Integer.parseInt(eachqty[0]); 33 | Float Cartprice=intqty*price; 34 | System.out.println("The cart price of "+product+" is " +Cartprice); 35 | return Cartprice;} 36 | 37 | //method to validate total 38 | public Float carttotal(Float dal,Float rice,Float total) { 39 | if (dal+rice==total) 40 | {System.out.println("The cart total is validated");} 41 | else 42 | {System.out.println("There is mismatch in cart total");} 43 | return total;} 44 | 45 | @Test 46 | public void bigbasket() throws InterruptedException 47 | { 48 | //Go to https://www.bigbasket.com/ 49 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver_win32/chromedriver.exe"); 50 | driver=new ChromeDriver(); 51 | driver.get("https://www.bigbasket.com/"); 52 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 53 | driver.manage().window().maximize(); 54 | action=new Actions(driver); 55 | WebDriverWait wait=new WebDriverWait(driver,30); 56 | 57 | //handle location popup 58 | if(driver.findElementByXPath("//label[contains(text(),'You are seeing our catalogue in')]").isDisplayed()) 59 | { 60 | driver.findElementByXPath("//span[@class='close-btn']").click(); 61 | } 62 | 63 | //mouse over on Shop by Category.Go to FOODGRAINS, OIL & MASALA --> RICE & RICE PRODUCTS 64 | action.moveToElement(driver.findElementByXPath("//a[@class='dropdown-toggle meganav-shop']")).click().build().perform(); 65 | action.moveToElement(driver.findElementByXPath("(//a[text()='Foodgrains, Oil & Masala'])[2]")).pause(2000).perform(); 66 | action.moveToElement(driver.findElementByXPath("(//a[text()='Rice & Rice Products'])[2]")).perform(); 67 | action.moveToElement(driver.findElementByXPath("(//a[text()='Boiled & Steam Rice'])[2]")).click().build().perform(); 68 | 69 | //Choose the Brand as bb Royal 70 | driver.findElementByXPath("(//span[text()='bb Royal'])[1]").click(); 71 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[text()='bb Royal']"))); 72 | 73 | //Go to Ponni Boiled Rice - Super Premium and select 5kg bag from Dropdown 74 | Thread.sleep(3000); 75 | driver.findElementByXPath("//a[text()='Ponni Boiled Rice - Super Premium']/following::button[1]").click(); 76 | driver.findElementByXPath("//a[text()='Ponni Boiled Rice - Super Premium']/following::button[1]/following::span[text()='5 kg'][1]").click(); 77 | Float ricePrice=Float.parseFloat(driver.findElementByXPath("//a[text()='Ponni Boiled Rice - Super Premium']/following::span[@class='discnt-price'][1]/span").getText()); 78 | System.out.println("The price of rice is" +ricePrice); 79 | 80 | //Click Add button 81 | addToCart("Ponni Boiled Rice - Super Premium",ricePrice); 82 | Float cartricePrice=cartValidation("Ponni Boiled Rice - Super Premium",ricePrice); 83 | 84 | //Type Dal in Search field and enter 85 | driver.findElementByXPath("//input[@id='input']").sendKeys("Dal",Keys.ENTER); 86 | 87 | //Go to Toor/Arhar Dal and select 2kg & set Qty 2 88 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::button[1]"))); 89 | driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::button[1]").click(); 90 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::button[1]/following::span[text()='2 kg'][1]"))); 91 | driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::button[1]/following::span[text()='2 kg'][1]").click(); 92 | driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::input[@ng-model='vm.startQuantity'][1]").clear(); 93 | driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::input[@ng-model='vm.startQuantity'][1]").sendKeys("2"); 94 | 95 | //Print the price of Dal 96 | Float dalPrice=Float.parseFloat(driver.findElementByXPath("//a[text()='Toor/Arhar Dal/Thuvaram Paruppu']/following::span[@class='discnt-price'][1]/span").getText()); 97 | System.out.println("The price of Dal is "+dalPrice); 98 | 99 | 100 | //Click Add button 101 | addToCart("Toor/Arhar", dalPrice); 102 | Float cartdalPrice=cartValidation("Toor/Arhar", dalPrice); 103 | 104 | //Mouse hover on My Basket 105 | action.moveToElement(driver.findElementByXPath("//span[@title='Your Basket']")).pause(2000).perform(); 106 | 107 | 108 | //Validate the Sub Total displayed for the selected items 109 | Float totalPrice=Float.parseFloat(driver.findElementByXPath("//span[@qa='subTotalMB']").getText()); 110 | System.out.println("The subtotal in cart is " +totalPrice); 111 | //cart total validation 112 | System.out.println("The total amount of 1ricce and 2dal is " +carttotal(cartricePrice,cartdalPrice,totalPrice)); 113 | 114 | //Reduce the Quantity of Dal as 1 115 | action.moveToElement(driver.findElementByXPath("//span[@title='Your Basket']")).pause(2000).perform(); 116 | driver.findElementByXPath("//div[@class='product-name']/a[contains(text(),'Toor/Arhar')]/following::button[@qa='decQtyMB']").click(); 117 | Thread.sleep(3000); 118 | Float newtotalPrice=Float.parseFloat(driver.findElementByXPath("//span[@qa='subTotalMB']").getText()); 119 | System.out.println("The total in cart is " +newtotalPrice); 120 | 121 | //cart total validation 122 | Float newdalPrice=cartValidation("Toor/Arhar",dalPrice); 123 | System.out.println("The total amount of 1 rice and 1 dal is " +carttotal(cartricePrice,newdalPrice,newtotalPrice)); 124 | 125 | driver.close(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /day7scooter.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | import java.util.Set; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import org.openqa.selenium.By; 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.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.Select; 21 | import org.openqa.selenium.support.ui.WebDriverWait; 22 | import org.testng.annotations.Test; 23 | 24 | public class day7scooter { 25 | 26 | public float conversion(String data) 27 | { 28 | Float Displvalue=Float.parseFloat(data); 29 | return Displvalue; 30 | } 31 | 32 | @Test 33 | public void scooter() throws InterruptedException 34 | { 35 | 36 | //launch browser 37 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 38 | ChromeOptions options=new ChromeOptions(); 39 | options.addArguments("--disable-notifications"); 40 | 41 | DesiredCapabilities cap = new DesiredCapabilities(); 42 | cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS); 43 | options.merge(cap); 44 | 45 | ChromeDriver driver=new ChromeDriver(options); 46 | driver.manage().window().maximize(); 47 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 48 | WebDriverWait wait=new WebDriverWait(driver,30); 49 | 50 | //launch scooter url 51 | driver.get("https://www.honda2wheelersindia.com/"); 52 | 53 | try 54 | { 55 | if(driver.findElementByXPath("//div[@class='modal-content']").isDisplayed()) 56 | {driver.findElementByXPath("//button[@class='close']").click();} 57 | } 58 | 59 | catch(Exception e) 60 | { 61 | System.out.println("Pop up didnt appear"); 62 | } 63 | 64 | //Click on scooters and click dio 65 | driver.findElementByLinkText("Scooter").click(); 66 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']"))); 67 | driver.findElementByXPath("//img[@src='/assets/images/thumb/dioBS6-icon.png']").click(); 68 | 69 | //Click on Specifications and mouseover on ENGINE 70 | driver.findElementByLinkText("Specifications").click(); 71 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByLinkText("ELECTRICALS"))); 72 | 73 | Actions action=new Actions(driver); 74 | action.moveToElement(driver.findElementByLinkText("ENGINE")).click().build().perform(); 75 | 76 | //Get Displacement value 77 | String strdioDisplvalue=(driver.findElementByXPath("//span[text()='Displacement']/following-sibling::span").getText()).replaceAll("[a-z]", ""); 78 | System.out.println("The displacement value of DIO is " +strdioDisplvalue); 79 | Float dioDisplvalue=conversion(strdioDisplvalue); 80 | 81 | //Go to Scooters and click Activa 125 82 | driver.findElementByLinkText("Scooter").click(); 83 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']"))); 84 | driver.findElementByXPath("//img[@src='/assets/images/thumb/activa-125new-icon.png']").click(); 85 | 86 | //Click on Specifications and mouseover on ENGINE 87 | driver.findElementByLinkText("Specifications").click(); 88 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByLinkText("ELECTRICALS"))); 89 | action.moveToElement(driver.findElementByLinkText("ENGINE")).click().build().perform(); 90 | 91 | //Get Displacement value 92 | String strActivaDisplvalue=(driver.findElementByXPath("//span[text()='Displacement']/following-sibling::span").getText()).replaceAll("[a-z]", ""); 93 | System.out.println("The displacement value of Activa is " +strActivaDisplvalue); 94 | Float ActivaDisplvalue=conversion(strActivaDisplvalue); 95 | 96 | //Compare Displacement of Dio and Activa 125 and print the Scooter name having better Displacement. 97 | if(Float.compare(dioDisplvalue, ActivaDisplvalue)<0) 98 | { 99 | System.out.println("Activa displacement is better"); 100 | } 101 | else 102 | { 103 | System.out.println("Dio 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 | driver.findElementByLinkText("Activa 125 BS-VI").click(); 111 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//a[contains(text(),'Product Features')]"))); 112 | 113 | //Click Vehicle Price 114 | driver.findElementByXPath("//a[contains(text(),'Vehicle Price')]").click(); 115 | Thread.sleep(3000); 116 | //Make sure Activa 125 BS-VI selected and click submit 117 | Select select=new Select(driver.findElementById("ModelID6")); 118 | String selectedOption = select.getFirstSelectedOption().getText(); 119 | 120 | if (selectedOption.contains("Activa 125 BS-VI")) 121 | { 122 | System.out.println("Activa 125 BS-VI is selected"); 123 | driver.findElementByXPath("//select[@id='ModelID6']//following::button[1]").click(); 124 | } 125 | else 126 | { 127 | System.out.println("The selection is wrong"); 128 | } 129 | 130 | //click the price link 131 | driver.findElementByLinkText("Click here to know the price of Activa 125 BS-VI.").click(); 132 | 133 | //Go to the new Window and select the state as Tamil Nadu and city as Chennai 134 | 135 | Set windowHandles = driver.getWindowHandles(); 136 | List listwin=new ArrayList (windowHandles); 137 | driver.switchTo().window(listwin.get(1)); 138 | Select selectState=new Select(driver.findElementById("StateID")); 139 | selectState.selectByVisibleText("Tamil Nadu"); 140 | 141 | Select selectCity =new Select(driver.findElementById("CityID")); 142 | selectCity.selectByVisibleText("Chennai"); 143 | 144 | //Click Search 145 | driver.findElementByXPath("//button[text()='Search']").click(); 146 | 147 | //Print all the 3 models and their prices 148 | Map tableData=new LinkedHashMap(); 149 | List model = driver.findElementsByXPath("//table[@class='datashow']//tr//td[contains(text(),'ACT')]"); 150 | List price = driver.findElementsByXPath("//table[@class='datashow']//tr//td[contains(text(),'Rs')]"); 151 | 152 | 153 | 154 | for (int i=0;i<=model.size()-1;i++) 155 | { 156 | tableData.put(model.get(i).getText(), price.get(i).getText()); 157 | } 158 | 159 | for (Entry mapData : tableData.entrySet()) { 160 | System.out.println("The model is " +mapData.getKey() +"The price is " +mapData.getValue()); 161 | } 162 | 163 | driver.close(); 164 | 165 | }} 166 | -------------------------------------------------------------------------------- /day8pepperfry.java: -------------------------------------------------------------------------------- 1 | package Learnings.Extra; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 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.apache.commons.io.FileUtils; 11 | import org.openqa.selenium.By; 12 | import org.openqa.selenium.JavascriptExecutor; 13 | import org.openqa.selenium.Keys; 14 | import org.openqa.selenium.OutputType; 15 | import org.openqa.selenium.StaleElementReferenceException; 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.support.ui.ExpectedConditions; 20 | import org.openqa.selenium.support.ui.WebDriverWait; 21 | import org.testng.annotations.Test; 22 | 23 | public class day8pepperfry { 24 | 25 | public ChromeDriver driver; 26 | public String wishlistCount; 27 | public Actions mouse; 28 | 29 | public void mousehover(String Product,String subProd,String catProd) 30 | { 31 | mouse=new Actions(driver); 32 | mouse.moveToElement(driver.findElementByXPath("//a[text()='"+Product+"' and @class='level-top']")).pause(2000).perform(); 33 | driver.findElementByLinkText(catProd).click(); 34 | } 35 | 36 | public void wishlist(String ModelName) throws InterruptedException 37 | { 38 | 39 | driver.findElementByXPath("//a[contains(@title,'"+ModelName+"')]/following::a[contains(@data-productname,'"+ModelName+"')]").click(); 40 | Thread.sleep(3000); 41 | wishlistCount = driver.findElementByXPath("//div[@class='wishlist_bar']//span").getText(); 42 | 43 | } 44 | 45 | 46 | @Test 47 | public void pepperfry() throws IOException, InterruptedException 48 | { 49 | 50 | //Go to https://www.pepperfry.com/ 51 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 52 | ChromeOptions options= new ChromeOptions(); 53 | options.addArguments("--disable-notifications"); 54 | driver=new ChromeDriver(options); 55 | WebDriverWait wait=new WebDriverWait(driver,30); 56 | JavascriptExecutor Js=(JavascriptExecutor)driver; 57 | driver.manage().window().maximize(); 58 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 59 | driver.get("https://www.pepperfry.com/"); 60 | 61 | //Close the signup pop up 62 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//div[@class='reg-modal-right-frm-wrap'])[1]"))); 63 | driver.findElementByXPath("(//a[@class='popup-close'])[5]").click(); 64 | 65 | //Mouseover on Furniture and click Office Chairs under Chairs -Using method 66 | mousehover("Furniture","Chairs","Office Chairs"); 67 | 68 | //click Executive Chairs 69 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//h5[text()='Executive Chairs']"))); 70 | driver.findElementByXPath("//h5[text()='Executive Chairs']").click(); 71 | 72 | //Change the minimum Height as 50 in under Dimensions 73 | driver.findElementByXPath("//h2[contains(text(),'DIMENSION')]/following::input[1]").clear(); 74 | driver.findElementByXPath("//h2[contains(text(),'DIMENSION')]/following::input[1]").sendKeys("50",Keys.ENTER); 75 | 76 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@id='clipFilterCardContainer']//li[contains(text(),'Height')]"))); 77 | if(driver.findElementByXPath("//div[@id='clipFilterCardContainer']//li[contains(text(),'Height')]").isDisplayed()) 78 | { 79 | System.out.println("The height filter is applied successfully"); 80 | } 81 | 82 | //Add "Poise Executive Chair in Black Colour" chair to Wishlist 83 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("//a[text()='Poise Executive Chair in Black Colour']"))); 84 | String ChairName = driver.findElementByXPath("//a[text()='Poise Executive Chair in Black Colour']").getText(); 85 | System.out.println(ChairName.substring(0, 15)); 86 | wishlist(ChairName.substring(0, 15)); 87 | 88 | 89 | //Mouseover on Homeware and Click Pressure Cookers under Cookware 90 | mousehover("Homeware","Cookware","Pressure Cookers"); 91 | 92 | //Select Prestige as Brand 93 | driver.findElementByXPath("//label[text()='Prestige']").click(); 94 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//li[text()='Prestige']"))); 95 | 96 | //Select Capacity as 1-3 Ltr 97 | Thread.sleep(3000); 98 | driver.findElementByXPath("//label[@for='capacity_db1_Ltr_-_3_Ltr']").click(); 99 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//li[text()='1 Ltr - 3 Ltr']"))); 100 | 101 | if(driver.findElementByXPath("//li[text()='1 Ltr - 3 Ltr']").isDisplayed() & driver.findElementByXPath("//li[text()='Prestige']").isDisplayed()) 102 | { 103 | System.out.println("The filter Prestige and capacity is applied successfully"); 104 | } 105 | 106 | //Add "Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr" to Wishlist 107 | 108 | String CookerName = driver.findElementByXPath("//a[text()='Nakshatra Cute Metallic Red Aluminium Cooker 2 Ltr']").getText(); 109 | System.out.println(CookerName.substring(0, 14)); 110 | Thread.sleep(3000); 111 | wishlist(CookerName.substring(0, 14)); 112 | if (wishlistCount.equals("2")) 113 | { 114 | System.out.println("The number of items in wishlist is " +wishlistCount); 115 | } 116 | 117 | 118 | //Navigate to Wishlist 119 | driver.findElementByXPath("//div[@class='wishlist_bar']/a").click(); 120 | 121 | //Move Pressure Cooker only to Cart from Wishlist 122 | Thread.sleep(3000); 123 | Js.executeScript("arguments[0].scrollIntoView();",driver.findElementByXPath("//div[@id='cart_item_holder']//a[contains(text(),'Cooker')]/following::div[1]//a[contains(text(),'Add to Cart')]")); 124 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//div[@id='cart_item_holder']//a[contains(text(),'Cooker')]/following::div[1]//a[contains(text(),'Add to Cart')]"))); 125 | driver.findElementByXPath("//div[@id='cart_item_holder']//a[contains(text(),'Cooker')]/following::div[1]//a[contains(text(),'Add to Cart')]").click(); 126 | 127 | //Check for the availability for Pincode 600128 128 | Js.executeScript("arguments[0].scrollIntoView();",driver.findElementByClassName("srvc_pin_text")); 129 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("srvc_pin_text"))); 130 | driver.findElementByClassName("srvc_pin_text").sendKeys("600128"); 131 | driver.findElementByClassName("check_available").click(); 132 | wait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath("(//div[@id='cart_item_holder']//a[contains(text(),'Cooker')])[1]"))); 133 | 134 | if (driver.findElementByXPath("(//div[@class='minicart-error'])[1]").isDisplayed()) { 135 | System.out.println("The product is not delivered to your location");} 136 | 137 | else { 138 | //Js.executeScript("arguments[0].scrollIntoView();",driver.findElementByXPath("//a[text()='Proceed to pay securely ']")); 139 | //Click Proceed to Pay Securely 140 | wait.ignoring(StaleElementReferenceException.class).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(),'Proceed to pay securely')]"))); 141 | driver.findElementByXPath("//a[contains(text(),'Proceed to pay securely')]").click(); 142 | 143 | //mouse.moveToElement(driver.findElementByXPath("//a[contains(text(),'Proceed to pay securely')]")).click().build().perform(); 144 | 145 | //Click Proceed to Pay 146 | driver.findElementByLinkText("PLACE ORDER").click(); 147 | 148 | //Capture the screenshot of the item under Order Item 149 | wait.ignoring(StaleElementReferenceException.class).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='ORDER SUMMARY']"))); 150 | driver.findElementByXPath("//span[text()='ORDER SUMMARY']").click(); 151 | File screenShot = driver.findElementByXPath("//li[@data-slick-index='0']").getScreenshotAs(OutputType.FILE); 152 | FileUtils.copyFile(screenShot, new File("./screenshot/image.png")); 153 | 154 | } 155 | driver.close(); 156 | 157 | } 158 | 159 | } 160 | --------------------------------------------------------------------------------