package com.mavlushechka.a1qa.elements; import com.mavlushechka.a1qa.driverUtils.ActionUtils; import com.mavlushechka.a1qa.driverUtils.WebDriverUtils; import com.mavlushechka.a1qa.driverUtils.WebDriverWaitFactory; import com.mavlushechka.a1qa.utils.LoggerUtils; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; public abstract class BaseElement { private final By locator; private final String name; public BaseElement(By locator, String name) { this.locator = locator; this.name = name; } public void click() { WebElement webElement = find(); scrollTo(); LoggerUtils.info("Clicking on the \"" + name + "\" element."); webElement.click(); } public String getText() { WebElement webElement = find(); LoggerUtils.info("Getting text of the \"" + name + "\" element."); return webElement.getText(); } public boolean isEnabled() { WebElement webElement = find(); LoggerUtils.info("Getting state of the \"" + name + "\" element."); return webElement.isEnabled(); } public boolean isVisible() { LoggerUtils.info("Getting visibility of the \"" + name + "\" element."); return WebDriverWaitFactory.createWebDriverWait().until(ExpectedConditions.visibilityOfElementLocated(locator)).isDisplayed(); } public boolean isInvisible() { LoggerUtils.info("Getting invisibility of the \"" + name + "\" element."); return WebDriverWaitFactory.createWebDriverWait().until(ExpectedConditions.invisibilityOfElementLocated(locator)); } public String getName() { return name; } public Dimension getDimension() { WebElement webElement = find(); LoggerUtils.info("Getting dimension of the \"" + name + "\" element."); return webElement.getSize(); } public String getAttributeValue(String attribute) { WebElement webElement = find(); LoggerUtils.info("Getting \"" + attribute + "\" attribute of the \"" + name + "\" element."); return webElement.getAttribute(attribute); } protected WebElement find() { isVisible(); LoggerUtils.info("Finding the \"" + name + "\" element."); return WebDriverUtils.findElement(locator); } protected void scrollTo() { WebElement webElement = find(); LoggerUtils.info("Scrolling to the \"" + name + "\" element."); ActionUtils.scrollTo(webElement); } }