Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
92 changes: 92 additions & 0 deletions FlightBookingTest.java
Original file line number Diff line number Diff line change
@@ -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<WebElement> 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<WebElement> 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");
}
}
}
55 changes: 55 additions & 0 deletions HotelBookingTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}

}
55 changes: 55 additions & 0 deletions SignInTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}


}