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

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

Issue 10790055: Convert more PyAuto proxy calls to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ensure the returned Python string is of type str, not unicode, before passing to GURL. 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
« no previous file with comments | « chrome/test/functional/popups.py ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 'windex': windex, 1157 'windex': windex,
1158 } 1158 }
1159 return self._GetResultFromJSONRequest(cmd_dict, windex=None).get('enabled') 1159 return self._GetResultFromJSONRequest(cmd_dict, windex=None).get('enabled')
1160 1160
1161 def ReloadTab(self, tab_index=0, windex=0): 1161 def ReloadTab(self, tab_index=0, windex=0):
1162 """Reload the given tab. 1162 """Reload the given tab.
1163 1163
1164 Blocks until the page has reloaded. 1164 Blocks until the page has reloaded.
1165 1165
1166 Args: 1166 Args:
1167 tab_index: The index of the tab to reload. Defaults to the first tab. 1167 tab_index: The index of the tab to reload. Defaults to 0.
1168 windex: The index of the browser window to work on. Defaults to the first 1168 windex: The index of the browser window to work on. Defaults to the first
1169 window. 1169 window.
1170 1170
1171 Raises: 1171 Raises:
1172 pyauto_errors.JSONInterfaceError if the automation call returns an error. 1172 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1173 """ 1173 """
1174 cmd_dict = { 1174 cmd_dict = {
1175 'command': 'Reload', 1175 'command': 'Reload',
1176 'tab_index': tab_index, 1176 'tab_index': tab_index,
1177 'windex': windex, 1177 'windex': windex,
(...skipping 28 matching lines...) Expand all
1206 Returns: 1206 Returns:
1207 An integer index for the currently active tab. 1207 An integer index for the currently active tab.
1208 """ 1208 """
1209 cmd_dict = { 1209 cmd_dict = {
1210 'command': 'GetActiveTabIndex', 1210 'command': 'GetActiveTabIndex',
1211 'windex': windex, 1211 'windex': windex,
1212 } 1212 }
1213 return self._GetResultFromJSONRequest(cmd_dict, 1213 return self._GetResultFromJSONRequest(cmd_dict,
1214 windex=None).get('tab_index') 1214 windex=None).get('tab_index')
1215 1215
1216 def ActivateTab(self, tab_index=0, windex=0):
1217 """Activates the given tab in the specified window.
1218
1219 Warning: Depending on the concept of an active tab is dangerous as it can
1220 change during the test. Instead use functions that accept a tab_index
1221 explicitly.
1222
1223 Args:
1224 tab_index: Integer index of the tab to activate; defaults to 0.
1225 windex: Integer index of the browser window to use; defaults to the first
1226 window.
1227
1228 Raises:
1229 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1230 """
1231 cmd_dict = {
1232 'command': 'ActivateTab',
1233 'tab_index': tab_index,
1234 'windex': windex,
1235 }
1236 self.BringBrowserToFront(windex)
1237 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1238
1239 def BringBrowserToFront(self, windex=0):
1240 """Activate the browser's window and bring it to front.
1241
1242 Args:
1243 windex: Integer index of the browser window to use; defaults to the first
1244 window.
1245
1246 Raises:
1247 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1248 """
1249 cmd_dict = {
1250 'command': 'BringBrowserToFront',
1251 'windex': windex,
1252 }
1253 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1254
1216 def AppendTab(self, url, windex=0): 1255 def AppendTab(self, url, windex=0):
1217 """Append a new tab. 1256 """Append a new tab.
1218 1257
1219 Creates a new tab at the end of given browser window and activates 1258 Creates a new tab at the end of given browser window and activates
1220 it. Blocks until the specified |url| is loaded. 1259 it. Blocks until the specified |url| is loaded.
1221 1260
1222 Args: 1261 Args:
1223 url: The url to load, can be string or a GURL object. 1262 url: The url to load, can be string or a GURL object.
1224 windex: The index of the browser window to work on. Defaults to the first 1263 windex: The index of the browser window to work on. Defaults to the first
1225 window. 1264 window.
1226 1265
1227 Returns: 1266 Returns:
1228 True if the url loads successfully in the new tab. False otherwise. 1267 True if the url loads successfully in the new tab. False otherwise.
1229 1268
1230 Raises: 1269 Raises:
1231 pyauto_errors.JSONInterfaceError if the automation call returns an error. 1270 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1232 """ 1271 """
1233 if isinstance(url, GURL): 1272 if isinstance(url, GURL):
1234 url = url.spec() 1273 url = url.spec()
1235 cmd_dict = { 1274 cmd_dict = {
1236 'command': 'AppendTab', 1275 'command': 'AppendTab',
1237 'url': url, 1276 'url': url,
1238 'windex': windex, 1277 'windex': windex,
1239 } 1278 }
1240 return self._GetResultFromJSONRequest(cmd_dict, windex=None).get('result') 1279 return self._GetResultFromJSONRequest(cmd_dict, windex=None).get('result')
1241 1280
1281 def GetTabCount(self, windex=0):
1282 """Gets the number of tab in the given browser window.
1283
1284 Args:
1285 windex: Integer index of the browser window to use; defaults to the first
1286 window.
1287
1288 Returns:
1289 The tab count.
1290
1291 Raises:
1292 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1293 """
1294 cmd_dict = {
1295 'command': 'GetTabCount',
1296 'windex': windex,
1297 }
1298 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['tab_count']
1299
1300 def GetTabInfo(self, tab_index=0, windex=0):
1301 """Gets information about the specified tab.
1302
1303 Args:
1304 tab_index: Integer index of the tab to activate; defaults to 0.
1305 windex: Integer index of the browser window to use; defaults to the first
1306 window.
1307
1308 Returns:
1309 A dictionary containing information about the tab.
1310 Example:
1311 { u'title': "Hello World",
1312 u'url': "http://foo.bar", }
1313
1314 Raises:
1315 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1316 """
1317 cmd_dict = {
1318 'command': 'GetTabInfo',
1319 'tab_index': tab_index,
1320 'windex': windex,
1321 }
1322 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
1323
1324 def GetActiveTabTitle(self, windex=0):
1325 """Gets the title of the active tab.
1326
1327 Warning: Depending on the concept of an active tab is dangerous as it can
1328 change during the test. Use GetTabInfo and supply a tab_index explicitly.
1329
1330 Args:
1331 windex: Integer index of the browser window to use; defaults to the first
1332 window.
1333
1334 Returns:
1335 The tab title as a string.
1336
1337 Raises:
1338 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1339 """
1340 return self.GetTabInfo(self.GetActiveTabIndex(windex), windex)['title']
1341
1342 def GetActiveTabURL(self, windex=0):
1343 """Gets the URL of the active tab.
1344
1345 Warning: Depending on the concept of an active tab is dangerous as it can
1346 change during the test. Use GetTabInfo and supply a tab_index explicitly.
1347
1348 Args:
1349 windex: Integer index of the browser window to use; defaults to the first
1350 window.
1351
1352 Returns:
1353 The tab URL as a GURL object.
1354
1355 Raises:
1356 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1357 """
1358 return GURL(str(self.GetTabInfo(self.GetActiveTabIndex(windex),
1359 windex)['url']))
1360
1242 def GetBookmarkModel(self, windex=0): 1361 def GetBookmarkModel(self, windex=0):
1243 """Return the bookmark model as a BookmarkModel object. 1362 """Return the bookmark model as a BookmarkModel object.
1244 1363
1245 This is a snapshot of the bookmark model; it is not a proxy and 1364 This is a snapshot of the bookmark model; it is not a proxy and
1246 does not get updated as the bookmark model changes. 1365 does not get updated as the bookmark model changes.
1247 """ 1366 """
1248 bookmarks_as_json = self._GetBookmarksAsJSON(windex) 1367 bookmarks_as_json = self._GetBookmarksAsJSON(windex)
1249 if not bookmarks_as_json: 1368 if not bookmarks_as_json:
1250 raise JSONInterfaceError('Could not resolve browser proxy.') 1369 raise JSONInterfaceError('Could not resolve browser proxy.')
1251 return bookmark_model.BookmarkModel(bookmarks_as_json) 1370 return bookmark_model.BookmarkModel(bookmarks_as_json)
(...skipping 4944 matching lines...) Expand 10 before | Expand all | Expand 10 after
6196 successful = result.wasSuccessful() 6315 successful = result.wasSuccessful()
6197 if not successful: 6316 if not successful:
6198 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6317 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6199 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6318 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6200 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6319 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6201 sys.exit(not successful) 6320 sys.exit(not successful)
6202 6321
6203 6322
6204 if __name__ == '__main__': 6323 if __name__ == '__main__':
6205 Main() 6324 Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/popups.py ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698