Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
.idea
.gradle
.gradle
/target/
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>codoingRound</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Binary file modified chromedriver.exe
Binary file not shown.
61 changes: 14 additions & 47 deletions src/main/java/FlightBookingTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.codoingRoiund.utils.WaitForElement;
import com.codoingRound.BasePage.BaseObject;
import com.sun.javafx.PlatformUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
Expand All @@ -10,34 +12,31 @@

import java.util.List;

public class FlightBookingTest {

WebDriver driver = new ChromeDriver();
public class FlightBookingTest extends BaseObject {

WaitForElement wait = new WaitForElement();

@Test
public void testThatResultsAppearForAOneWayJourney() {

setDriverPath();
driver.get("https://www.cleartrip.com/");
waitFor(2000);
driver.findElement(By.id("OneWay")).click();
if(!driver.findElement(By.id("OneWay")).isSelected())
{
driver.findElement(By.id("OneWay")).click();
}

driver.findElement(By.id("FromTag")).clear();
driver.findElement(By.id("FromTag")).sendKeys("Bangalore");
driver.findElement(By.xpath("//input[@id='FromTag']")).clear();
driver.findElement(By.xpath("//input[@id='FromTag']")).sendKeys("Bangalore");

//wait for the auto complete options to appear for the origin

waitFor(2000);
List<WebElement> 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");
driver.findElement(By.xpath("//input[@id='ToTag']")).clear();
driver.findElement(By.xpath("//input[@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<WebElement> destinationOptions = driver.findElement(By.id("ui-id-2")).findElements(By.tagName("li"));
destinationOptions.get(0).click();
Expand All @@ -47,43 +46,11 @@ public void testThatResultsAppearForAOneWayJourney() {
//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.
}
}
//verify that result appears for the provided journey search
Assert.assertTrue(wait.isElementPresent(By.className("searchSummary")));


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");
}
}
}
55 changes: 16 additions & 39 deletions src/main/java/HotelBookingTest.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,30 @@
import com.codoingRoiund.utils.WaitForElement;
import com.codoingRoiund.utils.pageRepo;
import com.codoingRound.BasePage.BaseObject;
import com.sun.javafx.PlatformUtil;

import org.openqa.selenium.By;
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 class HotelBookingTest extends BaseObject {
pageRepo pr = new pageRepo();
WaitForElement wait = new WaitForElement();

@Test
public void shouldBeAbleToSearchForHotels() {
setDriverPath();

driver.get("https://www.cleartrip.com/");
hotelLink.click();

localityTextBox.sendKeys("Indiranagar, Bangalore");

wait.elementToAppear("//li[contains(@class,'hotelApp')]//a[contains(text(),'Hotels')]", 20);
pr.hotels().click();

new Select(travellerSelection).selectByVisibleText("1 room, 2 adults");
searchButton.click();
pr.hotelSearch().sendKeys("Indiranagar, Bangalore");

driver.quit();
new Select(pr.travellers()).selectByVisibleText("1 room, 2 adults");
pr.searchHotels().click();

}

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");
}
}

}
49 changes: 19 additions & 30 deletions src/main/java/SignInTest.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
import com.codoingRoiund.utils.WaitForElement;
import com.codoingRound.BasePage.BaseObject;
import com.sun.javafx.PlatformUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class SignInTest {
public class SignInTest extends BaseObject {

WebDriver driver = new ChromeDriver();

@Test
public void shouldThrowAnErrorIfSignInDetailsAreMissing() {

setDriverPath();

driver.get("https://www.cleartrip.com/");
waitFor(2000);
public void shouldThrowAnErrorIfSignInDetailsAreMissing() throws Exception {

WaitForElement wait = new WaitForElement();

driver.findElement(By.linkText("Your trips")).click();
driver.findElement(By.id("SignIn")).click();


int size = driver.findElements(By.tagName("iframe")).size();
wait.waitFor(5000);

WebElement fr=driver.findElement(By.xpath("//iframe[@class='spinnerMedium']"));
driver.switchTo().defaultContent();
driver.switchTo().frame(fr);

// wait.elementToAppear("//button[@id='signInButton']", 20);
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();
System.out.println("Error : "+errors1);
Assert.assertEquals(errors1, "There were errors in your submission\nYour username is a required field\nYour account password is a required field");
}

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");
}
}



}
37 changes: 37 additions & 0 deletions src/main/java/com/codoingRoiund/utils/WaitForElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.codoingRoiund.utils;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.codoingRound.BasePage.BaseObject;

public class WaitForElement extends BaseObject{
WebDriverWait wait ;

public void elementToAppear(String xpath, int timeInSeconds) {
wait = new WebDriverWait(driver, timeInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));

}

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 boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

}
50 changes: 50 additions & 0 deletions src/main/java/com/codoingRoiund/utils/pageRepo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.codoingRoiund.utils;

import java.sql.Driver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.codoingRound.BasePage.BaseObject;

public class pageRepo extends BaseObject{
WebElement element;

public WebElement hotels() {
try {
element = driver.findElement(By.xpath("//li[contains(@class,'hotelApp')]//a[contains(text(),'Hotels')]"));
} catch (Exception e) {
System.out.println("Hotels Icon not found");
}
return element;
}

public WebElement hotelSearch() {
try {
element = driver.findElement(By.xpath("//input[@id='Tags']"));
} catch (Exception e) {
System.out.println("Hotels search Icon not found");
}
return element;
}

public WebElement travellers() {
try {
element = driver.findElement(By.xpath("//select[@id='travellersOnhome']"));
} catch (Exception e) {
System.out.println("Travellers Icon not found");
}
return element;
}

public WebElement searchHotels() {
try {
element = driver.findElement(By.xpath("//input[@id='SearchHotelsButton']"));
} catch (Exception e) {
System.out.println("Search Hotels Icon not found");
}
return element;
}

}
Loading