diff --git a/.classpath b/.classpath new file mode 100644 index 00000000..226c7f7a --- /dev/null +++ b/.classpath @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index 0275ff56..98a6bc15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build .idea -.gradle \ No newline at end of file +.gradle +/target/ diff --git a/.project b/.project new file mode 100644 index 00000000..98fd637a --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + codingRound + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..91ca62e2 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/java/FlightBookingTest.java b/src/main/java/FlightBookingTest.java index 19d98ddf..94bde1f3 100644 --- a/src/main/java/FlightBookingTest.java +++ b/src/main/java/FlightBookingTest.java @@ -1,89 +1,34 @@ -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.AfterClass; import org.testng.annotations.Test; -import java.util.List; - -public class FlightBookingTest { - - WebDriver driver = new ChromeDriver(); +import codingRound.Pages.FlightBooking_Page; +import codingRound.Utilities.Page; +public class FlightBookingTest extends Page { @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(); - 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(); - 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(); - - driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/table/tbody/tr[3]/td[7]/a")).click(); - + public void testThatResultsAppearForAOneWayJourney() { + + new Page().homePage(); + + new Page().waitFor(2000); + new FlightBooking_Page().selectJourneyType(); //all fields filled in. Now click on search - driver.findElement(By.id("SearchBtn")).click(); - - waitFor(5000); + new FlightBooking_Page().selectOrigin(); + new FlightBooking_Page().selectDestination(); + new FlightBooking_Page().searchFlight(); + new Page().waitFor(5000); //verify that result appears for the provided journey search - Assert.assertTrue(isElementPresent(By.className("searchSummary"))); - - //close the browser - driver.quit(); + + new FlightBooking_Page().verifySummary(); } + - - 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. - } + @AfterClass + public void endTest() { + driver.quit(); } + - - 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/src/main/java/HotelBookingTest.java b/src/main/java/HotelBookingTest.java index 2be026bb..743e9308 100644 --- a/src/main/java/HotelBookingTest.java +++ b/src/main/java/HotelBookingTest.java @@ -1,53 +1,24 @@ -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.AfterClass; import org.testng.annotations.Test; -public class HotelBookingTest { - WebDriver driver = new ChromeDriver(); +import codingRound.Pages.HotelBooking_Page; +import codingRound.Utilities.Page; - @FindBy(linkText = "Hotels") - private WebElement hotelLink; - - @FindBy(id = "Tags") - private WebElement localityTextBox; - - @FindBy(id = "SearchHotelsButton") - private WebElement searchButton; - - @FindBy(id = "travellersOnhome") - private WebElement travellerSelection; +public class HotelBookingTest extends Page{ @Test public void shouldBeAbleToSearchForHotels() { - setDriverPath(); - - driver.get("https://www.cleartrip.com/"); - hotelLink.click(); - - localityTextBox.sendKeys("Indiranagar, Bangalore"); - - 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"); + + new Page().homePage(); + new HotelBooking_Page().searchHotel(); + } + + @AfterClass + public void endTest() { + driver.quit(); } + } diff --git a/src/main/java/SignInTest.java b/src/main/java/SignInTest.java index 2c109950..5d8685dd 100644 --- a/src/main/java/SignInTest.java +++ b/src/main/java/SignInTest.java @@ -1,51 +1,29 @@ -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.AfterClass; import org.testng.annotations.Test; -public class SignInTest { +import codingRound.Pages.SignIn_Page; +import codingRound.Utilities.Page; - WebDriver driver = new ChromeDriver(); +public class SignInTest extends Page{ + @Test public void shouldThrowAnErrorIfSignInDetailsAreMissing() { - - setDriverPath(); - - driver.get("https://www.cleartrip.com/"); - waitFor(2000); - - driver.findElement(By.linkText("Your trips")).click(); - driver.findElement(By.id("SignIn")).click(); - - 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(); + new Page().homePage(); + + + new SignIn_Page().signIn(); + + new SignIn_Page().verifySubmission(); + } - 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. - } + @AfterClass + public void endTest() { + 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/src/main/java/codingRound/Utilities/Page.java b/src/main/java/codingRound/Utilities/Page.java new file mode 100644 index 00000000..852ef683 --- /dev/null +++ b/src/main/java/codingRound/Utilities/Page.java @@ -0,0 +1,56 @@ +package codingRound.Utilities; + +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +import com.sun.javafx.PlatformUtil; + +public class Page { + public static WebDriver driver; + + Page (WebDriver driver) { + this.driver = new ChromeDriver(); + setDriverPath(); + } + + public Page() { + // TODO Auto-generated constructor stub + } + + public void waitFor(int durationInMilliSeconds) { + try { + Thread.sleep(durationInMilliSeconds); + } catch (InterruptedException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + + + public 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"); + } + } + + protected boolean isElementPresent(By by) { + try { + driver.findElement(by); + return true; + } catch (NoSuchElementException e) { + return false; + } + } + + public void homePage() { + driver.get("https://www.cleartrip.com/"); + + } +}