diff options
Diffstat (limited to 'src/main/java/com/mavlushechka/a1qa/elements/BaseElement.java')
-rw-r--r-- | src/main/java/com/mavlushechka/a1qa/elements/BaseElement.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/elements/BaseElement.java b/src/main/java/com/mavlushechka/a1qa/elements/BaseElement.java new file mode 100644 index 0000000..a2dc55a --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/elements/BaseElement.java @@ -0,0 +1,86 @@ +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); + } + +} |