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

net.serenitybdd.core.pages.WebElementFacadeWait Maven / Gradle / Ivy

There is a newer version: 4.2.8
Show newest version
package net.serenitybdd.core.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class WebElementFacadeWait {
    PageObject page;
    private final long timeoutInSeconds;
    private final long sleepInMillis;

    public WebElementFacadeWait(PageObject page) {
        this.timeoutInSeconds = page.getImplicitWaitTimeout().getSeconds();
        this.sleepInMillis = 200;
        this.page = page;
    }

    public WebElementFacadeWait(PageObject page, long timeoutInSeconds) {
        this.timeoutInSeconds = timeoutInSeconds;
        this.sleepInMillis = 200;
        this.page = page;
    }

    protected WebElementFacadeWait(PageObject page, long timeoutInSeconds, long sleepInMillis) {
        this.timeoutInSeconds = timeoutInSeconds;
        this.sleepInMillis = sleepInMillis;
        this.page = page;
    }


    public WebElementFacadeWait forUpTo(long timeoutInSeconds) {
        return new WebElementFacadeWait(page, timeoutInSeconds, sleepInMillis);
    }

    public WebElementFacadeWait pollingEvery(long sleepInMillis) {
        return new WebElementFacadeWait(page, timeoutInSeconds, sleepInMillis);
    }

    public WebElementFacade until(ExpectedCondition isTrue) {
        return page.element(new WebDriverWait(page.getDriver(), Duration.ofSeconds(timeoutInSeconds)).until(isTrue));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy