{"record":{"id":"3b545f447832e44e","repo":"karatelabs/karate","slug":"waituntil-supplier-timeout","errorCode":null,"errorMessage":"waitUntil (supplier) timeout","messagePattern":"waitUntil \\(supplier\\) timeout","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java","lineNumber":677,"sourceCode":"        throw new DriverException(\"waitUntil timeout: \" + expression);\n    }\n\n    @Override\n    public Object waitUntil(java.util.function.Supplier<Object> condition) {\n        return waitUntil(condition, options.getTimeoutDuration());\n    }\n\n    @Override\n    public Object waitUntil(java.util.function.Supplier<Object> condition, java.time.Duration timeout) {\n        long deadline = System.currentTimeMillis() + timeout.toMillis();\n        while (System.currentTimeMillis() < deadline) {\n            Object result = condition.get();\n            if (isTruthy(result)) {\n                return result;\n            }\n            sleep(options.getRetryInterval());\n        }\n        throw new DriverException(\"waitUntil (supplier) timeout\");\n    }\n\n    @Override\n    public List<Element> waitForResultCount(String locator, int count) {\n        return waitForResultCount(locator, count, options.getTimeoutDuration());\n    }\n\n    @Override\n    public List<Element> waitForResultCount(String locator, int count, java.time.Duration timeout) {\n        long deadline = System.currentTimeMillis() + timeout.toMillis();\n        while (System.currentTimeMillis() < deadline) {\n            List<Element> results = locateAll(locator);\n            if (results.size() == count) {\n                return results;\n            }\n            sleep(options.getRetryInterval());\n        }\n        throw new DriverException(\"waitForResultCount timeout: \" + locator + \" expected count: \" + count);","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java#L659-L695","documentation":"W3cDriver.waitUntil(Supplier) polls condition.get() every retry interval until the result is truthy or the timeout elapses, then throws a DriverException with the fixed message 'waitUntil (supplier) timeout'. This is the Java-embedded variant used from Java tests/custom code rather than a page JS expression.","triggerScenarios":"Calling driver.waitUntil(java.util.function.Supplier<Object>) where the supplier keeps returning null/false/0 — e.g. a predicate reading driver state (URL, element count, a flag) that never becomes satisfied within the timeout.","commonSituations":"Supplier logic bug (always false); condition depends on an external event (websocket, background job) that never fires; timeout too short for the operation being awaited; supplier throws internally and the wrapper keeps polling.","solutions":["Log the supplier's return value each iteration to see why it never becomes truthy","Increase the timeout via waitUntil(condition, timeout)","Fix the supplier predicate so it correctly detects the target state","Ensure whatever the supplier waits on (async job, network event) is actually triggered"],"exampleFix":"// before\ndriver.waitUntil(() -> driver.getUrl().contains(\"/done\")); // nav never happens\n// after\ndriver.click(\"#finish\"); // trigger the navigation first\ndriver.waitUntil(() -> driver.getUrl().contains(\"/done\"), 30000);","handlingStrategy":"try-catch","validationCode":"// call condition.get() once yourself and inspect the result before polling\nObject probe = condition.get();","typeGuard":null,"tryCatchPattern":"try {\n    Object result = driver.waitUntil(condition, timeout);\n} catch (DriverException e) {\n    // log condition.get() result to see why it never turned truthy\n}","preventionTips":["Make the supplier cheap, side-effect free, and loggable","Trigger the async work the supplier depends on before waiting","Size the timeout for the slowest expected completion time"],"tags":["webdriver","timeout","supplier","wait"],"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"}