@Override public Object invoke(Object o, Method method, Object[] objects) throws Throwable { if ("toString".equals(method.getName())) { return name; } long end = this.clock.laterBy(TimeUnit.SECONDS.toMillis(this.timeOutInSeconds)); StaleElementReferenceException lasException = null; while (this.clock.isNowBefore(end)) { try { return super.invoke(o, method, objects); } catch (StaleElementReferenceException e) { lasException = e; this.waitFor(); } } throw lasException; }
MyObject(BigDecimal bigDecimal, Clock clock) { timeStampMap.put(Stamp.START, clock.now()); }
@Override public <T> T until(Function<WebDriver, T> isTrue) { long end = clock.laterBy(timeOutInMillis); NotFoundException lastException = null; while (clock.isNowBefore(end)) { try { T value = isTrue.apply(driver); if (value != null && Boolean.class.equals(value.getClass())) { if (Boolean.TRUE.equals(value)) { return value; } } else if (value != null) { return value; } } catch (NotFoundException e) { // Common case in many conditions, so swallow here, but be ready to // rethrow if it the element never appears. lastException = e; } sleep(); } throwTimeoutException( String.format("Timed out after %d seconds", SECONDS.convert(timeOutInMillis, MILLISECONDS)), lastException); throw new IllegalStateException("'throwTimeoutException' should have thrown an exception!"); }
public static String getCorrectDate(Clock clock) { Calendar cal = new GregorianCalendar(); cal.setTimeZone(...); // Which time zone are you interested in? cal.setTime(clock.now()); // Or cal.setTimeInMillis(clock.now()); // ... logic as before }
long end = clock.laterBy(timeout.in(MILLISECONDS)); Exception lastException = null; if (!clock.isNowBefore(end)) { String toAppend = (message == null) ? " waiting for " + condition.toString() : ": " + message;
public static int getAge(LocalDate birthdate, Clock clock) { LocalDate today = clock.now(); Period period = new Period(birthdate, today, PeriodType.yearMonthDay()); return period.getYears(); }
public <V> V until(Function<? super T, V> isTrue) { long end = getClock().laterBy(timeout.in(MILLISECONDS)); RuntimeException lastException = null; String waitForConditionMessage = isTrue.toString(); if (!getClock().isNowBefore(end)) { String message = String.format("Timed out after %d milliseconds: ",timeout.in(MILLISECONDS)) + waitForConditionMessage; throw timeoutException(message, lastException);
public void waitFor(Finder<WebElement, WebDriver> finder, long timeoutMillis) { long timeoutTime = clock.now() + timeoutMillis; while (clock.now() < timeoutTime) { Collection<WebElement> result = finder.findFrom(driver); for (WebElement webElement : result) { if (((RenderedWebElement) webElement).isDisplayed()) { return; // found it } } } failWith("Element was not rendered within " + timeoutMillis + "ms"); }
public <V> V until(Function<? super T, V> isTrue) { long end = getClock().laterBy(timeout.in(MILLISECONDS)); RuntimeException lastException = null; while (true) { if (!getClock().isNowBefore(end)) { throw timeoutException(String.format("Timed out after %d seconds", timeout.in(SECONDS)), lastException);
public void waitFor(Finder<WebElement, WebDriver> finder, long timeoutMillis) { long timeoutTime = clock.now() + timeoutMillis; while (clock.now() < timeoutTime) { Collection<WebElement> result = finder.findFrom(driver); for (WebElement webElement : result) { if (((RenderedWebElement) webElement).isDisplayed()) { return; // found it } } } failWith("Element was not rendered within " + timeoutMillis + "ms"); }
@Override @SuppressWarnings("unchecked") public T get() { try { isLoaded(); return (T) this; } catch (Error e) { load(); } long end = clock.laterBy(SECONDS.toMillis(timeOutInSeconds)); while (clock.isNowBefore(end)) { try { isLoaded(); return (T) this; } catch (Error e) { // Not a problem, we could still be loading } isError(); waitFor(sleepFor()); } isLoaded(); return (T) this; }
@Override @SuppressWarnings("unchecked") public T get() { try { isLoaded(); return (T) this; } catch (Error e) { load(); } long end = clock.laterBy(SECONDS.toMillis(timeOutInSeconds)); while (clock.isNowBefore(end)) { try { isLoaded(); return (T) this; } catch (Error e) { // Not a problem, we could still be loading } isError(); waitFor(sleepFor()); } isLoaded(); return (T) this; }
long end = clock.laterBy(timeout.in(MILLISECONDS)); Throwable lastException = null; while (true) { if (!clock.isNowBefore(end)) { String timeoutMessage = String.format( "Timed out after %d seconds trying to perform action %s",