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

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

Issue 10836015: Convert more automation calls to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1289
1290 Raises: 1290 Raises:
1291 pyauto_errors.JSONInterfaceError if the automation call returns an error. 1291 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1292 """ 1292 """
1293 cmd_dict = { 1293 cmd_dict = {
1294 'command': 'BringBrowserToFront', 1294 'command': 'BringBrowserToFront',
1295 'windex': windex, 1295 'windex': windex,
1296 } 1296 }
1297 self._GetResultFromJSONRequest(cmd_dict, windex=None) 1297 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1298 1298
1299 def GetBrowserWindowCount(self):
1300 """Get the browser window count.
1301
1302 Args:
1303 None.
1304
1305 Returns:
1306 Integer count of the number of browser windows. Includes popups.
1307
1308 Raises:
1309 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1310 """
1311 cmd_dict = {
1312 'command': 'GetBrowserWindowCount',
1313 'windex': windex,
1314 }
1315 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['count']
1316
1317 def OpenNewBrowserWindow(self, show):
1318 """Create a new browser window.
1319
1320 Args:
1321 show: Boolean indicating whether to show the window.
1322
1323 Raises:
1324 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1325 """
1326 cmd_dict = {
1327 'command': 'OpenNewBrowserWindow',
1328 'show': show,
1329 }
1330 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1331
1332 def CloseBrowserWindow(self, windex=0):
1333 """Create a new browser window.
1334
1335 Args:
1336 windex: Index of the browser window to close; defaults to 0.
1337
1338 Raises:
1339 pyauto_errors.JSONInterfaceError if the automation call returns an error.
1340 """
1341 cmd_dict = {
1342 'command': 'CloseBrowserWindow',
1343 'windex': windex,
1344 }
1345 self._GetResultFromJSONRequest(cmd_dict, windex=None)
1346
1299 def AppendTab(self, url, windex=0): 1347 def AppendTab(self, url, windex=0):
1300 """Append a new tab. 1348 """Append a new tab.
1301 1349
1302 Creates a new tab at the end of given browser window and activates 1350 Creates a new tab at the end of given browser window and activates
1303 it. Blocks until the specified |url| is loaded. 1351 it. Blocks until the specified |url| is loaded.
1304 1352
1305 Args: 1353 Args:
1306 url: The url to load, can be string or a GURL object. 1354 url: The url to load, can be string or a GURL object.
1307 windex: The index of the browser window to work on. Defaults to the first 1355 windex: The index of the browser window to work on. Defaults to the first
1308 window. 1356 window.
(...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after
3224 This is equivalent to clicking on a blocked popup in the UI available 3272 This is equivalent to clicking on a blocked popup in the UI available
3225 from the omnibox. 3273 from the omnibox.
3226 """ 3274 """
3227 cmd_dict = { 3275 cmd_dict = {
3228 'command': 'UnblockAndLaunchBlockedPopup', 3276 'command': 'UnblockAndLaunchBlockedPopup',
3229 'popup_index': popup_index, 3277 'popup_index': popup_index,
3230 'tab_index': tab_index, 3278 'tab_index': tab_index,
3231 } 3279 }
3232 self._GetResultFromJSONRequest(cmd_dict, windex=windex) 3280 self._GetResultFromJSONRequest(cmd_dict, windex=windex)
3233 3281
3282 def ResetToDefaultTheme(self, windex=0):
3283 """Reset to default theme.
3284
3285 Args:
3286 windex: Index of the window to reset; defaults to 0.
3287
3288 Raises:
3289 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3290 """
3291 cmd_dict = {
3292 'command': 'ResetToDefaultTheme',
3293 'windex': windex,
3294 }
3295 self._GetResultFromJSONRequest(cmd_dict, windex=None)
3296
3234 def SetTheme(self, crx_file_path, windex=0): 3297 def SetTheme(self, crx_file_path, windex=0):
3235 """Installs the given theme synchronously. 3298 """Installs the given theme synchronously.
3236 3299
3237 A theme file is a file with a .crx suffix, like an extension. The theme 3300 A theme file is a file with a .crx suffix, like an extension. The theme
3238 file must be specified with an absolute path. This method call waits until 3301 file must be specified with an absolute path. This method call waits until
3239 the theme is installed and will trigger the "theme installed" infobar. 3302 the theme is installed and will trigger the "theme installed" infobar.
3240 If the install is unsuccessful, will throw an exception. 3303 If the install is unsuccessful, will throw an exception.
3241 3304
3242 Uses InstallExtension(). 3305 Uses InstallExtension().
3243 3306
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3425 'command': 'FindInPage', 3488 'command': 'FindInPage',
3426 'tab_index' : tab_index, 3489 'tab_index' : tab_index,
3427 'search_string' : search_string, 3490 'search_string' : search_string,
3428 'forward' : forward, 3491 'forward' : forward,
3429 'match_case' : match_case, 3492 'match_case' : match_case,
3430 'find_next' : find_next, 3493 'find_next' : find_next,
3431 } 3494 }
3432 return self._GetResultFromJSONRequest(cmd_dict, windex=windex, 3495 return self._GetResultFromJSONRequest(cmd_dict, windex=windex,
3433 timeout=timeout) 3496 timeout=timeout)
3434 3497
3498 def OpenFindInPage(self, windex=0):
3499 """Opens the "Find in Page" box.
3500
3501 Args:
3502 windex: Index of the window; defaults to 0.
3503
3504 Raises:
3505 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3506 """
3507 cmd_dict = {
3508 'command': 'OpenFindInPage',
3509 'windex' : windex,
3510 }
3511 self._GetResultFromJSONRequest(cmd_dict, windex=None)
3512
3513 def IsFindInPageVisible(self, windex=0):
3514 """Returns the visibility of the "Find in Page" box.
3515
3516 Args:
3517 windex: Index of the window; defaults to 0.
3518
3519 Returns:
3520 A boolean indicating the visibility state of the "Find in Page" box.
3521
3522 Raises:
3523 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3524 """
3525 cmd_dict = {
3526 'command': 'IsFindInPageVisible',
3527 'windex' : windex,
3528 }
3529 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['is_visible']
3530
3531
3435 def AddDomEventObserver(self, event_name='', automation_id=-1, 3532 def AddDomEventObserver(self, event_name='', automation_id=-1,
3436 recurring=False): 3533 recurring=False):
3437 """Adds a DomEventObserver associated with the AutomationEventQueue. 3534 """Adds a DomEventObserver associated with the AutomationEventQueue.
3438 3535
3439 An app raises a matching event in Javascript by calling: 3536 An app raises a matching event in Javascript by calling:
3440 window.domAutomationController.sendWithId(automation_id, event_name) 3537 window.domAutomationController.sendWithId(automation_id, event_name)
3441 3538
3442 Args: 3539 Args:
3443 event_name: The event name to watch for. By default an event is raised 3540 event_name: The event name to watch for. By default an event is raised
3444 for any message. 3541 for any message.
(...skipping 3039 matching lines...) Expand 10 before | Expand all | Expand 10 after
6484 successful = result.wasSuccessful() 6581 successful = result.wasSuccessful()
6485 if not successful: 6582 if not successful:
6486 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6583 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6487 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6584 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6488 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6585 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6489 sys.exit(not successful) 6586 sys.exit(not successful)
6490 6587
6491 6588
6492 if __name__ == '__main__': 6589 if __name__ == '__main__':
6493 Main() 6590 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698