DriverOptions { public <T> T retry(Supplier<T> action, Predicate<T> condition, String logDescription, boolean failWithException) { long startTime = System.currentTimeMillis(); int count = 0, max = getRetryCount(); T result; boolean success; do { if (count > 0) { logger.debug("{} - retry #{}", logDescription, count); sleep(); } result = action.get(); success = condition.test(result); } while (!success && count++ < max); if (!success) { long elapsedTime = System.currentTimeMillis() - startTime; String message = logDescription + ": failed after " + (count - 1) + " retries and " + elapsedTime + " milliseconds"; logger.warn(message); if (failWithException) { throw new RuntimeException(message); } } return result; } DriverOptions(ScenarioContext context, Map<String, Object> options, LogAppender appender, int defaultPort, String defaultExecutable); void setContext(ScenarioContext context); ScenarioContext getContext(); boolean isRetryEnabled(); String getPreSubmitHash(); void setPreSubmitHash(String preSubmitHash); Http getHttp(); void arg(String arg); Command startProcess(); static Driver start(ScenarioContext context, Map<String, Object> options, LogAppender appender); Map<String, Object> getWebDriverSessionPayload(); static String preProcessWildCard(String locator); static String selector(String locator); static String selector(String locator, String contextNode); void setTimeout(Integer timeout); int getTimeout(); void setRetryInterval(Integer retryInterval); int getRetryInterval(); int getRetryCount(); T retry(Supplier<T> action, Predicate<T> condition, String logDescription, boolean failWithException); static String wrapInFunctionInvoke(String text); String highlight(String locator, int millis); String highlightAll(String locator, int millis); String optionSelector(String locator, String text); String optionSelector(String id, int index); String scriptSelector(String locator, String expression); String scriptSelector(String locator, String expression, String contextNode); String scriptAllSelector(String locator, String expression); String scriptAllSelector(String locator, String expression, String contextNode); void sleep(); void sleep(int millis); Map<String, Object> newMapWithSelectedKeys(Map<String, Object> map, String... keys); void embedPngImage(byte[] bytes); void embedContent(Embed embed); void disableRetry(); void enableRetry(Integer count, Integer interval); Element waitUntil(Driver driver, String locator, String expression); String waitForUrl(Driver driver, String expected); Element waitForAny(Driver driver, String... locators); Element optional(Driver driver, String locator); static String karateLocator(String karateRef); String focusJs(String locator); List<Element> findAll(Driver driver, String locator); final Map<String, Object> options; final int timeout; final boolean start; final String executable; final String type; final int port; final String host; final int pollAttempts; final int pollInterval; final boolean headless; final boolean showProcessLog; final boolean showDriverLog; final Logger logger; final LogAppender appender; final Logger processLogger; final Logger driverLogger; final String uniqueName; final File workingDir; final boolean disableNotifications; final String userAgent; final String userDataDir; final String processLogFile; final int maxPayloadSize; final List<String> addOptions; final List<String> args; final String webDriverUrl; final String webDriverPath; final Map<String, Object> webDriverSession; final Map<String, Object> httpConfig; final Target target; final String beforeStart; final String afterStop; final String videoFile; final boolean highlight; final int highlightDuration; final String attach; static final String SCROLL_JS_FUNCTION; static final String KARATE_REF_GENERATOR; }
@Test public void testRetry() { DriverOptions options = new DriverOptions(getContext(), Collections.EMPTY_MAP, null, 0, null); options.retry(() -> 1, x -> x < 5, "not 5", false); }