Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 10692067: Convert PyAuto's NavigateToURL, GetActiveTabIndex, Refresh, RefreshActiveTab, and AppendTab to the … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed the return value of AppendTab. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """PyAuto: Python Interface to Chromium's Automation Proxy. 6 """PyAuto: Python Interface to Chromium's Automation Proxy.
7 7
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. 8 PyAuto uses swig to expose Automation Proxy interfaces to Python.
9 For complete documentation on the functionality available, 9 For complete documentation on the functionality available,
10 run pydoc on this file. 10 run pydoc on this file.
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 if 'username' in cmd_dict_copy.keys(): 1050 if 'username' in cmd_dict_copy.keys():
1051 cmd_dict_copy['username'] = 'removed_username' 1051 cmd_dict_copy['username'] = 'removed_username'
1052 raise JSONInterfaceError('Automation call %s received empty response. ' 1052 raise JSONInterfaceError('Automation call %s received empty response. '
1053 'Additional information:\n%s' % (cmd_dict_copy, 1053 'Additional information:\n%s' % (cmd_dict_copy,
1054 additional_info)) 1054 additional_info))
1055 ret_dict = json.loads(result) 1055 ret_dict = json.loads(result)
1056 if ret_dict.has_key('error'): 1056 if ret_dict.has_key('error'):
1057 raise JSONInterfaceError(ret_dict['error']) 1057 raise JSONInterfaceError(ret_dict['error'])
1058 return ret_dict 1058 return ret_dict
1059 1059
1060 def NavigateToURL(self, url, windex=0, tab_index=0, navigation_count=1):
1061 """Navigate the given tab to the given URL.
1062
1063 Note that this method also activates the corresponding tab/window
1064 if it's not active already. Blocks until page has loaded.
1065
1066 Args:
1067 url: The URL to which to navigate.
1068 windex: The index of the browser window to work on. Defaults to the first
1069 window.
1070 tab_index: The index of the tab to work on. Defaults to the first tab.
1071 navigation_count: the number of navigations to wait for. Defaults to 1.
1072 """
1073 cmd_dict = {
1074 'command': 'NavigateToURL',
1075 'url': url,
1076 'windex': windex,
1077 'tab_index': tab_index,
1078 'navigation_count': navigation_count,
1079 }
1080 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1081
1082 def ReloadTab(self, windex, tab_index):
dennis_jeffrey 2012/07/03 00:47:04 should we provide defaults of 0 for "windex" and "
craigdh 2012/07/03 16:48:08 Done.
1083 """Reload the given tab.
1084
1085 Blocks until the page has reloaded.
1086
1087 Args:
1088 windex: The index of the browser window to work on.
1089 tab_index: The index of the tab to reload.
1090 """
1091 cmd_dict = {
1092 'command': 'Reload',
1093 'windex': windex,
1094 'tab_index': tab_index,
1095 }
1096 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
1097
1098 def ReloadActiveTab(self, windex=0):
1099 """Reload an active tab.
1100
1101 Args:
1102 windex: The index of the browser window to work on. Defaults to the first
1103 window.
1104 """
1105 self.ReloadTab(windex, self.GetActiveTabIndex(windex))
1106
1107 def GetActiveTabIndex(self, windex=0):
1108 """Get the index of the currently active tab in the given browser window.
1109
1110 Args:
1111 windex: The index of the browser window to work on. Defaults to the first
1112 window.
dennis_jeffrey 2012/07/03 00:47:04 add a Returns: section to this docstring
craigdh 2012/07/03 16:48:08 Done.
1113 """
1114 cmd_dict = {
1115 'command': 'GetActiveTabIndex',
1116 'windex': windex,
1117 }
1118 return self._GetResultFromJSONRequest(cmd_dict,
1119 windex=windex).get('tab_index')
1120
1121 def AppendTab(self, url, windex=0):
1122 """Append a new tab.
1123
1124 Create a new tab at the end of given or first browser window and activate
1125 it. Blocks until the page is loaded.
dennis_jeffrey 2012/07/03 00:47:04 Creates a new tab at the end of the given browser
craigdh 2012/07/03 16:48:08 Done.
1126
1127 Args:
1128 url: The url to load, can be string or a GURL object.
1129 windex: The index of the browser window to work on. Defaults to the first
1130 window.
dennis_jeffrey 2012/07/03 00:47:04 add a Returns: section to this docstring.
craigdh 2012/07/03 16:48:08 Done.
1131 """
1132 if isinstance(url, GURL):
1133 url = url.spec()
1134 cmd_dict = {
1135 'command': 'AppendTab',
1136 'url': url,
1137 'windex': windex,
1138 }
1139 return self._GetResultFromJSONRequest(cmd_dict, windex=windex).get('result')
1140
1060 def GetBookmarkModel(self, windex=0): 1141 def GetBookmarkModel(self, windex=0):
1061 """Return the bookmark model as a BookmarkModel object. 1142 """Return the bookmark model as a BookmarkModel object.
1062 1143
1063 This is a snapshot of the bookmark model; it is not a proxy and 1144 This is a snapshot of the bookmark model; it is not a proxy and
1064 does not get updated as the bookmark model changes. 1145 does not get updated as the bookmark model changes.
1065 """ 1146 """
1066 bookmarks_as_json = self._GetBookmarksAsJSON(windex) 1147 bookmarks_as_json = self._GetBookmarksAsJSON(windex)
1067 if not bookmarks_as_json: 1148 if not bookmarks_as_json:
1068 raise JSONInterfaceError('Could not resolve browser proxy.') 1149 raise JSONInterfaceError('Could not resolve browser proxy.')
1069 return bookmark_model.BookmarkModel(bookmarks_as_json) 1150 return bookmark_model.BookmarkModel(bookmarks_as_json)
(...skipping 2084 matching lines...) Expand 10 before | Expand all | Expand 10 after
3154 """Removes all events currently in the AutomationEventQueue. 3235 """Removes all events currently in the AutomationEventQueue.
3155 3236
3156 Raises: 3237 Raises:
3157 pyauto_errors.JSONInterfaceError if the automation call returns an error. 3238 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3158 """ 3239 """
3159 cmd_dict = { 3240 cmd_dict = {
3160 'command': 'ClearEventQueue', 3241 'command': 'ClearEventQueue',
3161 } 3242 }
3162 return self._GetResultFromJSONRequest(cmd_dict, windex=None) 3243 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
3163 3244
3164 def AppendTab(self, url, windex=0):
3165 """Create a new tab.
3166
3167 Create a new tab at the end of given or first browser window
3168 and activate it. Blocks until the url is loaded.
3169
3170 Args:
3171 url: The url to load, can be string or a GURL object.
3172 windex: Index of the window to open a tab in. Default 0 - first window.
3173
3174 Returns:
3175 True on success.
3176 """
3177 if type(url) is GURL:
3178 gurl = url
3179 else:
3180 gurl = GURL(url)
3181 return pyautolib.PyUITestBase.AppendTab(self, gurl, windex)
3182
3183 def WaitUntilNavigationCompletes(self, tab_index=0, windex=0): 3245 def WaitUntilNavigationCompletes(self, tab_index=0, windex=0):
3184 """Wait until the specified tab is done navigating. 3246 """Wait until the specified tab is done navigating.
3185 3247
3186 It is safe to call ExecuteJavascript() as soon as the call returns. If 3248 It is safe to call ExecuteJavascript() as soon as the call returns. If
3187 there is no outstanding navigation the call will return immediately. 3249 there is no outstanding navigation the call will return immediately.
3188 3250
3189 Args: 3251 Args:
3190 tab_index: index of the tab. 3252 tab_index: index of the tab.
3191 windex: index of the window. 3253 windex: index of the window.
3192 3254
(...skipping 2794 matching lines...) Expand 10 before | Expand all | Expand 10 after
5987 successful = result.wasSuccessful() 6049 successful = result.wasSuccessful()
5988 if not successful: 6050 if not successful:
5989 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6051 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5990 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6052 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5991 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6053 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5992 sys.exit(not successful) 6054 sys.exit(not successful)
5993 6055
5994 6056
5995 if __name__ == '__main__': 6057 if __name__ == '__main__':
5996 Main() 6058 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698