Commit aa524e49 authored by craigdh@chromium.org's avatar craigdh@chromium.org

Improve pyautolib errors.

Adds a new pyauto exception for failures caught by automation calls (inherits from JSONInterfaceError).
Improves the error messages generated for automation infrastructure failures.

TEST=Manually caused automation commands to fail and verified error messages.
BUG=132803

Review URL: https://chromiumcodereview.appspot.com/10855161

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151853 0039d316-1c4b-4281-b951-d872f2087c98
parent 74bb1ef7
...@@ -60,7 +60,7 @@ class TabTracker(object): ...@@ -60,7 +60,7 @@ class TabTracker(object):
tab_uuid: the uuid of the tab to close tab_uuid: the uuid of the tab to close
""" """
idx = self.GetTabIndex(tab_uuid) idx = self.GetTabIndex(tab_uuid)
self._browser.GetBrowserWindow(self._window_idx).GetTab(idx).Close() self._browser.CloseTab(tab_index=idx, windex=self._window_idx)
del self._uuids[idx] del self._uuids[idx]
def GetTabIndex(self, tab_uuid): def GetTabIndex(self, tab_uuid):
......
...@@ -74,4 +74,4 @@ class WebrtcBrutalityTest(webrtc_test_base.WebrtcTestBase): ...@@ -74,4 +74,4 @@ class WebrtcBrutalityTest(webrtc_test_base.WebrtcTestBase):
if __name__ == '__main__': if __name__ == '__main__':
pyauto_functional.Main() pyauto_functional.Main()
\ No newline at end of file
...@@ -84,6 +84,7 @@ import history_info ...@@ -84,6 +84,7 @@ import history_info
import omnibox_info import omnibox_info
import plugins_info import plugins_info
import prefs_info import prefs_info
from pyauto_errors import AutomationCommandFail
from pyauto_errors import JavascriptRuntimeError from pyauto_errors import JavascriptRuntimeError
from pyauto_errors import JSONInterfaceError from pyauto_errors import JSONInterfaceError
from pyauto_errors import NTPThumbnailNotShownError from pyauto_errors import NTPThumbnailNotShownError
...@@ -1103,7 +1104,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): ...@@ -1103,7 +1104,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
additional_info)) additional_info))
ret_dict = json.loads(result) ret_dict = json.loads(result)
if ret_dict.has_key('error'): if ret_dict.has_key('error'):
raise JSONInterfaceError(ret_dict['error']) if ret_dict.get('is_interface_error'):
raise JSONInterfaceError(ret_dict['error'])
else:
raise AutomationCommandFail(ret_dict['error'])
return ret_dict return ret_dict
def NavigateToURL(self, url, windex=0, tab_index=None, navigation_count=1): def NavigateToURL(self, url, windex=0, tab_index=None, navigation_count=1):
......
...@@ -10,7 +10,15 @@ class JavascriptRuntimeError(RuntimeError): ...@@ -10,7 +10,15 @@ class JavascriptRuntimeError(RuntimeError):
class JSONInterfaceError(RuntimeError): class JSONInterfaceError(RuntimeError):
"""Represent an error in the JSON ipc interface.""" """Represent an error in the JSON IPC interface."""
pass
class AutomationCommandFail(JSONInterfaceError):
"""Represent an automation command failure.
These failures are passed back from the Chrome side of the IPC.
"""
pass pass
......
...@@ -104,20 +104,19 @@ AutomationProxy* PyUITestBase::automation() const { ...@@ -104,20 +104,19 @@ AutomationProxy* PyUITestBase::automation() const {
return automation_proxy; return automation_proxy;
} }
scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) {
return automation()->GetBrowserWindow(window_index);
}
std::string PyUITestBase::_SendJSONRequest(int window_index, std::string PyUITestBase::_SendJSONRequest(int window_index,
const std::string& request, const std::string& request,
int timeout) { int timeout) {
std::string response; std::string response;
bool success; bool success;
AutomationMessageSender* automation_sender = automation(); AutomationProxy* automation_sender = automation();
base::TimeTicks time = base::TimeTicks::Now(); base::TimeTicks time = base::TimeTicks::Now();
if (!automation_sender) { if (!automation_sender) {
ErrorResponse("The automation proxy does not exist", request, &response); ErrorResponse("Automation proxy does not exist", request, &response);
} else if (!automation_sender->channel()) {
ErrorResponse("Chrome automation IPC channel was found already broken",
request, &response);
} else if (!automation_sender->Send( } else if (!automation_sender->Send(
new AutomationMsg_SendJSONRequest(window_index, request, &response, new AutomationMsg_SendJSONRequest(window_index, request, &response,
&success), &success),
...@@ -138,6 +137,7 @@ void PyUITestBase::ErrorResponse( ...@@ -138,6 +137,7 @@ void PyUITestBase::ErrorResponse(
request.c_str()); request.c_str());
LOG(ERROR) << "Error during automation: " << error_msg; LOG(ERROR) << "Error during automation: " << error_msg;
error_dict.SetString("error", error_msg); error_dict.SetString("error", error_msg);
error_dict.SetBoolean("is_interface_error", true);
base::JSONWriter::Write(&error_dict, response); base::JSONWriter::Write(&error_dict, response);
} }
...@@ -149,11 +149,13 @@ void PyUITestBase::RequestFailureResponse( ...@@ -149,11 +149,13 @@ void PyUITestBase::RequestFailureResponse(
// TODO(craigdh): Determine timeout directly from IPC's Send(). // TODO(craigdh): Determine timeout directly from IPC's Send().
if (duration >= timeout) { if (duration >= timeout) {
ErrorResponse( ErrorResponse(
StringPrintf("Request timed out after %d seconds", StringPrintf("Chrome automation timed out after %d seconds",
static_cast<int>(duration.InSeconds())), static_cast<int>(duration.InSeconds())),
request, response); request, response);
} else { } else {
// TODO(craigdh): Determine specific cause. // TODO(craigdh): Determine specific cause.
ErrorResponse("Chrome failed to respond", request, response); ErrorResponse(
"Chrome automation failed prior to timing out, did chrome crash?",
request, response);
} }
} }
...@@ -71,9 +71,6 @@ class PyUITestBase : public UITestBase { ...@@ -71,9 +71,6 @@ class PyUITestBase : public UITestBase {
// AutomationProxy methods // AutomationProxy methods
// Get a handle to browser window at the given index, or NULL on failure.
scoped_refptr<BrowserProxy> GetBrowserWindow(int window_index);
// Meta-methods. Generic pattern of passing args and response as // Meta-methods. Generic pattern of passing args and response as
// JSON dict to avoid future use of the SWIG interface and // JSON dict to avoid future use of the SWIG interface and
// automation proxy additions. Returns response as JSON dict. // automation proxy additions. Returns response as JSON dict.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment