Search in sources :

Example 1 with WaitForSelectorOptions

use of com.ruiyun.jvppeteer.options.WaitForSelectorOptions in project epic4j by huisunan.

the class SelectorUtil method timeout.

public WaitForSelectorOptions timeout(Integer timeout) {
    WaitForSelectorOptions options = new WaitForSelectorOptions();
    options.setTimeout(timeout);
    return options;
}
Also used : WaitForSelectorOptions(com.ruiyun.jvppeteer.options.WaitForSelectorOptions)

Example 2 with WaitForSelectorOptions

use of com.ruiyun.jvppeteer.options.WaitForSelectorOptions in project epic4j by huisunan.

the class SelectorUtil method timeout.

public WaitForSelectorOptions timeout(Integer timeout) {
    WaitForSelectorOptions options = new WaitForSelectorOptions();
    options.setTimeout(timeout);
    return options;
}
Also used : WaitForSelectorOptions(com.ruiyun.jvppeteer.options.WaitForSelectorOptions)

Example 3 with WaitForSelectorOptions

use of com.ruiyun.jvppeteer.options.WaitForSelectorOptions in project epic4j by huisunan.

the class PageUtil method findSelectors.

/**
 * 在指定范围时间内,遍历查找
 *
 * @param page        page
 * @param timeout     超时时间
 * @param ignore      true忽略异常
 * @param timeoutBack 超时后回调
 * @param selectItems 要查询的元素
 */
@SneakyThrows
public void findSelectors(Page page, Integer timeout, Boolean ignore, SelectItem.SelectCallBack timeoutBack, SelectItem... selectItems) {
    WaitForSelectorOptions options = new WaitForSelectorOptions();
    options.setTimeout(timeout);
    // 100ms
    int interval = 100;
    for (int i = 0; i < timeout; i += interval) {
        for (SelectItem selectItem : selectItems) {
            boolean flag = false;
            try {
                flag = selectItem.getPagePredicate().test(page, selectItem);
            } catch (Exception e) {
                if (ignore)
                    log.debug("ignore exception", e);
                else
                    throw e;
            }
            if (flag) {
                boolean isContinue = selectItem.getCallback().run();
                if (!isContinue) {
                    return;
                }
            }
        }
        TimeUnit.MILLISECONDS.sleep(interval);
    }
    if (timeoutBack != null) {
        timeoutBack.run();
    }
}
Also used : SelectItem(com.hsn.epic4j.bean.SelectItem) WaitForSelectorOptions(com.ruiyun.jvppeteer.options.WaitForSelectorOptions) TimeException(com.hsn.epic4j.exception.TimeException) SneakyThrows(lombok.SneakyThrows)

Aggregations

WaitForSelectorOptions (com.ruiyun.jvppeteer.options.WaitForSelectorOptions)3 SelectItem (com.hsn.epic4j.bean.SelectItem)1 TimeException (com.hsn.epic4j.exception.TimeException)1 SneakyThrows (lombok.SneakyThrows)1