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
89 changes: 61 additions & 28 deletions src/main/java/FlightBookingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,91 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.text.ParseException;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class FlightBookingTest {

WebDriver driver = new ChromeDriver();


WebDriver driver ;
FlightBookingTestElements fbte ;
WebDriverWait wait;
String srcCity = "Bangalore";
String destCity = "Delhi";
String day = "27";
String month = "October";
String year = "2020";

@BeforeTest
public void beforeTest() {
setDriverPath();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
fbte = new FlightBookingTestElements(driver);
wait = new WebDriverWait(driver, 10);

}
@Test
public void testThatResultsAppearForAOneWayJourney() {
public void testThatResultsAppearForAOneWayJourney() throws ParseException {

setDriverPath();
// setDriverPath();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
driver.get("https://www.cleartrip.com/");
waitFor(2000);
driver.findElement(By.id("OneWay")).click();
driver.manage().window().fullscreen();
// waitFor(2000);
fbte.oneWayElement().click();

driver.findElement(By.id("FromTag")).clear();
driver.findElement(By.id("FromTag")).sendKeys("Bangalore");
fbte.srcElement().clear();
fbte.srcElement().sendKeys(srcCity);
wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(fbte.sourceOptions, fbte.liTag));


//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"));
// waitFor(5000);
List<WebElement> originOptions = fbte.srcOptions();
originOptions.get(0).click();

waitFor(1000);

fbte.destElement().clear();
fbte.destElement().sendKeys(destCity);

driver.findElement(By.id("toTag")).clear();
driver.findElement(By.id("toTag")).sendKeys("Delhi");

wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(fbte.destOptions, fbte.liTag));
//wait for the auto complete options to appear for the destination

waitFor(2000);
//waitFor(5000);
//select the first item from the destination auto complete list
List<WebElement> destinationOptions = driver.findElement(By.id("ui-id-2")).findElements(By.tagName("li"));
List<WebElement> destinationOptions = fbte.destOptions();
destinationOptions.get(0).click();

driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/table/tbody/tr[3]/td[7]/a")).click();

// driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/table/tbody/tr[4]/td[7]/a")).click();
fbte.selectDate(year, month, day);
//all fields filled in. Now click on search
driver.findElement(By.id("SearchBtn")).click();
System.out.println(driver.findElement(fbte.calendar).getText());
if(fbte.searchElement().isEnabled() && fbte.srcElement().getText()!=null && fbte.destElement()!=null && driver.findElement(fbte.calendar).getText()!=null )
fbte.searchElement().click();

waitFor(5000);
// waitFor(5000);
//verify that result appears for the provided journey search
Assert.assertTrue(isElementPresent(By.className("searchSummary")));

//close the browser
driver.quit();


Assert.assertTrue(isElementPresent(fbte.seachSummary));
}

@AfterTest
public void afterTest()
{
driver.close();
driver.quit();
}

private void waitFor(int durationInMilliSeconds) {
try {
Expand All @@ -68,7 +101,7 @@ private void waitFor(int durationInMilliSeconds) {

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
wait.until(ExpectedConditions.presenceOfElementLocated(by));
return true;
} catch (NoSuchElementException e) {
return false;
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/FlightBookingTestElements.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class FlightBookingTestElements {
WebDriver driver;
By oneWay = By.id("OneWay");
By source = By.id("FromTag");
By destination = By.name("destination");
By sourceOptions = By.id("ui-id-1");
By destOptions = By.id("ui-id-2");
By liTag = By.tagName("li");
By searchBt = By.id("SearchBtn");
By seachSummary = By.className("searchSummary");
By calendar = By.xpath("//*[@id='ui-datepicker-div']");

public FlightBookingTestElements(WebDriver driver) {
this.driver = driver;
}

public WebElement oneWayElement()
{
return driver.findElement(oneWay);
}
public WebElement srcElement()
{
return driver.findElement(source);
}
public WebElement destElement()
{
return driver.findElement(destination);
}
public List<WebElement> srcOptions()
{
return driver.findElement(sourceOptions).findElements(liTag);
}
public List<WebElement> destOptions()
{
return driver.findElement(destOptions).findElements(liTag);
}
public WebElement searchElement()
{
return driver.findElement(searchBt);
}
public WebElement searchSumElement()
{
return driver.findElement(seachSummary);
}
public void selectDate(String year, String monthName, String day) throws ParseException
{
driver.findElement(calendar).click();

String currentYear= driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-year']")).getText();
// System.out.println(currentYear);
if(!currentYear.equals(year))
{
do{
driver.findElement(By.xpath("//a[@class='nextMonth ']")).click();
}while(!driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-year']")).getText().equals(year));

}

String currentMonth= driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-month']")).getText();
// System.out.println("mont;"+currentMonth);
if(!currentMonth.equalsIgnoreCase(monthName))
{
do{
driver.findElement(By.xpath("//a[@class='nextMonth ']")).click();
}while(!driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-month']")).getText().trim().equalsIgnoreCase(monthName));

}

int javaMonthInt= getMonthJavaInt(monthName);


List<WebElement> allDateOfDesiredMonth= driver.findElements(By.xpath("//div[@class='monthBlock first']/table/tbody[1]//td[(contains(@class,'undefined') and @data-month='"+javaMonthInt+"')]"));
for(WebElement d:allDateOfDesiredMonth )
{

if(d.getText().trim().equals(day))
{
System.out.println("date:"+d.getAttribute("data-month"));
System.out.println(d.findElement(By.className("ui-state-default")).getText());
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", d);
break;
}
}

}

public int getMonthJavaInt(String monthName) throws ParseException
{

Date date = new SimpleDateFormat("MMMM").parse(monthName);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.MONTH);
}

}
37 changes: 31 additions & 6 deletions src/main/java/HotelBookingTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import com.sun.javafx.PlatformUtil;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class HotelBookingTest {

WebDriver driver = new ChromeDriver();

WebDriver driver ;
@FindBy(linkText = "Hotels")
private WebElement hotelLink;

Expand All @@ -21,23 +28,41 @@ public class HotelBookingTest {

@FindBy(id = "travellersOnhome")
private WebElement travellerSelection;

@BeforeTest
public void beforeTest() {
setDriverPath();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);

PageFactory.initElements(driver, this);
}

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

// setDriverPath();

driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
driver.get("https://www.cleartrip.com/");
driver.manage().window().fullscreen();

hotelLink.click();

localityTextBox.sendKeys("Indiranagar, Bangalore");

new Select(travellerSelection).selectByVisibleText("1 room, 2 adults");
searchButton.click();

driver.quit();

}

@AfterTest
public void afterTest()
{
driver.close();
driver.quit();
}

private void setDriverPath() {
if (PlatformUtil.isMac()) {
System.setProperty("webdriver.chrome.driver", "chromedriver");
Expand Down
59 changes: 45 additions & 14 deletions src/main/java/SignInTest.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
import com.sun.javafx.PlatformUtil;
import java.util.concurrent.TimeUnit;

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.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class SignInTest {
import com.sun.javafx.PlatformUtil;

WebDriver driver = new ChromeDriver();
public class SignInTest {

WebDriver driver ;
SignInTestElements sine;

@BeforeTest
public void beforeTest() {
setDriverPath();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
sine = new SignInTestElements(driver);
}
@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.manage().window().fullscreen();
driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// waitFor(2000);

//driver.findElement(By.linkText("Your trips")).click();
sine.yourTripsElement().click();
//driver.findElement(By.id("SignIn")).click();
sine.signInElement().click();

driver.findElement(By.id("signInButton")).click();

String errors1 = driver.findElement(By.id("errors1")).getText();
//driver.findElement(By.id("signInButton")).click();
driver.switchTo().frame(sine.iFrameElement());
sine.signInButtonElement().click();

String errors1 = sine.errorMsgElement().getText();
Assert.assertTrue(errors1.contains("There were errors in your submission"));
driver.quit();

driver.switchTo().parentFrame();
}

@AfterTest
public void afterTest()
{
driver.close();
driver.quit();
}

private void waitFor(int durationInMilliSeconds) {
Expand All @@ -35,7 +65,8 @@ private void waitFor(int durationInMilliSeconds) {
}
}

private void setDriverPath() {
@SuppressWarnings("restriction")
private void setDriverPath() {
if (PlatformUtil.isMac()) {
System.setProperty("webdriver.chrome.driver", "chromedriver");
}
Expand Down
Loading