OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """PyAuto: Python Interface to Chromium's Automation Proxy. | 7 """PyAuto: Python Interface to Chromium's Automation Proxy. |
8 | 8 |
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
10 For complete documentation on the functionality available, | 10 For complete documentation on the functionality available, |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 windex: 0-based window index on which to work. Default: 0 (first window) | 464 windex: 0-based window index on which to work. Default: 0 (first window) |
465 Use -ve windex if the automation command does not apply to a | 465 Use -ve windex if the automation command does not apply to a |
466 browser window. example: chromeos login | 466 browser window. example: chromeos login |
467 | 467 |
468 Returns: | 468 Returns: |
469 a dictionary for the output returned by the automation channel. | 469 a dictionary for the output returned by the automation channel. |
470 | 470 |
471 Raises: | 471 Raises: |
472 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 472 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
473 """ | 473 """ |
474 ret_dict = json.loads(self._SendJSONRequest(windex, json.dumps(cmd_dict))) | 474 result = self._SendJSONRequest(windex, json.dumps(cmd_dict)) |
| 475 if len(result) == 0: |
| 476 raise JSONInterfaceError('Automation call received no response.') |
| 477 ret_dict = json.loads(result) |
475 if ret_dict.has_key('error'): | 478 if ret_dict.has_key('error'): |
476 raise JSONInterfaceError(ret_dict['error']) | 479 raise JSONInterfaceError(ret_dict['error']) |
477 return ret_dict | 480 return ret_dict |
478 | 481 |
479 def GetBookmarkModel(self): | 482 def GetBookmarkModel(self): |
480 """Return the bookmark model as a BookmarkModel object. | 483 """Return the bookmark model as a BookmarkModel object. |
481 | 484 |
482 This is a snapshot of the bookmark model; it is not a proxy and | 485 This is a snapshot of the bookmark model; it is not a proxy and |
483 does not get updated as the bookmark model changes. | 486 does not get updated as the bookmark model changes. |
484 """ | 487 """ |
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 Sample: | 2284 Sample: |
2282 | 2285 |
2283 { u'is_logged_in': True, | 2286 { u'is_logged_in': True, |
2284 u'is_guest': False, | 2287 u'is_guest': False, |
2285 u'is_screen_locked': False} | 2288 u'is_screen_locked': False} |
2286 | 2289 |
2287 Raises: | 2290 Raises: |
2288 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2291 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
2289 """ | 2292 """ |
2290 cmd_dict = { 'command': 'GetLoginInfo' } | 2293 cmd_dict = { 'command': 'GetLoginInfo' } |
2291 return self._GetResultFromJSONRequest(cmd_dict) | 2294 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
2292 | 2295 |
2293 def LoginAsGuest(self): | 2296 def LoginAsGuest(self): |
2294 """Login to chromeos as a guest user. | 2297 """Login to chromeos as a guest user. |
2295 | 2298 |
2296 Waits until logged in. | 2299 Waits until logged in. |
2297 Should be displaying the login screen to work. | 2300 Should be displaying the login screen to work. |
2298 | 2301 |
2299 Raises: | 2302 Raises: |
2300 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2303 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
2301 """ | 2304 """ |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2370 | 2373 |
2371 def GetNetworkInfo(self): | 2374 def GetNetworkInfo(self): |
2372 """Get details about ethernet, wifi, and cellular networks on chromeos. | 2375 """Get details about ethernet, wifi, and cellular networks on chromeos. |
2373 | 2376 |
2374 Raises: | 2377 Raises: |
2375 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2378 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
2376 """ | 2379 """ |
2377 cmd_dict = { 'command': 'GetNetworkInfo' } | 2380 cmd_dict = { 'command': 'GetNetworkInfo' } |
2378 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) | 2381 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
2379 | 2382 |
| 2383 def NetworkScan(self): |
| 2384 """Causes ChromeOS to scan for available wifi networks. |
| 2385 |
| 2386 Blocks until scanning is complete. |
| 2387 |
| 2388 Raises: |
| 2389 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2390 """ |
| 2391 cmd_dict = { 'command': 'NetworkScan' } |
| 2392 self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
| 2393 |
2380 def ConnectToWifiNetwork(self, service_path, | 2394 def ConnectToWifiNetwork(self, service_path, |
2381 password='', identity='', certpath=''): | 2395 password='', identity='', certpath=''): |
2382 """Connect to a wifi network by its service path. | 2396 """Connect to a wifi network by its service path. |
2383 | 2397 |
| 2398 Blocks until connection succeeds or fails. |
| 2399 |
| 2400 Returns: |
| 2401 A tuple. |
| 2402 The first element is True on success and False on failure. |
| 2403 The second element is None on success or an error string on failure. |
| 2404 |
2384 Raises: | 2405 Raises: |
2385 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2406 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
2386 """ | 2407 """ |
2387 cmd_dict = { | 2408 cmd_dict = { |
2388 'command': 'ConnectToWifiNetwork', | 2409 'command': 'ConnectToWifiNetwork', |
2389 'service_path': service_path, | 2410 'service_path': service_path, |
2390 'password': password, | 2411 'password': password, |
2391 'identity': identity, | 2412 'identity': identity, |
2392 'certpath': certpath, | 2413 'certpath': certpath, |
2393 } | 2414 } |
2394 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) | 2415 result = self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
| 2416 if result.has_key('error_code'): |
| 2417 return (False, result['error_code']) |
| 2418 else: |
| 2419 return (True, None) |
| 2420 |
| 2421 def DisconnectFromWifiNetwork(self, service_path, |
| 2422 password='', identity='', certpath=''): |
| 2423 """Disconnect from a wifi network by its service path. |
| 2424 |
| 2425 Blocks until disconnect is complete. |
| 2426 |
| 2427 Raises: |
| 2428 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2429 """ |
| 2430 cmd_dict = { |
| 2431 'command': 'DisconnectFromWifiNetwork', |
| 2432 'service_path': service_path, |
| 2433 } |
| 2434 self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
2395 | 2435 |
2396 ## ChromeOS section -- end | 2436 ## ChromeOS section -- end |
2397 | 2437 |
2398 | 2438 |
2399 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): | 2439 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): |
2400 """Base TestSuite for PyAuto UI tests.""" | 2440 """Base TestSuite for PyAuto UI tests.""" |
2401 | 2441 |
2402 def __init__(self, args): | 2442 def __init__(self, args): |
2403 pyautolib.PyUITestSuiteBase.__init__(self, args) | 2443 pyautolib.PyUITestSuiteBase.__init__(self, args) |
2404 | 2444 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2784 if self._options.verbose: | 2824 if self._options.verbose: |
2785 verbosity = 2 | 2825 verbosity = 2 |
2786 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 2826 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
2787 del loaded_tests # Need to destroy test cases before the suite | 2827 del loaded_tests # Need to destroy test cases before the suite |
2788 del pyauto_suite | 2828 del pyauto_suite |
2789 sys.exit(not result.wasSuccessful()) | 2829 sys.exit(not result.wasSuccessful()) |
2790 | 2830 |
2791 | 2831 |
2792 if __name__ == '__main__': | 2832 if __name__ == '__main__': |
2793 Main() | 2833 Main() |
OLD | NEW |