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
64 changes: 62 additions & 2 deletions HotelsDotComTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;
Expand All @@ -17,10 +22,11 @@ public class HotelsDotComTest {

@BeforeClass
public static void setUp() throws Exception {
EdgeOptions options = new EdgeOptions();
/*EdgeOptions options = new EdgeOptions();
options.addArguments("--user-data-dir=/Users/tim/Library/Application Support/Microsoft Edge/Default");
driver = new EdgeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));*/
driver = new ChromeDriver();
}

@Test
Expand Down Expand Up @@ -51,4 +57,58 @@ public void testHotelPrice() throws Exception {
System.out.println(price);

}

@Test
public void testHotelPrice2() throws InterruptedException {
driver.get("https://www.hotels.com/");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Thread.sleep(2000);
driver.manage().window().maximize();

// Enter the city
WebElement cityInput = driver.findElement(By.xpath("//*[@aria-label='Where to?']"));
wait.until(ExpectedConditions.visibilityOf(cityInput));
cityInput.click();
wait.until(ExpectedConditions.visibilityOf(cityInput));
WebElement destinationInput = driver.findElement(By.xpath("//*[@id='destination_form_field']"));
destinationInput.sendKeys("Los Angeles");
wait.until(ExpectedConditions.visibilityOf(cityInput));
destinationInput.sendKeys(Keys.RETURN);
//cityInput.submit();

WebElement calender = driver.findElement(By.xpath("//button[@data-testid='uitk-date-selector-input1-default']"));
calender.click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='uitk-cal-controls-button uitk-cal-controls-button-inset-multi uitk-cal-controls-button-next']"))).click();

WebElement flexible = driver.findElement(By.xpath("//a[@href='#EGDSBasicTabSearchForm_date_form_nested_flexible_tab_dates']"));
flexible.click();

List<WebElement> months = driver.findElements(By.xpath("//label[@class='button-toggle-custom-content-container']"));

for (WebElement month : months) {
month.click();
}
driver.findElement(By.xpath("//button[@id='search_button']")).click();

// Wait for results to load
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@aria-label='Search by property name']")));

// Search Hotels
WebElement searchHotels = driver.findElement(By.xpath("//*[@aria-label='Search by property name']"));
searchHotels.click();
WebElement hotelInput = driver.findElement(By.xpath("//input[@class='uitk-field-input uitk-typeahead-input uitk-typeahead-input-v2']"));
hotelInput.sendKeys("Four Seasons");
hotelInput.sendKeys(Keys.RETURN);

//Filtering the results
Select sort = new Select(driver.findElement(By.xpath("//select[@id='sort-filter-dropdown-sort']")));
sort.selectByVisibleText("Price: low to high");

String price = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='uitk-text uitk-type-end uitk-type-300 uitk-text-default-theme']"))).getText();
System.out.println(price);

String date = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='uitk-text uitk-type-end uitk-type-300 uitk-type-bold uitk-text-default-theme']"))).getText();
System.out.println(date);
}
}