{"record":{"id":"aa72955f7ac30e90","repo":"karatelabs/karate","slug":"retry-failed-after-attempts-cdpdriver","errorCode":null,"errorMessage":"retry FAILED after {} attempts: {} | {}","messagePattern":"retry FAILED after (.+?) attempts: (.+?) \\| (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":4290,"sourceCode":"        // Retry loop\n        for (int attempt = 1; attempt <= maxAttempts; attempt++) {\n            // Abort on interruption instead of degrading into a busy spin: sleep()\n            // preserves the interrupt flag, so every later sleep would return\n            // instantly and the remaining attempts would hammer CDP back-to-back.\n            if (Thread.currentThread().isInterrupted()) {\n                logger.warn(\"retry aborted (thread interrupted): {}\", description);\n                return false;\n            }\n            sleep(interval);\n            if (Boolean.TRUE.equals(condition.get())) {\n                logger.warn(\"retry succeeded after {} attempt(s): {}\", attempt, description);\n                return true;\n            }\n            logger.warn(\"retry attempt {}/{} failed for: {}\", attempt, maxAttempts, description);\n        }\n\n        // Log failure with driver state for diagnostics\n        logger.warn(\"retry FAILED after {} attempts: {} | {}\", maxAttempts, description, getDriverState());\n        return false;\n    }\n\n    /**\n     * Centralized retry mechanism using default options.\n     */\n    private boolean retry(String description, Supplier<Boolean> condition) {\n        return retry(description, condition, options.getRetryCount(), options.getRetryInterval());\n    }\n\n    /**\n     * Get current driver state for diagnostic logging.\n     * Captures key state that helps debug flaky test failures.\n     */\n    private String getDriverState() {\n        StringBuilder sb = new StringBuilder();\n        sb.append(\"url=\");\n        try {","sourceCodeStart":4272,"sourceCodeEnd":4308,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L4272-L4308","documentation":"WARN log emitted when the CDP driver's retry helper exhausts all maxAttempts without the condition ever becoming true. The message includes the driver state snapshot (getDriverState()) to aid diagnosis. The helper returns false to its caller, which typically translates into a failed wait/timeout assertion in the test.","triggerScenarios":"The Supplier<Boolean> condition never returned true within maxAttempts × interval milliseconds — e.g. element never appeared, navigation never completed, expected driver state never reached.","commonSituations":"Wrong selector or frame; page crashed or navigated away; network failure loading the app; Chrome hung; timeout budget simply too small for a heavy page.","solutions":["Read the appended driver state in the log to see where the driver was stuck (URL, targets, readiness).","Verify the selector/URL/frame the condition targets is actually correct in the app under test.","Increase the retry timeout/interval if the app legitimately needs longer.","Check Chrome/network health; a crashed or unresponsive browser will never satisfy the condition."],"exampleFix":"// before: relying on default retries\ndriver.retry(interval, count, condition);\n// after: give a legitimately slow app more budget\ndriver.retry(2000, 15, condition); // 30s total instead of default","handlingStrategy":"retry","validationCode":"// Java-side guard before invoking a wait that relies on the retry helper\nif (!driverRetry.waitFor(description, condition, maxAttempts, interval)) {\n    throw new AssertionError(\"condition never satisfied: \" + description + \" | driver state: \" + driverState);\n}","typeGuard":null,"tryCatchPattern":"// treat the false return as a timeout failure\ncatch (AssertionError e) {\n    logger.error(\"retry exhausted: {}\", e.getMessage()); // inspect logged getDriverState()\n}","preventionTips":["Always read the driver-state snapshot in the log — it usually reveals whether the page, URL, or target was wrong.","Budget timeouts against slow CI machines, not local laptops.","Validate selectors/frames against the real app before long retry loops."],"tags":["cdp","retry","timeout","driver"],"backgroundTag":"request-timeout","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}