diff --git a/FlightBookingTest.java b/FlightBookingTest.java new file mode 100644 index 00000000..1e8c43ae --- /dev/null +++ b/FlightBookingTest.java @@ -0,0 +1,92 @@ +import com.sun.javafx.PlatformUtil; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.Select; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.List; + +public class FlightBookingTest { + + WebDriver driver = new ChromeDriver(); + + + @Test + public void testThatResultsAppearForAOneWayJourney() { + + setDriverPath(); + driver.get("https://www.cleartrip.com/"); + waitFor(2000); + driver.findElement(By.id("OneWay")).click(); + + driver.findElement(By.id("FromTag")).clear(); + //hard coding is done which is not considered as a good practice. So, data should be kept in a file and pick the value from that file itself. + driver.findElement(By.id("FromTag")).sendKeys("Bangalore"); + + //wait for the auto complete options to appear for the origin + + waitFor(2000); + List originOptions = driver.findElement(By.id("ui-id-1")).findElements(By.tagName("li")); + originOptions.get(0).click(); + + driver.findElement(By.id("toTag")).clear(); + //hard coding is done which is not considered as a good practice. So, data should be kept in a file and pick the value from that file itself. + driver.findElement(By.id("toTag")).sendKeys("Delhi"); + + //wait for the auto complete options to appear for the destination + + waitFor(2000); + //select the first item from the destination auto complete list + List destinationOptions = driver.findElement(By.id("ui-id-2")).findElements(By.tagName("li")); + destinationOptions.get(0).click(); + + //the below mentioned xpath gives the value of the 7th column of 3rd row and is valid only when the current date is less than this element, So here a proper function for selecting the date should be implemented. + driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/table/tbody/tr[3]/td[7]/a")).click(); + + //all fields filled in. Now click on search + driver.findElement(By.id("SearchBtn")).click(); + + waitFor(5000); + //verify that result appears for the provided journey search + Assert.assertTrue(isElementPresent(By.className("searchSummary"))); + + //close the browser + driver.quit(); + + } + + + private void waitFor(int durationInMilliSeconds) { + try { + Thread.sleep(durationInMilliSeconds); + } catch (InterruptedException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + + + private boolean isElementPresent(By by) { + try { + driver.findElement(by); + return true; + } catch (NoSuchElementException e) { + return false; + } + } + + private void setDriverPath() { + if (PlatformUtil.isMac()) { + System.setProperty("webdriver.chrome.driver", "chromedriver"); + } + if (PlatformUtil.isWindows()) { + System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); + } + if (PlatformUtil.isLinux()) { + System.setProperty("webdriver.chrome.driver", "chromedriver_linux"); + } + } +} diff --git a/HotelBookingTest.java b/HotelBookingTest.java new file mode 100644 index 00000000..93064395 --- /dev/null +++ b/HotelBookingTest.java @@ -0,0 +1,55 @@ +import com.sun.javafx.PlatformUtil; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.Select; +import org.testng.annotations.Test; + +public class HotelBookingTest { + + WebDriver driver = new ChromeDriver(); + + @FindBy(linkText = "Hotels") + private WebElement hotelLink; + + @FindBy(id = "Tags") + private WebElement localityTextBox; + + @FindBy(id = "SearchHotelsButton") + private WebElement searchButton; + + @FindBy(id = "travellersOnhome") + private WebElement travellerSelection; + + @Test + public void shouldBeAbleToSearchForHotels() { + setDriverPath(); + + driver.get("https://www.cleartrip.com/"); + hotelLink.click(); + + //hard coding is done which is not considered as a good practice. So, data should be kept in a file and pick the value from that file itself. + localityTextBox.sendKeys("Indiranagar, Bangalore"); + + //hard coding is done which is not considered as a good practice. So, data should be kept in a file and pick the value from that file itself. + new Select(travellerSelection).selectByVisibleText("1 room, 2 adults"); + searchButton.click(); + + driver.quit(); + + } + + private void setDriverPath() { + if (PlatformUtil.isMac()) { + System.setProperty("webdriver.chrome.driver", "chromedriver"); + } + if (PlatformUtil.isWindows()) { + System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); + } + if (PlatformUtil.isLinux()) { + System.setProperty("webdriver.chrome.driver", "chromedriver_linux"); + } + } + +} diff --git a/SignInTest.java b/SignInTest.java new file mode 100644 index 00000000..f5c5972c --- /dev/null +++ b/SignInTest.java @@ -0,0 +1,55 @@ +import com.sun.javafx.PlatformUtil; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class SignInTest { + + WebDriver driver = new ChromeDriver(); + + @Test + public void shouldThrowAnErrorIfSignInDetailsAreMissing() { + + setDriverPath(); + + driver.get("https://www.cleartrip.com/"); + waitFor(2000); + + driver.findElement(By.linkText("Your trips")).click(); + waitFor(1000); + driver.findElement(By.id("SignIn")).click(); + waitFor(2000); + + driver.switchTo().frame("modal_window"); + driver.findElement(By.id("signInButton")).click(); + waitFor(2000); + + String errors1 = driver.findElement(By.id("errors1")).getText(); + Assert.assertTrue(errors1.contains("There were errors in your submission")); + driver.quit(); + } + + private void waitFor(int durationInMilliSeconds) { + try { + Thread.sleep(durationInMilliSeconds); + } catch (InterruptedException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + + private void setDriverPath() { + if (PlatformUtil.isMac()) { + System.setProperty("webdriver.chrome.driver", "chromedriver"); + } + if (PlatformUtil.isWindows()) { + System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); + } + if (PlatformUtil.isLinux()) { + System.setProperty("webdriver.chrome.driver", "chromedriver_linux"); + } + } + + +}