{"record":{"id":"5cd3531a84d7958c","repo":"karatelabs/karate","slug":"webdriver-session-create-failed-e-getmessage","errorCode":null,"errorMessage":"WebDriver session create failed: \" + e.getMessage()","messagePattern":"WebDriver session create failed: \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java","lineNumber":129,"sourceCode":"            if (response.statusCode() != 200) {\n                throw new DriverException(\"WebDriver session create failed with status \"\n                        + response.statusCode() + \": \" + response.body());\n            }\n\n            Map<String, Object> body = Json.of(response.body()).asMap();\n            Map<String, Object> value = (Map<String, Object>) body.get(\"value\");\n            String sessionId = (String) value.get(\"sessionId\");\n            if (sessionId == null) {\n                throw new DriverException(\"WebDriver session create response missing sessionId: \" + response.body());\n            }\n\n            logger.info(\"W3C session created: {}\", sessionId);\n            return new W3cSession(client, baseUrl, sessionId, timeout);\n        } catch (IOException | InterruptedException e) {\n            if (e instanceof InterruptedException) {\n                Thread.currentThread().interrupt();\n            }\n            throw new DriverException(\"WebDriver session create failed: \" + e.getMessage(), e);\n        }\n    }\n\n    // ========== Navigation ==========\n\n    public void navigateTo(String url) {\n        post(\"url\", Map.of(\"url\", url));\n    }\n\n    public String getUrl() {\n        return (String) getValue(get(\"url\"));\n    }\n\n    public String getTitle() {\n        return (String) getValue(get(\"title\"));\n    }\n\n    public void back() {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cSession.java#L111-L147","documentation":"W3cSession.create wraps IOException/InterruptedException from the HTTP exchange in a DriverException 'WebDriver session create failed: <cause message>'. This is the transport-level failure path: the request to the WebDriver server could not be completed at all (connection refused, reset, or the thread was interrupted).","triggerScenarios":"POST /session fails at the network layer — driver process died between startup and session creation, wrong host/port, TLS/proxy issues, or the waiting thread was interrupted while blocked on client.send().","commonSituations":"Driver crashed right after startup (check driver logs); firewall blocking the port; connecting to a remote grid that is down; test harness shutting down and interrupting the driver-start thread.","solutions":["Check the wrapped cause (e.getMessage / getCause) — 'Connection refused' means nothing is listening on host:port","Verify the WebDriver server is running and reachable (curl http://host:port/status)","Correct the host/port configuration or restart the driver binary","If InterruptedException, avoid interrupting driver startup threads and check for premature framework shutdown"],"exampleFix":"// before\nMap<String, Object> opts = MapUtils.of(\"type\", \"chromedriver\", \"port\", 9515, \"host\", \"10.0.0.99\"); // grid down\n// after\nMap<String, Object> opts = MapUtils.of(\"type\", \"chromedriver\", \"port\", 9515, \"host\", \"localhost\");\n// and pre-check: curl http://localhost:9515/status before starting the session","handlingStrategy":"retry","validationCode":"// reachability probe before session create\ntry (Socket s = new Socket(host, port)) { /* endpoint listening */ } catch (IOException e) { /* abort or restart driver */ }","typeGuard":null,"tryCatchPattern":"try {\n    session = W3cSession.create(client, baseUrl, caps, timeout);\n} catch (DriverException e) {\n    if (e.getCause() instanceof IOException) {\n        // restart driver binary / fix host:port, then retry with backoff\n    }\n}","preventionTips":["Check driver process health (it may have crashed after startup)","Verify host/port with a /status probe before each run","Avoid interrupting threads that are starting driver sessions"],"tags":["webdriver","session","network","connection"],"backgroundTag":"connection-refused","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"}