All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.willhaben.willtest.misc.pages.AbstractWaitingBuilder Maven / Gradle / Ivy

There is a newer version: 3.1.10
Show newest version
package at.willhaben.willtest.misc.pages;

import at.willhaben.willtest.misc.utils.ConditionType;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.util.Objects;

public abstract class AbstractWaitingBuilder {

    private final PageObject pageObject;
    private By by;
    private WebElement webElement;

    AbstractWaitingBuilder(PageObject pageObject, WebElement webElement) {
        this.pageObject = pageObject;
        this.webElement = webElement;
    }

    AbstractWaitingBuilder(PageObject pageObject, By by) {
        this.pageObject = pageObject;
        this.by = by;
    }

    public PageObject getPageObject() {
        return pageObject;
    }

    public abstract T clickable(long timeout);

    public abstract T visible(long timeout);

    public T clickable() {
        return clickable(PageObject.DEFAULT_WAIT_TIMEOUT);
    }

    public T visible() {
        return visible(PageObject.DEFAULT_WAIT_TIMEOUT);
    }

    protected ExpectedCondition generateCondition(ConditionType condition) {
        switch (condition) {
            case CLICKABLE:
                return generateClickableCondition();
            case VISIBLE:
                return generateVisibleCondition();
            default:
                throw new IllegalArgumentException("Illegal waiting condition [" + condition.toString() + "].");
        }
    }

    private ExpectedCondition generateClickableCondition() {
        if(Objects.nonNull(webElement)) {
            return ExpectedConditions.elementToBeClickable(webElement);
        } else {
            return ExpectedConditions.elementToBeClickable(by);
        }
    }

    private ExpectedCondition generateVisibleCondition() {
        if(Objects.nonNull(webElement)) {
            return ExpectedConditions.visibilityOf(webElement);
        } else {
            return ExpectedConditions.visibilityOfElementLocated(by);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy