{"record":{"id":"c3b6f604b4c63cb4","repo":"karatelabs/karate","slug":"timeout-waiting-for-condition","errorCode":null,"errorMessage":"timeout waiting for condition","messagePattern":"timeout waiting for condition","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":3451,"sourceCode":"    }\n\n    /**\n     * Wait until a supplier returns a truthy value.\n     */\n    public Object waitUntil(Supplier<Object> condition) {\n        return waitUntil(condition, options.getTimeoutDuration());\n    }\n\n    /**\n     * Wait until a supplier returns a truthy value with custom timeout.\n     */\n    public Object waitUntil(Supplier<Object> condition, Duration timeout) {\n        Object result = pollFor(timeout.toMillis(), options.getRetryInterval(), () -> {\n            Object r = condition.get();\n            return Terms.isTruthy(r) ? r : null;\n        });\n        if (result == null) {\n            throw new DriverException(\"timeout waiting for condition\");\n        }\n        return result;\n    }\n\n    /**\n     * Wait for a specific number of elements to match.\n     */\n    public List<Element> waitForResultCount(String locator, int count) {\n        return waitForResultCount(locator, count, options.getTimeoutDuration());\n    }\n\n    /**\n     * Wait for a specific number of elements to match with custom timeout.\n     */\n    public List<Element> waitForResultCount(String locator, int count, Duration timeout) {\n        boolean met = pollUntil(timeout.toMillis(), options.getRetryInterval(),\n                () -> ((Number) script(Locators.countJs(locator))).intValue() == count);\n        if (!met) {","sourceCodeStart":3433,"sourceCodeEnd":3469,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L3433-L3469","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndriver.waitUntil(() -> fetchCount() == 5, Duration.ofSeconds(5));\n// after\nint n = fetchCount(); // log/assert n first\ndriver.waitUntil(() -> { int c = fetchCount(); logger.debug(\"count={}\", c); return c == 5; }, Duration.ofSeconds(15));","handlingStrategy":"try-catch","validationCode":"// evaluate the supplier once outside the wait\nObject first = conditionSupplier.get();\nif (first == null) { logger.warn(\"supplier currently returns null\"); }","typeGuard":null,"tryCatchPattern":"try {\n    Object result = driver.waitUntil(() -> pollJavaState(), Duration.ofSeconds(20));\n} catch (DriverException e) {\n    logger.error(\"supplier condition never truthy within budget\");\n    throw e;\n}","preventionTips":["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"],"tags":["driver","timeout","supplier","wait-until"],"backgroundTag":"request-timeout","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}