-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathFlightBookingTest.java
More file actions
134 lines (99 loc) · 3.88 KB
/
FlightBookingTest.java
File metadata and controls
134 lines (99 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
public class FlightBookingTest {
static WebDriver driver = new ChromeDriver();
@FindBy(id = "OneWay")
private WebElement radio_oneWay;
@FindBy(id = "FromTag")
private WebElement txtbox_from;
@FindBy(css = "ul#ui-id-1>li.list>a")
private List<WebElement> lnk_autoSuggestionsOriginTxtBx;
@FindBy(css = "ul#ui-id-2>li.list>a")
private List<WebElement> lnk_autoSuggestionsDestinationTxtBx;
@FindBy(id = "ToTag")
private WebElement txtbox_to;
@FindBy(id = "DepartDate")
private WebElement txt_departCalendar;
@FindBy(id = "SearchBtn")
private WebElement btn_searchFlight;
@FindBy(className = "searchSummary")
private WebElement str_searchSummary;
@Test
public void testThatResultsAppearForAOneWayJourney() {
setDriverPath();
driver.get("https://www.cleartrip.com/");
PageFactory.initElements(driver, this);
waitFor(2000);
radio_oneWay.click();
txtbox_from.clear();
txtbox_from.sendKeys("Bangalore");
//wait for the auto complete options to appear for the origin
HotelBookingTest.explicitWait_till_ElementsVisibility(lnk_autoSuggestionsOriginTxtBx);
select_autosuggestion_value_by_index(lnk_autoSuggestionsOriginTxtBx , 0);
txtbox_to.clear();
txtbox_to.sendKeys("Delhi");
//wait for the auto complete options to appear for the destination
HotelBookingTest.explicitWait_till_ElementsVisibility(lnk_autoSuggestionsDestinationTxtBx);
//select the first item from the destination auto complete list
select_autosuggestion_value_by_index(lnk_autoSuggestionsDestinationTxtBx , 0);
txt_departCalendar.click();
selectdate(txt_departCalendar,29,9,2019);
//all fields filled in. Now click on search
btn_searchFlight.click();
SignInTest.explicitWaitTillElementVisibility(str_searchSummary);
//verify that result appears for the provided journey search
Assert.assertTrue(isElementPresent(By.className("searchSummary")));
//close the browser
driver.quit();
}
private void selectdate(WebElement element,int date,int month,int year) {
String reqDate=date+"";
String reqMonth=month+"";
String reqYear=year+"";
element.sendKeys(reqDate+"/"+reqMonth+"/"+reqYear);
}
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;
}
}
public void select_autosuggestion_value_by_index(List<WebElement> elements,int indx) {
try {
elements.get(indx).click();
}
catch(Exception e) {
System.out.println(e);
}
}
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");
}
}
}