Created
August 25, 2024 23:00
-
-
Save cyupa/45c4a0fbf9640fabb826173bff393e98 to your computer and use it in GitHub Desktop.
HotelDetailsage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pageObjects; | |
import java.util.List; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.support.FindBy; | |
import org.openqa.selenium.support.PageFactory; | |
public class HotelDetailsPage extends BasePage { | |
// UI Elements | |
@FindBy(xpath = "//div[@class='carousel-root']") | |
WebElement carousel; | |
@FindBy(xpath = "//div[@class='carousel carousel-slider']/ul") | |
WebElement carouselDots; | |
@FindBy(xpath = "//div[@class='text-4xl flex items-center font-bold md:text-5xl text-center sm:text-start']") | |
WebElement hotelTitle; | |
// Initializer | |
public HotelDetailsPage(WebDriver driver) { | |
this.webDriver = driver; | |
PageFactory.initElements(driver, this); | |
} | |
public WebElement getCarousel() { | |
return this.carousel; | |
} | |
public List<WebElement> getCarouselControlDots() { | |
// Find all child elements of carouselDots (<ul> element) | |
return carouselDots.findElements(By.xpath("./child::*")); | |
} | |
public String getHotelTitle() { | |
return hotelTitle.getText(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package seleniumTests; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import pageObjects.HotelDetailsPage; | |
import utils.BaseTestClass; | |
import java.util.List; | |
public class HotelDetailsTests extends BaseTestClass { | |
// Test parameters | |
private String topRoyalBrasovURL = "http://138.68.69.185/hotel-details/97506b5a-3df8-4967-9379-265925aa9832"; | |
@Test | |
public void testIfCarouselIsPresent() { | |
driver.get(topRoyalBrasovURL); | |
// Initialise HotelDetailsPage and get carousel element | |
HotelDetailsPage hotelPage = new HotelDetailsPage(driver); | |
WebElement carousel = hotelPage.getCarousel(); | |
// Carousel element should not be null (it exists). | |
Assert.assertNotNull(carousel); | |
} | |
@Test | |
public void testCarouselImagesCount() { | |
driver.get(topRoyalBrasovURL); | |
// Initialise HotelDetailsPage and get carousel dots element | |
HotelDetailsPage hotelPage = new HotelDetailsPage(driver); | |
List<WebElement> carouselDots; | |
carouselDots = hotelPage.getCarouselControlDots(); | |
// Check if carousel has between 0 and 50 dots | |
Assert.assertTrue("Carousel should have between 0 and 50 dots: " + carouselDots.size(), | |
carouselDots.size() > 0 && carouselDots.size() <= 50); | |
} | |
@Test | |
public void testHotelTitle() { | |
driver.get(topRoyalBrasovURL); | |
// Initialise HotelDetailsPage and get hotel title element | |
HotelDetailsPage hotelPage = new HotelDetailsPage(driver); | |
String hotelTitle = hotelPage.getHotelTitle(); | |
// Check if hotel title is not empty | |
Assert.assertFalse("Hotel title should not be empty", hotelTitle.isEmpty()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment