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

com.jdiai.jsbuilder.RetryFunctions Maven / Gradle / Ivy

package com.jdiai.jsbuilder;

import com.jdiai.tools.Timer;
import org.openqa.selenium.WebDriver;

import java.util.List;
import java.util.function.BiFunction;

import static com.jdiai.jsbuilder.HttpExecutor.execute;

public class RetryFunctions {
    public static BiFunction DEFAULT_SCRIPT_EXECUTE =
        (driver, script) -> HttpExecutor.execute((WebDriver) driver, script);
        // ((JavascriptExecutor)driver).executeScript(jsScript);
    public static BiFunction RETRY_TIMEOUT = (driver, jsScript) -> {
        Timer t = new Timer(1000);
        Object obj = null;
        while (obj == null && t.isRunning()) {
            try {
                obj = execute((WebDriver) driver, jsScript);
            } catch (Exception ignore) { }
        }
        return obj;
    };

    public static BiFunction> DEFAULT_LIST_SCRIPT_EXECUTE =
        (driver, jsScript) -> (List) execute((WebDriver) driver, jsScript);

    public static BiFunction> LIST_RETRY_TIMEOUT = (driver, jsScript) -> {
        Timer t = new Timer(1000);
        List obj = null;
        while (obj == null && t.isRunning()) {
            try {
                obj = (List) execute((WebDriver) driver, jsScript);
            } catch (Exception ignore) { }
        }
        return obj;
    };
}