OLD | NEW |
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 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 | 1263 |
1264 Raises: | 1264 Raises: |
1265 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 1265 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
1266 """ | 1266 """ |
1267 cmd_dict = { | 1267 cmd_dict = { |
1268 'command': 'BringBrowserToFront', | 1268 'command': 'BringBrowserToFront', |
1269 'windex': windex, | 1269 'windex': windex, |
1270 } | 1270 } |
1271 self._GetResultFromJSONRequest(cmd_dict, windex=None) | 1271 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
1272 | 1272 |
| 1273 def GetBrowserWindowCount(self): |
| 1274 """Get the browser window count. |
| 1275 |
| 1276 Args: |
| 1277 None. |
| 1278 |
| 1279 Returns: |
| 1280 Integer count of the number of browser windows. Includes popups. |
| 1281 |
| 1282 Raises: |
| 1283 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1284 """ |
| 1285 cmd_dict = {'command': 'GetBrowserWindowCount'} |
| 1286 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['count'] |
| 1287 |
| 1288 def OpenNewBrowserWindow(self, show): |
| 1289 """Create a new browser window. |
| 1290 |
| 1291 Args: |
| 1292 show: Boolean indicating whether to show the window. |
| 1293 |
| 1294 Raises: |
| 1295 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1296 """ |
| 1297 cmd_dict = { |
| 1298 'command': 'OpenNewBrowserWindow', |
| 1299 'show': show, |
| 1300 } |
| 1301 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 1302 |
| 1303 def CloseBrowserWindow(self, windex=0): |
| 1304 """Create a new browser window. |
| 1305 |
| 1306 Args: |
| 1307 windex: Index of the browser window to close; defaults to 0. |
| 1308 |
| 1309 Raises: |
| 1310 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 1311 """ |
| 1312 cmd_dict = { |
| 1313 'command': 'CloseBrowserWindow', |
| 1314 'windex': windex, |
| 1315 } |
| 1316 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 1317 |
1273 def AppendTab(self, url, windex=0): | 1318 def AppendTab(self, url, windex=0): |
1274 """Append a new tab. | 1319 """Append a new tab. |
1275 | 1320 |
1276 Creates a new tab at the end of given browser window and activates | 1321 Creates a new tab at the end of given browser window and activates |
1277 it. Blocks until the specified |url| is loaded. | 1322 it. Blocks until the specified |url| is loaded. |
1278 | 1323 |
1279 Args: | 1324 Args: |
1280 url: The url to load, can be string or a GURL object. | 1325 url: The url to load, can be string or a GURL object. |
1281 windex: The index of the browser window to work on. Defaults to the first | 1326 windex: The index of the browser window to work on. Defaults to the first |
1282 window. | 1327 window. |
(...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3198 This is equivalent to clicking on a blocked popup in the UI available | 3243 This is equivalent to clicking on a blocked popup in the UI available |
3199 from the omnibox. | 3244 from the omnibox. |
3200 """ | 3245 """ |
3201 cmd_dict = { | 3246 cmd_dict = { |
3202 'command': 'UnblockAndLaunchBlockedPopup', | 3247 'command': 'UnblockAndLaunchBlockedPopup', |
3203 'popup_index': popup_index, | 3248 'popup_index': popup_index, |
3204 'tab_index': tab_index, | 3249 'tab_index': tab_index, |
3205 } | 3250 } |
3206 self._GetResultFromJSONRequest(cmd_dict, windex=windex) | 3251 self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
3207 | 3252 |
| 3253 def ResetToDefaultTheme(self, windex=0): |
| 3254 """Reset to default theme. |
| 3255 |
| 3256 Args: |
| 3257 windex: Index of the window to reset; defaults to 0. |
| 3258 |
| 3259 Raises: |
| 3260 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 3261 """ |
| 3262 cmd_dict = { |
| 3263 'command': 'ResetToDefaultTheme', |
| 3264 'windex': windex, |
| 3265 } |
| 3266 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 3267 |
3208 def SetTheme(self, crx_file_path, windex=0): | 3268 def SetTheme(self, crx_file_path, windex=0): |
3209 """Installs the given theme synchronously. | 3269 """Installs the given theme synchronously. |
3210 | 3270 |
3211 A theme file is a file with a .crx suffix, like an extension. The theme | 3271 A theme file is a file with a .crx suffix, like an extension. The theme |
3212 file must be specified with an absolute path. This method call waits until | 3272 file must be specified with an absolute path. This method call waits until |
3213 the theme is installed and will trigger the "theme installed" infobar. | 3273 the theme is installed and will trigger the "theme installed" infobar. |
3214 If the install is unsuccessful, will throw an exception. | 3274 If the install is unsuccessful, will throw an exception. |
3215 | 3275 |
3216 Uses InstallExtension(). | 3276 Uses InstallExtension(). |
3217 | 3277 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3399 'command': 'FindInPage', | 3459 'command': 'FindInPage', |
3400 'tab_index' : tab_index, | 3460 'tab_index' : tab_index, |
3401 'search_string' : search_string, | 3461 'search_string' : search_string, |
3402 'forward' : forward, | 3462 'forward' : forward, |
3403 'match_case' : match_case, | 3463 'match_case' : match_case, |
3404 'find_next' : find_next, | 3464 'find_next' : find_next, |
3405 } | 3465 } |
3406 return self._GetResultFromJSONRequest(cmd_dict, windex=windex, | 3466 return self._GetResultFromJSONRequest(cmd_dict, windex=windex, |
3407 timeout=timeout) | 3467 timeout=timeout) |
3408 | 3468 |
| 3469 def OpenFindInPage(self, windex=0): |
| 3470 """Opens the "Find in Page" box. |
| 3471 |
| 3472 Args: |
| 3473 windex: Index of the window; defaults to 0. |
| 3474 |
| 3475 Raises: |
| 3476 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 3477 """ |
| 3478 cmd_dict = { |
| 3479 'command': 'OpenFindInPage', |
| 3480 'windex' : windex, |
| 3481 } |
| 3482 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 3483 |
| 3484 def IsFindInPageVisible(self, windex=0): |
| 3485 """Returns the visibility of the "Find in Page" box. |
| 3486 |
| 3487 Args: |
| 3488 windex: Index of the window; defaults to 0. |
| 3489 |
| 3490 Returns: |
| 3491 A boolean indicating the visibility state of the "Find in Page" box. |
| 3492 |
| 3493 Raises: |
| 3494 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 3495 """ |
| 3496 cmd_dict = { |
| 3497 'command': 'IsFindInPageVisible', |
| 3498 'windex' : windex, |
| 3499 } |
| 3500 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['is_visible'] |
| 3501 |
| 3502 |
3409 def AddDomEventObserver(self, event_name='', automation_id=-1, | 3503 def AddDomEventObserver(self, event_name='', automation_id=-1, |
3410 recurring=False): | 3504 recurring=False): |
3411 """Adds a DomEventObserver associated with the AutomationEventQueue. | 3505 """Adds a DomEventObserver associated with the AutomationEventQueue. |
3412 | 3506 |
3413 An app raises a matching event in Javascript by calling: | 3507 An app raises a matching event in Javascript by calling: |
3414 window.domAutomationController.sendWithId(automation_id, event_name) | 3508 window.domAutomationController.sendWithId(automation_id, event_name) |
3415 | 3509 |
3416 Args: | 3510 Args: |
3417 event_name: The event name to watch for. By default an event is raised | 3511 event_name: The event name to watch for. By default an event is raised |
3418 for any message. | 3512 for any message. |
(...skipping 3039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6458 successful = result.wasSuccessful() | 6552 successful = result.wasSuccessful() |
6459 if not successful: | 6553 if not successful: |
6460 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6554 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6461 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6555 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6462 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6556 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6463 sys.exit(not successful) | 6557 sys.exit(not successful) |
6464 | 6558 |
6465 | 6559 |
6466 if __name__ == '__main__': | 6560 if __name__ == '__main__': |
6467 Main() | 6561 Main() |
OLD | NEW |