aquality.selenium.core.elements.ElementStateProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aquality-selenium-core Show documentation
Show all versions of aquality-selenium-core Show documentation
Library with core functions simplifying work with Selenium-controlled applications.
package aquality.selenium.core.elements;
import aquality.selenium.core.elements.interfaces.IElementStateProvider;
import aquality.selenium.core.elements.interfaces.ILogElementState;
import org.openqa.selenium.WebElement;
/**
* Abstract ElementStateProvider class.
*
* @author lenovo
* @version $Id: $Id
*/
public abstract class ElementStateProvider implements IElementStateProvider {
private final ILogElementState logger;
/**
* Constructor for ElementStateProvider.
*
* @param logger a {@link aquality.selenium.core.elements.interfaces.ILogElementState} object.
*/
protected ElementStateProvider(ILogElementState logger) {
this.logger = logger;
}
/**
* logElementState.
*
* @param messageKey a {@link java.lang.String} object.
* @param conditionKeyPart a {@link java.lang.String} object.
*/
protected void logElementState(String messageKey, String conditionKeyPart) {
String conditionKey = "loc.el.state.".concat(conditionKeyPart);
logger.logElementState(messageKey, conditionKey);
}
/**
* isElementEnabled.
*
* @param element a {@link org.openqa.selenium.WebElement} object.
* @return a boolean.
*/
protected boolean isElementEnabled(WebElement element) {
return element.isEnabled();
}
/**
* elementEnabled.
*
* @return a {@link aquality.selenium.core.elements.DesiredState} object.
*/
protected DesiredState elementEnabled() {
return new DesiredState(this::isElementEnabled, "enabled")
.withCatchingTimeoutException()
.withThrowingNoSuchElementException();
}
/**
* elementNotEnabled.
*
* @return a {@link aquality.selenium.core.elements.DesiredState} object.
*/
protected DesiredState elementNotEnabled() {
return new DesiredState(element -> !isElementEnabled(element), "not.enabled")
.withCatchingTimeoutException()
.withThrowingNoSuchElementException();
}
/**
* elementClickable.
*
* @return a {@link aquality.selenium.core.elements.DesiredState} object.
*/
protected DesiredState elementClickable() {
return new DesiredState(webElement -> webElement.isDisplayed() && webElement.isEnabled(), "clickable");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy