diff --git a/.gitignore b/.gitignore index 0275ff56..081a08f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build .idea -.gradle \ No newline at end of file +.gradle +/out \ No newline at end of file diff --git a/chromedriver.exe b/chromedriver.exe index 4bfff1ef..244efd40 100755 Binary files a/chromedriver.exe and b/chromedriver.exe differ diff --git a/src/main/java/Credentials.java b/src/main/java/Credentials.java new file mode 100644 index 00000000..11918932 --- /dev/null +++ b/src/main/java/Credentials.java @@ -0,0 +1,18 @@ +public class Credentials { + + private String username; + private String password; + + public Credentials() { + username = "test@testing.com"; + password = "password@123"; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } +} diff --git a/src/main/java/FlightBookingTest.java b/src/main/java/FlightBookingTest.java index 19d98ddf..89c9441b 100644 --- a/src/main/java/FlightBookingTest.java +++ b/src/main/java/FlightBookingTest.java @@ -56,6 +56,27 @@ public void testThatResultsAppearForAOneWayJourney() { } + @Test + public void testThatResultsAppearForRecentSearches() { + + setDriverPath(); + driver.get("https://www.cleartrip.com/"); + waitFor(2000); + + //results for all recent searches + List recentSearches = driver.findElements(By.cssSelector("#RecentSearch li")); + + //Click on the first recent search + recentSearches.get(0).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 { diff --git a/src/main/java/HotelBookingTest.java b/src/main/java/HotelBookingTest.java index 2be026bb..2ab2fe2a 100644 --- a/src/main/java/HotelBookingTest.java +++ b/src/main/java/HotelBookingTest.java @@ -4,8 +4,11 @@ import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; +import org.testng.Assert; import org.testng.annotations.Test; +import java.util.List; + public class HotelBookingTest { WebDriver driver = new ChromeDriver(); @@ -22,6 +25,12 @@ public class HotelBookingTest { @FindBy(id = "travellersOnhome") private WebElement travellerSelection; + @FindBy(css = ".starFilter input[value='5']") + private WebElement fiveStarFilter; + + @FindBy(css = ".hotelsList li .metaData.clearFix span[class*='starRating']") + private List filteredHotelsRating; + @Test public void shouldBeAbleToSearchForHotels() { setDriverPath(); @@ -38,6 +47,37 @@ public void shouldBeAbleToSearchForHotels() { } + @Test + public void shouldBeAbleToFilterFiveStarHotels() { + setDriverPath(); + + driver.get("https://www.cleartrip.com/"); + hotelLink.click(); + + localityTextBox.sendKeys("Indiranagar, Bangalore"); + + new Select(travellerSelection).selectByVisibleText("1 room, 2 adults"); + searchButton.click(); + + waitFor(5000); + + fiveStarFilter.click(); + + waitFor(2000); + + Assert.assertTrue(filteredHotelsRating.get(0).getAttribute("Title").contains("5")); + + 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"); diff --git a/src/main/java/SignInTest.java b/src/main/java/SignInTest.java index 2c109950..0f2dd382 100644 --- a/src/main/java/SignInTest.java +++ b/src/main/java/SignInTest.java @@ -7,7 +7,8 @@ public class SignInTest { - WebDriver driver = new ChromeDriver(); + WebDriver driver; + Credentials creds; @Test public void shouldThrowAnErrorIfSignInDetailsAreMissing() { @@ -27,6 +28,29 @@ public void shouldThrowAnErrorIfSignInDetailsAreMissing() { driver.quit(); } + @Test + public void shouldThrowAnErrorIfSignInWithInvalidCredentials() { + + setDriverPath(); + driver.get("https://www.cleartrip.com/"); + waitFor(2000); + + driver.findElement(By.linkText("Your trips")).click(); + waitFor(2000); + driver.findElement(By.id("SignIn")).click(); + + waitFor(3000); + + driver.findElement(By.id("email")).sendKeys(creds.getUsername()); + driver.findElement(By.id("password")).sendKeys(creds.getPassword()); + + driver.findElement(By.id("signInButton")).click(); + + 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);