Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions java/client/src/org/openqa/selenium/remote/ProtocolHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,32 @@ private Optional<Result> createSession(HttpClient client, InputStream newSession
jsonBlob = new HashMap<>();
}

// If the result looks positive, return the result.
Object sessionId = jsonBlob.get("sessionId");
Object value = jsonBlob.get("value");
Object w3cError = jsonBlob.get("error");
Object ossStatus = jsonBlob.get("status");

// If the result was an error that we believe has to do with the remote end failing to start the
// session, create an exception and throw it.
Response tempResponse = null;
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
tempResponse = new Response(null);
tempResponse.setStatus(ErrorCodes.SESSION_NOT_CREATED);
tempResponse.setValue(value);
} else if ("session not created".equals(w3cError)) {
tempResponse = new Response(null);
tempResponse.setStatus(ErrorCodes.SESSION_NOT_CREATED);
tempResponse.setValue(value);
} else if (ossStatus instanceof Number && ((Number) ossStatus).intValue() != 0) {
tempResponse = new Response(null);
tempResponse.setStatus(ErrorCodes.SESSION_NOT_CREATED);
tempResponse.setValue(value);
}

if (tempResponse != null) {
new ErrorHandler().throwIfResponseFailed(tempResponse, 0);
}

Object sessionId = jsonBlob.get("sessionId");
Map<String, ?> capabilities = null;

// The old geckodriver prior to 0.14 returned "value" as the thing containing the session id.
Expand All @@ -342,29 +363,10 @@ private Optional<Result> createSession(HttpClient client, InputStream newSession
capabilities = ((Capabilities) capabilities).asMap();
}

if (response.getStatus() == HttpURLConnection.HTTP_OK) {
if (sessionId != null && capabilities != null) {
Dialect dialect = ossStatus == null ? Dialect.W3C : Dialect.OSS;
return Optional.of(
new Result(dialect, String.valueOf(sessionId), capabilities));
}
}

// If the result was an error that we believe has to do with the remote end failing to start the
// session, create an exception and throw it.
Response tempResponse = null;
if ("session not created".equals(w3cError)) {
tempResponse = new Response(null);
tempResponse.setStatus(ErrorCodes.SESSION_NOT_CREATED);
tempResponse.setValue(jsonBlob);
} else if (ossStatus instanceof Number) {
tempResponse = new Response(null);
tempResponse.setStatus(ErrorCodes.SESSION_NOT_CREATED);
tempResponse.setValue(jsonBlob);
}

if (tempResponse != null) {
new ErrorHandler().throwIfResponseFailed(tempResponse, 0);
// If the result looks positive, return the result.
if (sessionId != null && capabilities != null) {
Dialect dialect = ossStatus == null ? Dialect.W3C : Dialect.OSS;
return Optional.of(new Result(dialect, String.valueOf(sessionId), capabilities));
}

// Otherwise, just return empty.
Expand Down