Skip to content

Commit

Permalink
Adding additional error message info to navigation methods in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Aug 8, 2019
1 parent 0223766 commit fd6981b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
10 changes: 8 additions & 2 deletions cpp/iedriver/Browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,27 @@ void Browser::Close() {
}
}

int Browser::NavigateToUrl(const std::string& url) {
int Browser::NavigateToUrl(const std::string& url,
std::string* error_message) {
LOG(TRACE) << "Entring Browser::NavigateToUrl";

std::wstring wide_url = StringUtilities::ToWString(url);
CComVariant url_variant(wide_url.c_str());
CComVariant dummy;

// TODO: check HRESULT for error
HRESULT hr = this->browser_->Navigate2(&url_variant,
&dummy,
&dummy,
&dummy,
&dummy);
if (FAILED(hr)) {
LOGHR(WARN, hr) << "Call to IWebBrowser2::Navigate2 failed";
_com_error error(hr);
std::wstring formatted_message = StringUtilities::Format(
L"Received error: 0x%08x ['%s']",
hr,
error.ErrorMessage());
*error_message = StringUtilities::ToString(formatted_message);
return EUNHANDLEDERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/iedriver/Browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
void SetWidth(long width);
void SetHeight(long height);

int NavigateToUrl(const std::string& url);
int NavigateToUrl(const std::string& url, std::string* error_message);
int NavigateBack(void);
int NavigateForward(void);
int Refresh(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ void CreateNewWindowCommandHandler::ExecuteInternal(
if (window_type == WINDOW_WINDOW_TYPE) {
BrowserHandle tmp_browser;
executor.GetManagedBrowser(new_window_handle, &tmp_browser);
tmp_browser->NavigateToUrl("about:blank");
std::string error_message = "";
tmp_browser->NavigateToUrl("about:blank", &error_message);
}
Json::Value result;
result["handle"] = new_window_handle;
Expand Down
7 changes: 5 additions & 2 deletions cpp/iedriver/CommandHandlers/GoToUrlCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ void GoToUrlCommandHandler::ExecuteInternal(
if (browser_wrapper->IsCrossZoneUrl(url)) {
browser_wrapper->InitiateBrowserReattach();
}
status_code = browser_wrapper->NavigateToUrl(url);
std::string error_message = "";
status_code = browser_wrapper->NavigateToUrl(url, &error_message);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(ERROR_UNKNOWN_ERROR, "Failed to navigate to "
+ url
+ ". This usually means that a call to the COM method IWebBrowser2::Navigate2() failed.");
+ ". This usually means that a call to the COM method "
+ "IWebBrowser2::Navigate2() failed. The error returned is: "
+ error_message);
return;
}
browser_wrapper->SetFocusedFrameByElement(NULL);
Expand Down
3 changes: 2 additions & 1 deletion cpp/iedriver/DocumentHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class DocumentHost {
virtual void SetWidth(long width) = 0;
virtual void SetHeight(long height) = 0;

virtual int NavigateToUrl(const std::string& url) = 0;
virtual int NavigateToUrl(const std::string& url,
std::string* error_message) = 0;
virtual int NavigateBack(void) = 0;
virtual int NavigateForward(void) = 0;
virtual int Refresh(void) = 0;
Expand Down
3 changes: 2 additions & 1 deletion cpp/iedriver/HtmlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void HtmlDialog::SetHeight(long height) {
LOG(TRACE) << "Entering HtmlDialog::SetHeight";
}

int HtmlDialog::NavigateToUrl(const std::string& url) {
int HtmlDialog::NavigateToUrl(const std::string& url,
std::string* error_message) {
LOG(TRACE) << "Entering HtmlDialog::NavigateToUrl";
// Cannot force navigation on windows opened with showModalDialog();
return ENOTIMPLEMENTED;
Expand Down
2 changes: 1 addition & 1 deletion cpp/iedriver/HtmlDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class HtmlDialog : public DocumentHost, public IDispEventSimpleImpl<1, HtmlDialo
void SetWidth(long width);
void SetHeight(long height);

int NavigateToUrl(const std::string& url);
int NavigateToUrl(const std::string& url, std::string* error_message);
int NavigateBack(void);
int NavigateForward(void);
int Refresh(void);
Expand Down

0 comments on commit fd6981b

Please sign in to comment.