karatelabs/karate · error · DriverException
timeout waiting for condition
Error message
timeout waiting for condition
What it means
CdpDriver.waitUntil(Supplier<Object> condition, timeout) polls a caller-supplied Java supplier until it returns a truthy value (per Terms.isTruthy); if the result stays falsy until the timeout, a DriverException with no detail beyond the generic message is thrown. Note the message carries no condition text, so wrap suppliers to log failures.
Solutions
- Wrap the supplier to log each evaluation (or the exception) so you can see why it stays falsy
- Verify the supplier returns a truthy value in isolation (call once and print the result)
- Increase the timeout
- Fix the supplier so errors propagate instead of silently returning null
Example fix
// before
driver.waitUntil(() -> fetchCount() == 5, Duration.ofSeconds(5));
// after
int n = fetchCount(); // log/assert n first
driver.waitUntil(() -> { int c = fetchCount(); logger.debug("count={}", c); return c == 5; }, Duration.ofSeconds(15)); Defensive patterns
Strategy: try-catch
Validate before calling
// evaluate the supplier once outside the wait
Object first = conditionSupplier.get();
if (first == null) { logger.warn("supplier currently returns null"); } Try / catch
try {
Object result = driver.waitUntil(() -> pollJavaState(), Duration.ofSeconds(20));
} catch (DriverException e) {
logger.error("supplier condition never truthy within budget");
throw e;
} Prevention
- Make the supplier log each evaluation or its exceptions — the error message carries no detail
- Ensure the supplier propagates errors instead of swallowing them into null
- Return clearly truthy values (non-null objects, Boolean.TRUE) to avoid isTruthy ambiguity
When it happens
Trigger: driver.waitUntil(() -> someJavaCheck(), Duration) where the supplier keeps returning null/false/empty — e.g. polling a Java-side value (DOM read, API response) that never turns truthy within the budget.
Common situations: Supplier throws internally and callers swallow it, always returning null; supplier polls the wrong object; timeout shorter than the async work being waited on; bug where the supplier reads a stale snapshot.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- timeout waiting for condition
- timeout waiting for condition
- element not found after
- retry FAILED after attempts: |
- timeout waiting for any element
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/c3b6f604b4c63cb4.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java:3451
}
/**
* Wait until a supplier returns a truthy value.
*/
public Object waitUntil(Supplier<Object> condition) {
return waitUntil(condition, options.getTimeoutDuration());
}
/**
* Wait until a supplier returns a truthy value with custom timeout.
*/
public Object waitUntil(Supplier<Object> condition, Duration timeout) {
Object result = pollFor(timeout.toMillis(), options.getRetryInterval(), () -> {
Object r = condition.get();
return Terms.isTruthy(r) ? r : null;
});
if (result == null) {
throw new DriverException("timeout waiting for condition");
}
return result;
}
/**
* Wait for a specific number of elements to match.
*/
public List<Element> waitForResultCount(String locator, int count) {
return waitForResultCount(locator, count, options.getTimeoutDuration());
}
/**
* Wait for a specific number of elements to match with custom timeout.
*/
public List<Element> waitForResultCount(String locator, int count, Duration timeout) {
boolean met = pollUntil(timeout.toMillis(), options.getRetryInterval(),
() -> ((Number) script(Locators.countJs(locator))).intValue() == count);
if (!met) {View on GitHub (pinned to a22eb90246)