├── Day1 ├── Day3_MakeMyTrip.java └── Myntra_WishList.java /Day1: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Day3_MakeMyTrip.java: -------------------------------------------------------------------------------- 1 | package test.exercise; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.WebDriver; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.chrome.ChromeDriver; 12 | import org.openqa.selenium.support.ui.ExpectedConditions; 13 | import org.openqa.selenium.support.ui.Select; 14 | import org.openqa.selenium.support.ui.WebDriverWait; 15 | 16 | public class Day3_MakeMyTrip { 17 | 18 | public static void main(String[] args) throws InterruptedException 19 | { 20 | // 1) Go to https://www.makemytrip.com/ 21 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 22 | ChromeDriver driver = new ChromeDriver(); 23 | driver.manage().window().maximize(); 24 | driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS); 25 | driver.get("https://www.makemytrip.com/"); 26 | 27 | // 2) Click Hotels 28 | driver.findElementByXPath("//a[@class='makeFlex hrtlCenter column']").click(); 29 | 30 | // 3) Enter city as Goa, and choose Goa, India 31 | driver.findElementByXPath("//input[@id='city']").click(); 32 | Thread.sleep(2000); 33 | driver.findElementByXPath("//input[@class='react-autosuggest__input react-autosuggest__input--open']").sendKeys("Goa"); 34 | driver.findElementByXPath("//p[contains(text(),'Goa, India')]").click(); 35 | 36 | // 4) Enter Check in date as Next month 15th (May 15) and Check out as start date+5 37 | driver.findElementById("checkin").click(); 38 | driver.findElementByXPath("(//div[text()='15'])[2]").click(); 39 | String checkin = driver.findElementByXPath("(//div[text()='15'])[2]").getText(); 40 | System.out.println(checkin); 41 | int startDate = Integer.parseInt(checkin); 42 | WebElement currentMonth = driver.findElementByXPath("(//div[@class='DayPicker-Month'])[2]"); 43 | currentMonth.findElement(By.xpath("(//div[text()='"+(startDate+5)+"'])[2]")).click(); 44 | 45 | // 5) Click on ROOMS & GUESTS and click 2 Adults and one Children(age 12). Click Apply Button. 46 | driver.findElementByXPath("//input[@id='guest']").click(); 47 | driver.findElementByXPath("//ul[@data-cy='adultCount']//li[text()=2]").click(); 48 | driver.findElementByXPath("//p[@data-cy='childrenRange']/following::ul/li[text()=1]").click(); 49 | WebElement ele = driver.findElementByClassName("ageSelectBox"); 50 | Select dd= new Select(ele); 51 | dd.selectByVisibleText("12"); 52 | driver.findElementByXPath("//button[text()='APPLY']").click(); 53 | 54 | // 6) Click Search button 55 | driver.findElementByXPath("//button[text()='Search']").click(); 56 | 57 | // 7) Select locality as Baga 58 | if(driver.findElementByXPath("//div[contains(@class, 'mmBackdrop wholeBlack')]").isDisplayed()) 59 | driver.findElementByXPath("//div[contains(@class, 'mmBackdrop wholeBlack')]").click(); 60 | driver.findElementByXPath("//div[@class='locationFtrModal']//label[contains(text(),'Baga')]").click(); 61 | 62 | 63 | // 8) Select 5 start in Star Category under Select Filters 64 | WebDriverWait wait = new WebDriverWait(driver, 30); 65 | wait.until(ExpectedConditions.visibilityOf( driver.findElementByXPath("//div[text()='Star Category']/following::ul//label[text()='5 Star']"))); 66 | Thread.sleep(2000); 67 | driver.findElementByXPath("//div[text()='Star Category']/following::ul//label[text()='5 Star']").click(); 68 | 69 | // 9) Click on the first resulting hotel and go to the new window 70 | driver.findElementByXPath("(//div[@class='makeFlex spaceBetween']/div)[1]").click(); 71 | Set resultSet = driver.getWindowHandles(); 72 | List lst = new ArrayList(resultSet); 73 | driver.switchTo().window(lst.get(1)); 74 | 75 | // 10) Print the Hotel Name 76 | String hotelName = driver.findElementById("detpg_hotel_name").getText(); 77 | System.out.println("Hotel name is "+ hotelName); 78 | 79 | // 11) Click MORE OPTIONS link and Select 3Months plan and close 80 | driver.findElementByXPath("//span[text()='MORE OPTIONS']").click(); 81 | Thread.sleep(3000); 82 | driver.findElementByXPath("(//span[text()='SELECT'])[1]").click(); 83 | driver.findElementByXPath("//span[@class='close']").click(); 84 | 85 | // 12) Click on BOOK THIS NOW 86 | driver.findElementByXPath("//a[text()='BOOK THIS NOW']").click(); 87 | System.out.println("Book now button clicked"); 88 | 89 | // 13) Print the Total Payable amount 90 | String totalAmount = driver.findElementById("revpg_total_payable_amt").getText(); 91 | System.out.println("Total Payable AMount: "+totalAmount); 92 | 93 | // 14) Close the browser 94 | driver.quit(); 95 | 96 | 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /Myntra_WishList.java: -------------------------------------------------------------------------------- 1 | package test.exercise; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.openqa.selenium.interactions.Actions; 8 | import org.openqa.selenium.support.ui.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | 11 | public class Myntra_WishList { 12 | 13 | public static void main(String[] args) throws InterruptedException 14 | { 15 | //1) Open https://www.myntra.com/ 16 | System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe"); 17 | ChromeDriver driver = new ChromeDriver(); 18 | driver.get("https://www.myntra.com"); 19 | driver.manage().window().maximize(); 20 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 21 | 22 | //2) Mouse over on WOMEN (Actions -> moveToElement 23 | Actions action = new Actions(driver); 24 | action.moveToElement(driver.findElementByXPath("(//a[text()='Women'])[1]")).build().perform(); 25 | Thread.sleep(2000); 26 | 27 | //3) Click Jackets & Coats 28 | WebDriverWait wait = new WebDriverWait(driver,30); 29 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//a[text()='Jackets & Coats'])[1]"))); 30 | driver.findElementByXPath("(//a[text()='Jackets & Coats'])[1]").click(); 31 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 32 | 33 | //4) Find the total count of item (top) -> getText -> String 34 | String str = driver.findElementByClassName("title-count").getText(); 35 | String text = str.replaceAll("\\D",""); 36 | int intTotalCountOfItem = Integer.parseInt(text); 37 | 38 | //5) Validate the sum of categories count matches 39 | WebElement category_Jacket = driver.findElementByXPath("(//ul[@class='categories-list']//span[@class='categories-num'])[1]"); 40 | WebElement category_Coats = driver.findElementByXPath("(//ul[@class='categories-list']//span[@class='categories-num'])[2]"); 41 | int intcategory_Jacket = Integer.parseInt(category_Jacket.getText().replaceAll("\\D", "")); 42 | int intcategory_Coats = Integer.parseInt(category_Coats.getText().replaceAll("\\D", "")); 43 | if((intcategory_Jacket+intcategory_Coats)==intTotalCountOfItem) 44 | { 45 | System.out.println("Count matches"); 46 | } 47 | else 48 | { 49 | System.out.println("Count is not matched"); 50 | } 51 | 52 | //6) Check coats: 53 | driver.findElementByXPath("//label[text()='Coats']//div").click(); 54 | Thread.sleep(2000); 55 | 56 | //7) Click + More option under BRAND Click more under brand 57 | driver.findElementByXPath("//div[@class='brand-more']").click(); 58 | Thread.sleep(2000); 59 | 60 | //8) Type MANGO and click checkbox 61 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//input[@class='FilterDirectory-searchInput']"))); 62 | driver.findElementByXPath("//input[@class='FilterDirectory-searchInput']").sendKeys("MANGO"); 63 | 64 | driver.findElementByXPath("//span[@class='FilterDirectory-count']/following-sibling::div").click(); 65 | 66 | //9) Close the pop-up x 67 | driver.findElementByXPath("//span[contains(@class,'myntraweb-sprite FilterDirectory-close')]").click(); 68 | 69 | //10) Confirm all the Coats are of brand MANGO 70 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//ul[@class='results-base']//h3[@class='product-brand'])[1]"))); 71 | List lst = driver.findElementsByXPath("//ul[@class='results-base']//h3[@class='product-brand']"); 72 | boolean bool_IfAnyNotMango = false; 73 | for(WebElement ele:lst) 74 | { 75 | //wait.until(ExpectedConditions.visibilityOf(ele)); 76 | if(!ele.getText().equalsIgnoreCase("MANGO")) 77 | { 78 | bool_IfAnyNotMango = true; 79 | } 80 | 81 | } 82 | if(bool_IfAnyNotMango==false) 83 | { 84 | System.out.println("All Mango brands are only displayed"); 85 | } 86 | 87 | //11) Sort by Better Discount 88 | action.moveToElement(driver.findElementByXPath("//div[@class='sort-sortBy']")).build().perform(); 89 | action.moveToElement(driver.findElementByXPath("//label[text()='Better Discount']")).click().perform(); 90 | 91 | 92 | //12) Find the price of first displayed item 93 | wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("(//ul[@class='results-base']//span[@class='product-discountedPrice'])[1]"))); 94 | String text_Price = driver.findElementByXPath("(//ul[@class='results-base']//span[@class='product-discountedPrice'])[1]").getText(); 95 | String text_PriceAlone = text_Price.replaceAll("\\D",""); 96 | int intPrice = Integer.parseInt(text_PriceAlone); 97 | System.out.println("Price of first displayed item - "+intPrice); 98 | 99 | //13) Mouse over on size of the first item 100 | action.moveToElement(driver.findElementByXPath("(//h4[@class='product-product'])[1]")).build().perform(); 101 | 102 | //14) Click on WishList Now 103 | driver.findElementByXPath("(//ul[@class='results-base']//span[@class='product-actionsButton product-wishlist product-prelaunchBtn'])[1]").click(); 104 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 105 | 106 | // 15) Close Browser 107 | if(driver.getTitle().equalsIgnoreCase("Login")) 108 | { 109 | driver.close(); 110 | } 111 | 112 | 113 | } 114 | 115 | 116 | } 117 | --------------------------------------------------------------------------------