Skip to content
Open
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
58 changes: 45 additions & 13 deletions src/main/java/HotelBookingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,67 @@

public class HotelBookingTest {

WebDriver driver = new ChromeDriver();
static WebDriver driver = new ChromeDriver();

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

@FindBy(id = "Tags")
private WebElement localityTextBox;
@FindBy(id = "Tags")
private WebElement localityTextBox;

@FindBy(id = "SearchHotelsButton")
private WebElement searchButton;
@FindBy(css = "ul#ui-id-1>li>a")
private List<WebElement> autosuggestionlocalityTextBox;

@FindBy(id = "travellersOnhome")
private WebElement travellerSelection;
@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();
// Maximizing window
driver.manage().window().maximize();

// Initialize the page objects.
PageFactory.initElements(driver, this);

hotelLink.click();

localityTextBox.sendKeys("Indiranagar, Bangalore");
localityTextBox.sendKeys("Indiranagar, Bangalore");

new Select(travellerSelection).selectByVisibleText("1 room, 2 adults");
searchButton.click();
// Create a method to select value from auto-suggested values populated by Where text box.
selectAutoSuggestedValue(autosuggestionlocalityTextBox, "Indiranagar, Bangalore");

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

driver.quit();

}

private static void selectAutoSuggestedValue(List<WebElement> elements, String partialLinkName) {
try {
explicitWait_till_ElementsVisibility(elements);
int lnkCnt = elements.size();
for (int i = 0; i < lnkCnt; i++) {
WebElement link = elements.get(i);
if (link.getText().contains(partialLinkName)) {
link.click();
break;
}
}
} catch (Exception e) {
System.out.println("Exception:" + e);
}
}

static void explicitWait_till_ElementsVisibility(List<WebElement> elements) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfAllElements(elements));
}

private void setDriverPath() {
if (PlatformUtil.isMac()) {
Expand Down