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

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: rebase 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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 if 'username' in cmd_dict_copy.keys(): 1055 if 'username' in cmd_dict_copy.keys():
1056 cmd_dict_copy['username'] = 'removed_username' 1056 cmd_dict_copy['username'] = 'removed_username'
1057 raise JSONInterfaceError('Automation call %s received empty response. ' 1057 raise JSONInterfaceError('Automation call %s received empty response. '
1058 'Additional information:\n%s' % (cmd_dict_copy, 1058 'Additional information:\n%s' % (cmd_dict_copy,
1059 additional_info)) 1059 additional_info))
1060 ret_dict = json.loads(result) 1060 ret_dict = json.loads(result)
1061 if ret_dict.has_key('error'): 1061 if ret_dict.has_key('error'):
1062 raise JSONInterfaceError(ret_dict['error']) 1062 raise JSONInterfaceError(ret_dict['error'])
1063 return ret_dict 1063 return ret_dict
1064 1064
1065 def NavigateToURL(self, url, windex=0, tab_index=0, navigation_count=1):
Nirnimesh 2012/07/03 23:13:26 maintain the order of args. tab_index should come
craigdh 2012/07/11 19:10:26 If you look at pyautolib.h you'll see that previou
1066 """Navigate the given tab to the given URL.
1067
1068 Note that this method also activates the corresponding tab/window
1069 if it's not active already. Blocks until page has loaded.
1070
1071 Args:
1072 url: The URL to which to navigate.
1073 windex: The index of the browser window to work on. Defaults to the first
1074 window.
1075 tab_index: The index of the tab to work on. Defaults to the first tab.
1076 navigation_count: the number of navigations to wait for. Defaults to 1.
1077 """
1078 cmd_dict = {
1079 'command': 'NavigateToURL',
1080 'url': url,
1081 'windex': windex,
1082 'tab_index': tab_index,
1083 'navigation_count': navigation_count,
1084 }
1085 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
Nirnimesh 2012/07/03 23:13:26 Can we return the result of the navigation in case
craigdh 2012/07/11 19:10:26 A quick grep of test/functional/* indicates no one
1086
1087 def ReloadTab(self, windex=0, tab_index=0):
1088 """Reload the given tab.
1089
1090 Blocks until the page has reloaded.
1091
1092 Args:
1093 windex: The index of the browser window to work on. Defaults to the first
1094 window.
1095 tab_index: The index of the tab to reload. Defaults to the first tab.
1096 """
1097 cmd_dict = {
1098 'command': 'Reload',
1099 'windex': windex,
1100 'tab_index': tab_index,
1101 }
1102 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
Nirnimesh 2012/07/03 23:13:26 windex=None here and all calls that are serviced f
craigdh 2012/07/11 19:10:26 Done.
1103
1104 def ReloadActiveTab(self, windex=0):
1105 """Reload an active tab.
1106
1107 Args:
1108 windex: The index of the browser window to work on. Defaults to the first
1109 window.
1110 """
1111 self.ReloadTab(windex, self.GetActiveTabIndex(windex))
1112
1113 def GetActiveTabIndex(self, windex=0):
1114 """Get the index of the currently active tab in the given browser window.
Nirnimesh 2012/07/03 23:13:26 It's generally not good to rely on the concept of
craigdh 2012/07/11 19:10:26 Done.
1115
1116 Args:
1117 windex: The index of the browser window to work on. Defaults to the first
1118 window.
1119
1120 Returns:
1121 An integer index for the currently active tab.
1122 """
1123 cmd_dict = {
1124 'command': 'GetActiveTabIndex',
1125 'windex': windex,
1126 }
1127 return self._GetResultFromJSONRequest(cmd_dict,
1128 windex=windex).get('tab_index')
1129
1130 def AppendTab(self, url, windex=0):
1131 """Append a new tab.
1132
1133 Creates a new tab at the end of given browser window and activates
1134 it. Blocks until the specified |url| is loaded.
1135
1136 Args:
1137 url: The url to load, can be string or a GURL object.
1138 windex: The index of the browser window to work on. Defaults to the first
1139 window.
1140
1141 Returns:
1142 True if the url loads successfully in the new tab. False otherwise.
1143 """
1144 if isinstance(url, GURL):
1145 url = url.spec()
1146 cmd_dict = {
1147 'command': 'AppendTab',
1148 'url': url,
1149 'windex': windex,
1150 }
1151 return self._GetResultFromJSONRequest(cmd_dict, windex=windex).get('result')
1152
1065 def GetBookmarkModel(self, windex=0): 1153 def GetBookmarkModel(self, windex=0):
1066 """Return the bookmark model as a BookmarkModel object. 1154 """Return the bookmark model as a BookmarkModel object.
1067 1155
1068 This is a snapshot of the bookmark model; it is not a proxy and 1156 This is a snapshot of the bookmark model; it is not a proxy and
1069 does not get updated as the bookmark model changes. 1157 does not get updated as the bookmark model changes.
1070 """ 1158 """
1071 bookmarks_as_json = self._GetBookmarksAsJSON(windex) 1159 bookmarks_as_json = self._GetBookmarksAsJSON(windex)
1072 if not bookmarks_as_json: 1160 if not bookmarks_as_json:
1073 raise JSONInterfaceError('Could not resolve browser proxy.') 1161 raise JSONInterfaceError('Could not resolve browser proxy.')
1074 return bookmark_model.BookmarkModel(bookmarks_as_json) 1162 return bookmark_model.BookmarkModel(bookmarks_as_json)
(...skipping 2084 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 """Removes all events currently in the AutomationEventQueue. 3247 """Removes all events currently in the AutomationEventQueue.
3160 3248
3161 Raises: 3249 Raises:
3162 pyauto_errors.JSONInterfaceError if the automation call returns an error. 3250 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3163 """ 3251 """
3164 cmd_dict = { 3252 cmd_dict = {
3165 'command': 'ClearEventQueue', 3253 'command': 'ClearEventQueue',
3166 } 3254 }
3167 return self._GetResultFromJSONRequest(cmd_dict, windex=None) 3255 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
3168 3256
3169 def AppendTab(self, url, windex=0):
3170 """Create a new tab.
3171
3172 Create a new tab at the end of given or first browser window
3173 and activate it. Blocks until the url is loaded.
3174
3175 Args:
3176 url: The url to load, can be string or a GURL object.
3177 windex: Index of the window to open a tab in. Default 0 - first window.
3178
3179 Returns:
3180 True on success.
3181 """
3182 if type(url) is GURL:
3183 gurl = url
3184 else:
3185 gurl = GURL(url)
3186 return pyautolib.PyUITestBase.AppendTab(self, gurl, windex)
3187
3188 def WaitUntilNavigationCompletes(self, tab_index=0, windex=0): 3257 def WaitUntilNavigationCompletes(self, tab_index=0, windex=0):
3189 """Wait until the specified tab is done navigating. 3258 """Wait until the specified tab is done navigating.
3190 3259
3191 It is safe to call ExecuteJavascript() as soon as the call returns. If 3260 It is safe to call ExecuteJavascript() as soon as the call returns. If
3192 there is no outstanding navigation the call will return immediately. 3261 there is no outstanding navigation the call will return immediately.
3193 3262
3194 Args: 3263 Args:
3195 tab_index: index of the tab. 3264 tab_index: index of the tab.
3196 windex: index of the window. 3265 windex: index of the window.
3197 3266
(...skipping 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after
6002 successful = result.wasSuccessful() 6071 successful = result.wasSuccessful()
6003 if not successful: 6072 if not successful:
6004 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6073 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6005 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6074 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6006 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6075 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6007 sys.exit(not successful) 6076 sys.exit(not successful)
6008 6077
6009 6078
6010 if __name__ == '__main__': 6079 if __name__ == '__main__':
6011 Main() 6080 Main()
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.cc ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698