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

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: Addressed Nirnimesh's comments. 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):
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=None)
1086
1087 def ReloadTab(self, tab_index=0, windex=0):
1088 """Reload the given tab.
1089
1090 Blocks until the page has reloaded.
1091
1092 Args:
1093 tab_index: The index of the tab to reload. Defaults to the first tab.
1094 windex: The index of the browser window to work on. Defaults to the first
1095 window.
1096 """
1097 cmd_dict = {
1098 'command': 'Reload',
1099 'tab_index': tab_index,
1100 'windex': windex,
1101 }
1102 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1103
1104 def ReloadActiveTab(self, windex=0):
1105 """Reload an active tab.
1106
1107 Warning: Depending on the concept of an active tab is dangerous as it can
1108 change during the test. Use ReloadTab and supply a tab_index explicitly.
1109
1110 Args:
1111 windex: The index of the browser window to work on. Defaults to the first
1112 window.
1113 """
1114 self.ReloadTab(windex, self.GetActiveTabIndex(windex))
1115
1116 def GetActiveTabIndex(self, windex=0):
1117 """Get the index of the currently active tab in the given browser window.
1118
1119 Warning: Depending on the concept of an active tab is dangerous as it can
1120 change during the test. Supply the tab_index explicitly, if possible.
1121
1122 Args:
1123 windex: The index of the browser window to work on. Defaults to the first
1124 window.
1125
1126 Returns:
1127 An integer index for the currently active tab.
1128 """
1129 cmd_dict = {
1130 'command': 'GetActiveTabIndex',
1131 'windex': windex,
1132 }
1133 return self._GetResultFromJSONRequest(cmd_dict,
1134 windex=None).get('tab_index')
1135
1136 def AppendTab(self, url, windex=0):
1137 """Append a new tab.
1138
1139 Creates a new tab at the end of given browser window and activates
1140 it. Blocks until the specified |url| is loaded.
1141
1142 Args:
1143 url: The url to load, can be string or a GURL object.
1144 windex: The index of the browser window to work on. Defaults to the first
1145 window.
1146
1147 Returns:
1148 True if the url loads successfully in the new tab. False otherwise.
1149 """
1150 if isinstance(url, GURL):
1151 url = url.spec()
1152 cmd_dict = {
1153 'command': 'AppendTab',
1154 'url': url,
1155 'windex': windex,
1156 }
1157 return self._GetResultFromJSONRequest(cmd_dict, windex=None).get('result')
1158
1065 def GetBookmarkModel(self, windex=0): 1159 def GetBookmarkModel(self, windex=0):
1066 """Return the bookmark model as a BookmarkModel object. 1160 """Return the bookmark model as a BookmarkModel object.
1067 1161
1068 This is a snapshot of the bookmark model; it is not a proxy and 1162 This is a snapshot of the bookmark model; it is not a proxy and
1069 does not get updated as the bookmark model changes. 1163 does not get updated as the bookmark model changes.
1070 """ 1164 """
1071 bookmarks_as_json = self._GetBookmarksAsJSON(windex) 1165 bookmarks_as_json = self._GetBookmarksAsJSON(windex)
1072 if not bookmarks_as_json: 1166 if not bookmarks_as_json:
1073 raise JSONInterfaceError('Could not resolve browser proxy.') 1167 raise JSONInterfaceError('Could not resolve browser proxy.')
1074 return bookmark_model.BookmarkModel(bookmarks_as_json) 1168 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. 3253 """Removes all events currently in the AutomationEventQueue.
3160 3254
3161 Raises: 3255 Raises:
3162 pyauto_errors.JSONInterfaceError if the automation call returns an error. 3256 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3163 """ 3257 """
3164 cmd_dict = { 3258 cmd_dict = {
3165 'command': 'ClearEventQueue', 3259 'command': 'ClearEventQueue',
3166 } 3260 }
3167 return self._GetResultFromJSONRequest(cmd_dict, windex=None) 3261 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
3168 3262
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): 3263 def WaitUntilNavigationCompletes(self, tab_index=0, windex=0):
3189 """Wait until the specified tab is done navigating. 3264 """Wait until the specified tab is done navigating.
3190 3265
3191 It is safe to call ExecuteJavascript() as soon as the call returns. If 3266 It is safe to call ExecuteJavascript() as soon as the call returns. If
3192 there is no outstanding navigation the call will return immediately. 3267 there is no outstanding navigation the call will return immediately.
3193 3268
3194 Args: 3269 Args:
3195 tab_index: index of the tab. 3270 tab_index: index of the tab.
3196 windex: index of the window. 3271 windex: index of the window.
3197 3272
(...skipping 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after
6002 successful = result.wasSuccessful() 6077 successful = result.wasSuccessful()
6003 if not successful: 6078 if not successful:
6004 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6079 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6005 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6080 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6006 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6081 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6007 sys.exit(not successful) 6082 sys.exit(not successful)
6008 6083
6009 6084
6010 if __name__ == '__main__': 6085 if __name__ == '__main__':
6011 Main() 6086 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