Skip to content

Commit

Permalink
Correcting invalid session ID response JSON payload for IE driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jul 10, 2018
1 parent 67b6c8d commit 94678f7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cpp/webdriver-server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstring>
#include <sstream>
#include "session.h"
#include "errorcodes.h"
#include "uri_info.h"
#include "logging.h"

Expand Down Expand Up @@ -340,7 +341,8 @@ std::string Server::DispatchCommand(const std::string& uri,

if (command == webdriver::CommandType::NoCommand) {
// Hand-code the response for an unknown URL
serialized_response.append("{ \"error\" : \"unknown method\", ");
serialized_response.append("{ \"value\" : { ");
serialized_response.append("\"error\" : \"unknown method\", ");
serialized_response.append("\"message\" : \"Command not found: ");
serialized_response.append(http_verb);
serialized_response.append(" ");
Expand All @@ -364,18 +366,23 @@ std::string Server::DispatchCommand(const std::string& uri,
serialized_response.append("{ \"value\" : null }");
} else {
// Hand-code the response for an invalid session id
serialized_response.append("{ \"error\" : \"invalid session id\", ");
serialized_response.append("{ \"value\" : { ");
serialized_response.append("\"error\" : \"");
serialized_response.append(ERROR_INVALID_SESSION_ID).append("\", ");
serialized_response.append("\"message\" : \"session ");
serialized_response.append(session_id);
serialized_response.append(" does not exist\" }");
serialized_response.append(" does not exist\", ");
serialized_response.append("\"stacktrace\" : \"\" }");
serialized_response.append("}");
}
} else {
if (command == webdriver::CommandType::NewSession &&
this->sessions_.size() > 0) {
// According to the W3C Specification, only a single session is
// allowed by a single driver instance.
serialized_response.append("{ \"value\" : { ");
serialized_response.append("\"error\" : \"session not created\", ");
serialized_response.append("\"error\" : \"");
serialized_response.append(ERROR_SESSION_NOT_CREATED).append("\", ");
serialized_response.append("\"message\" : \"only one session may ");
serialized_response.append("be created at a time, and a session ");
serialized_response.append("already exists\", ");
Expand Down

0 comments on commit 94678f7

Please sign in to comment.