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 2780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2791 'command': 'FindInPage', | 2791 'command': 'FindInPage', |
2792 'tab_index' : tab_index, | 2792 'tab_index' : tab_index, |
2793 'search_string' : search_string, | 2793 'search_string' : search_string, |
2794 'forward' : forward, | 2794 'forward' : forward, |
2795 'match_case' : match_case, | 2795 'match_case' : match_case, |
2796 'find_next' : find_next, | 2796 'find_next' : find_next, |
2797 } | 2797 } |
2798 return self._GetResultFromJSONRequest(cmd_dict, windex=windex, | 2798 return self._GetResultFromJSONRequest(cmd_dict, windex=windex, |
2799 timeout=timeout) | 2799 timeout=timeout) |
2800 | 2800 |
2801 def AddDomRaisedEventObserver(self, event_name='', tab_index=0, windex=0, | |
2802 frame_xpath=''): | |
2803 """Adds a DomRaisedEventObserver associated with the AutomationEventQueue. | |
2804 | |
2805 Args: | |
2806 event_name: The raised event name to watch for. By default all raised | |
2807 events are observed. | |
2808 tab_index: index of the tab. | |
2809 windex: index of the window. | |
2810 frame_xpath: XPath of the frame to execute the script. Default is no | |
2811 frame. Example: '//frames[1]'. | |
2812 | |
2813 Returns: | |
2814 The id of the created observer, which can be used with GetNextEvent(id) | |
2815 and RemoveEventObserver(id). | |
2816 | |
2817 Raises: | |
2818 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2819 """ | |
2820 # TODO(craigdh): Add a corresponding method for extension views. | |
2821 # TODO(craigdh): Add documentation for raising an event once it has been | |
2822 # implemented. | |
2823 cmd_dict = { | |
2824 'command': 'AddDomRaisedEventObserver', | |
2825 'event_name': event_name, | |
2826 'tab_index' : tab_index, | |
2827 'windex' : windex, | |
2828 'frame_xpath' : frame_xpath, | |
2829 } | |
2830 return self._GetResultFromJSONRequest(cmd_dict, | |
2831 windex=windex)['observer_id'] | |
Nirnimesh
2012/03/01 10:34:12
You've added AddDomRaisedEventObserver to handler_
craigdh
2012/03/01 21:34:18
Fixed. This was left over from a time when creatin
| |
2832 | |
2833 def GetNextEvent(self, observer_id=-1, blocking=True, timeout=-1): | |
2834 """Waits for an observed event to occur. | |
2835 | |
2836 The returned event is removed from the Event Queue. If there is already a | |
2837 matching event in the queue it is returned immediately, otherwise the call | |
2838 blocks until a matching event occurs. If blocking is disabled and no | |
2839 matching event is in the queue this function will immediately return None. | |
2840 | |
2841 Args: | |
2842 observer_id: The id of the observer to wait for, matches any event by | |
2843 default. | |
2844 blocking: If True waits until there is a matching event in the queue, | |
2845 if False and there is no event waiting in the queue returns None | |
2846 immediately. | |
2847 timeout: Time to wait for a matching event, defaults to | |
2848 self.large_test_timeout_ms(). | |
Nirnimesh
2012/03/01 10:34:12
fix comment. defaults to automation timeout
craigdh
2012/03/01 21:34:18
Done.
| |
2849 | |
2850 Returns: | |
2851 Event response dictionary, or None if blocking is disabled and there is no | |
2852 matching event in the queue. | |
2853 SAMPLE: | |
2854 { 'observer_id': 1, | |
2855 'name': 'login completed', | |
2856 'type': 'raised_event'} | |
2857 | |
2858 Raises: | |
2859 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2860 """ | |
2861 cmd_dict = { | |
2862 'command': 'GetNextEvent', | |
2863 'observer_id' : observer_id, | |
2864 'blocking' : blocking, | |
2865 } | |
2866 return self._GetResultFromJSONRequest(cmd_dict, windex=None, | |
2867 timeout=timeout) | |
2868 | |
2869 def RemoveEventObserver(self, observer_id): | |
2870 """Removes an Event Observer from the AutomationEventQueue. | |
2871 | |
2872 Expects a valid observer_id. | |
2873 | |
2874 Args: | |
2875 observer_id: The id of the observer to remove. | |
2876 | |
2877 Raises: | |
2878 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2879 """ | |
2880 cmd_dict = { | |
2881 'command': 'RemoveEventObserver', | |
2882 'observer_id' : observer_id, | |
2883 } | |
2884 return self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
2885 | |
2886 def ClearEventQueue(self): | |
2887 """Removes all events currently in the AutomationEventQueue. | |
2888 | |
2889 Raises: | |
2890 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2891 """ | |
2892 cmd_dict = { | |
2893 'command': 'ClearEventQueue', | |
2894 } | |
2895 return self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
2896 | |
2801 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): | 2897 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): |
2802 """Executes a script in the specified frame of a tab. | 2898 """Executes a script in the specified frame of a tab. |
2803 | 2899 |
2804 By default, execute the script in the top frame of the first tab in the | 2900 By default, execute the script in the top frame of the first tab in the |
2805 first window. The invoked javascript function must send a result back via | 2901 first window. The invoked javascript function must send a result back via |
2806 the domAutomationController.send function, or this function will never | 2902 the domAutomationController.send function, or this function will never |
2807 return. | 2903 return. |
2808 | 2904 |
2809 Args: | 2905 Args: |
2810 js: script to be executed. | 2906 js: script to be executed. |
(...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5024 successful = result.wasSuccessful() | 5120 successful = result.wasSuccessful() |
5025 if not successful: | 5121 if not successful: |
5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5122 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5123 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5124 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5029 sys.exit(not successful) | 5125 sys.exit(not successful) |
5030 | 5126 |
5031 | 5127 |
5032 if __name__ == '__main__': | 5128 if __name__ == '__main__': |
5033 Main() | 5129 Main() |
OLD | NEW |