Shaishav Desai
Write an automation testing script for any travel application site scenarios?

Write an automation script for the below scenarios,

  1. Go to any one - https://www.makemytrip.com / https://www.goibibo.com / trivago.in - Compare hotel prices worldwide.
  2. Search for location India - Delhi
  3. From date should be 30 days from now
  4. To date should be 32 days from now
  5. Search results
  6. Observe top two hotels and capture the rate
  7. Open detail page for both the entries and capture rate
  8. Compare rates and provide conclusion whether rates are same or not
  9. Provide the runnable jar file for this test scenarios

Thanks!

By Shaishav Desai in Software Testing on Feb 20 2023
  • Tuhin Paul
    Feb, 2023 22

    Writing the code using Selenium WebDriver with Java:

    1. import org.openqa.selenium.By;
    2. import org.openqa.selenium.WebDriver;
    3. import org.openqa.selenium.WebElement;
    4. import org.openqa.selenium.chrome.ChromeDriver;
    5. import java.util.List;
    6. public class HotelPriceComparisonTest {
    7. public static void main(String[] args) {
    8. // Set system property for ChromeDriver
    9. System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
    10. // Launch ChromeDriver
    11. WebDriver driver = new ChromeDriver();
    12. // Navigate to the website
    13. driver.get("https://www.makemytrip.com/hotels/");
    14. // Wait for the page to load
    15. Thread.sleep(5000);
    16. // Select worldwide search
    17. WebElement worldwideSearch = driver.findElement(By.id("searchBtn"));
    18. worldwideSearch.click();
    19. // Wait for the search bar to appear
    20. Thread.sleep(5000);
    21. // Select location and date range
    22. WebElement locationInput = driver.findElement(By.id("city"));
    23. locationInput.sendKeys("India - Delhi");
    24. WebElement fromDateInput = driver.findElement(By.id("checkin"));
    25. fromDateInput.clear();
    26. fromDateInput.sendKeys("22/03/2023");
    27. WebElement toDateInput = driver.findElement(By.id("checkout"));
    28. toDateInput.clear();
    29. toDateInput.sendKeys("24/03/2023");
    30. // Search for hotels
    31. WebElement searchButton = driver.findElement(By.xpath("//button[@data-cy='submitHotels']"));
    32. searchButton.click();
    33. // Wait for search results to load
    34. Thread.sleep(10000);
    35. // Get top two hotels
    36. List<;WebElement>; hotelCards = driver.findElements(By.xpath("//div[@class='makeFlex column']//div[@class='cardSection']"));
    37. WebElement hotelCard1 = hotelCards.get(0);
    38. WebElement hotelCard2 = hotelCards.get(1);
    39. // Get hotel rates from search results
    40. WebElement hotelRate1 = hotelCard1.findElement(By.xpath("//span[@class='ListingPrice__finalPrice']"));
    41. WebElement hotelRate2 = hotelCard2.findElement(By.xpath("//span[@class='ListingPrice__finalPrice']"));
    42. System.out.println("Top two hotels and their rates:");
    43. System.out.println(hotelCard1.getText() + " - " + hotelRate1.getText());
    44. System.out.println(hotelCard2.getText() + " - " + hotelRate2.getText());
    45. // Open detail page for first hotel
    46. hotelCard1.click();
    47. // Wait for detail page to load
    48. Thread.sleep(5000);
    49. // Get rate from detail page
    50. WebElement detailPageRate1 = driver.findElement(By.xpath("//div[@class='base_price_section clearfix']//span[@class='discounted_price']"));
    51. // Navigate back to search results
    52. driver.navigate().back();
    53. // Open detail page for second hotel
    54. hotelCard2.click();
    55. // Wait for detail page to load
    56. Thread.sleep(5000);
    57. // Get rate from detail page
    58. WebElement detailPageRate2 = driver.findElement(By.xpath("//div[@class='base_price_section clearfix']//span[@class='discounted_price']"));
    59. // Compare rates and provide conclusion
    60. if (hotelRate1.getText().equals(detailPageRate1.getText()) && hotelRate2.getText().equals(detailPageRate2.getText())) {
    61. System.out.println("Rates are the same");
    62. } else {
    63. System.out.println("Rates are different");
    64. }
    65. // Close the browser
    66. driver.quit();
    67. }
    68. }

    See if it serve your purpose.

    • 2


Most Popular Job Functions


MOST LIKED QUESTIONS