Skip to content

Commit 10f6f6c

Browse files
authored
Create FlightBookingTestElements.java
1 parent 50f70d5 commit 10f6f6c

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import java.text.ParseException;
2+
import java.text.SimpleDateFormat;
3+
import java.util.Calendar;
4+
import java.util.Date;
5+
import java.util.List;
6+
7+
import org.openqa.selenium.By;
8+
import org.openqa.selenium.JavascriptExecutor;
9+
import org.openqa.selenium.WebDriver;
10+
import org.openqa.selenium.WebElement;
11+
12+
public class FlightBookingTestElements {
13+
WebDriver driver;
14+
By oneWay = By.id("OneWay");
15+
By source = By.id("FromTag");
16+
By destination = By.name("destination");
17+
By sourceOptions = By.id("ui-id-1");
18+
By destOptions = By.id("ui-id-2");
19+
By liTag = By.tagName("li");
20+
By searchBt = By.id("SearchBtn");
21+
By seachSummary = By.className("searchSummary");
22+
By calendar = By.xpath("//*[@id='ui-datepicker-div']");
23+
24+
public FlightBookingTestElements(WebDriver driver) {
25+
this.driver = driver;
26+
}
27+
28+
public WebElement oneWayElement()
29+
{
30+
return driver.findElement(oneWay);
31+
}
32+
public WebElement srcElement()
33+
{
34+
return driver.findElement(source);
35+
}
36+
public WebElement destElement()
37+
{
38+
return driver.findElement(destination);
39+
}
40+
public List<WebElement> srcOptions()
41+
{
42+
return driver.findElement(sourceOptions).findElements(liTag);
43+
}
44+
public List<WebElement> destOptions()
45+
{
46+
return driver.findElement(destOptions).findElements(liTag);
47+
}
48+
public WebElement searchElement()
49+
{
50+
return driver.findElement(searchBt);
51+
}
52+
public WebElement searchSumElement()
53+
{
54+
return driver.findElement(seachSummary);
55+
}
56+
public void selectDate(String year, String monthName, String day) throws ParseException
57+
{
58+
driver.findElement(calendar).click();
59+
60+
String currentYear= driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-year']")).getText();
61+
// System.out.println(currentYear);
62+
if(!currentYear.equals(year))
63+
{
64+
do{
65+
driver.findElement(By.xpath("//a[@class='nextMonth ']")).click();
66+
}while(!driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-year']")).getText().equals(year));
67+
68+
}
69+
70+
String currentMonth= driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-month']")).getText();
71+
// System.out.println("mont;"+currentMonth);
72+
if(!currentMonth.equalsIgnoreCase(monthName))
73+
{
74+
do{
75+
driver.findElement(By.xpath("//a[@class='nextMonth ']")).click();
76+
}while(!driver.findElement(By.xpath("//div[@class='monthBlock first']//div[@class='title']/span[@class='ui-datepicker-month']")).getText().trim().equalsIgnoreCase(monthName));
77+
78+
}
79+
80+
int javaMonthInt= getMonthJavaInt(monthName);
81+
82+
83+
List<WebElement> allDateOfDesiredMonth= driver.findElements(By.xpath("//div[@class='monthBlock first']/table/tbody[1]//td[(contains(@class,'undefined') and @data-month='"+javaMonthInt+"')]"));
84+
for(WebElement d:allDateOfDesiredMonth )
85+
{
86+
87+
if(d.getText().trim().equals(day))
88+
{
89+
System.out.println("date:"+d.getAttribute("data-month"));
90+
System.out.println(d.findElement(By.className("ui-state-default")).getText());
91+
JavascriptExecutor executor = (JavascriptExecutor) driver;
92+
executor.executeScript("arguments[0].click();", d);
93+
break;
94+
}
95+
}
96+
97+
}
98+
99+
public int getMonthJavaInt(String monthName) throws ParseException
100+
{
101+
102+
Date date = new SimpleDateFormat("MMMM").parse(monthName);
103+
Calendar cal = Calendar.getInstance();
104+
cal.setTime(date);
105+
return cal.get(Calendar.MONTH);
106+
}
107+
108+
}

0 commit comments

Comments
 (0)