Skip to content

Commit

Permalink
Correcting error statuses returned for switching frames in IE
Browse files Browse the repository at this point in the history
The IE driver now returns the correct status as specified by the W3C
WebDriver Specification for error conditions encountered when
attempting to switch frames.
  • Loading branch information
jimevans committed Jan 24, 2019
1 parent 7c87e88 commit ae76e25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cpp/iedriver/CommandHandlers/SwitchToFrameCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,41 @@ void SwitchToFrameCommandHandler::ExecuteInternal(
return;
}

std::string error_message = "No frame found";
if (frame_id.isNull()) {
status_code = browser_wrapper->SetFocusedFrameByElement(NULL);
} else if (frame_id.isObject()) {
Json::Value element_id = frame_id.get(JSON_ELEMENT_PROPERTY_NAME, Json::Value::null);

if (element_id.isNull()) {
status_code = ENOSUCHFRAME;
status_code = EINVALIDARGUMENT;
error_message = "Frame identifier was an object, but not a web element reference";
} else {
std::string frame_element_id = element_id.asString();

ElementHandle frame_element_wrapper;
status_code = this->GetElement(executor,
frame_element_id,
&frame_element_wrapper);
frame_element_id,
&frame_element_wrapper);
if (status_code == WD_SUCCESS) {
status_code = browser_wrapper->SetFocusedFrameByElement(frame_element_wrapper->element());
}
}
} else if(frame_id.isIntegral()) {
int frame_index = frame_id.asInt();
status_code = browser_wrapper->SetFocusedFrameByIndex(frame_index);
if (frame_index < 0 || frame_index > 65535) {
status_code = EINVALIDARGUMENT;
error_message = "Frame identifier was an integer, but must be between 0 and 65535 inclusive";
} else {
status_code = browser_wrapper->SetFocusedFrameByIndex(frame_index);
}
} else {
status_code = EINVALIDARGUMENT;
error_message = "Frame identifier argument must be null, an integer, or a web element reference";
}

if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "No frame found");
response->SetErrorResponse(status_code, error_message);
} else {
response->SetSuccessResponse(Json::Value::null);
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/webdriver-server/response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ std::string Response::ConvertErrorCode(const int error_code) {
return ERROR_MOVE_TARGET_OUT_OF_BOUNDS;
} else if (error_code == EINVALIDARGUMENT) {
return ERROR_INVALID_ARGUMENT;
} else if (error_code == ENOSUCHELEMENT) {
return ERROR_NO_SUCH_ELEMENT;
}

return "";
Expand Down

0 comments on commit ae76e25

Please sign in to comment.