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=''): |
| 2802 """Adds a DomRaisedEventObserver associated with the AutomationEventQueue. |
| 2803 |
| 2804 Args: |
| 2805 event_name: The raised event name to watch for. By default all raised |
| 2806 events are observed. |
| 2807 |
| 2808 Returns: |
| 2809 The id of the created observer, which can be used with GetNextEvent(id) |
| 2810 and RemoveEventObserver(id). |
| 2811 |
| 2812 Raises: |
| 2813 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2814 """ |
| 2815 # TODO(craigdh): Add documentation for raising an event once it has been |
| 2816 # implemented. |
| 2817 cmd_dict = { |
| 2818 'command': 'AddDomRaisedEventObserver', |
| 2819 'event_name': event_name, |
| 2820 } |
| 2821 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['observer_id'] |
| 2822 |
| 2823 def GetNextEvent(self, observer_id=-1, blocking=True, timeout=-1): |
| 2824 """Waits for an observed event to occur. |
| 2825 |
| 2826 The returned event is removed from the Event Queue. If there is already a |
| 2827 matching event in the queue it is returned immediately, otherwise the call |
| 2828 blocks until a matching event occurs. If blocking is disabled and no |
| 2829 matching event is in the queue this function will immediately return None. |
| 2830 |
| 2831 Args: |
| 2832 observer_id: The id of the observer to wait for, matches any event by |
| 2833 default. |
| 2834 blocking: If True waits until there is a matching event in the queue, |
| 2835 if False and there is no event waiting in the queue returns None |
| 2836 immediately. |
| 2837 timeout: Time to wait for a matching event, defaults to the default |
| 2838 automation timeout. |
| 2839 |
| 2840 Returns: |
| 2841 Event response dictionary, or None if blocking is disabled and there is no |
| 2842 matching event in the queue. |
| 2843 SAMPLE: |
| 2844 { 'observer_id': 1, |
| 2845 'name': 'login completed', |
| 2846 'type': 'raised_event'} |
| 2847 |
| 2848 Raises: |
| 2849 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2850 """ |
| 2851 cmd_dict = { |
| 2852 'command': 'GetNextEvent', |
| 2853 'observer_id' : observer_id, |
| 2854 'blocking' : blocking, |
| 2855 } |
| 2856 return self._GetResultFromJSONRequest(cmd_dict, windex=None, |
| 2857 timeout=timeout) |
| 2858 |
| 2859 def RemoveEventObserver(self, observer_id): |
| 2860 """Removes an Event Observer from the AutomationEventQueue. |
| 2861 |
| 2862 Expects a valid observer_id. |
| 2863 |
| 2864 Args: |
| 2865 observer_id: The id of the observer to remove. |
| 2866 |
| 2867 Raises: |
| 2868 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2869 """ |
| 2870 cmd_dict = { |
| 2871 'command': 'RemoveEventObserver', |
| 2872 'observer_id' : observer_id, |
| 2873 } |
| 2874 return self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 2875 |
| 2876 def ClearEventQueue(self): |
| 2877 """Removes all events currently in the AutomationEventQueue. |
| 2878 |
| 2879 Raises: |
| 2880 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2881 """ |
| 2882 cmd_dict = { |
| 2883 'command': 'ClearEventQueue', |
| 2884 } |
| 2885 return self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 2886 |
2801 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): | 2887 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): |
2802 """Executes a script in the specified frame of a tab. | 2888 """Executes a script in the specified frame of a tab. |
2803 | 2889 |
2804 By default, execute the script in the top frame of the first tab in the | 2890 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 | 2891 first window. The invoked javascript function must send a result back via |
2806 the domAutomationController.send function, or this function will never | 2892 the domAutomationController.send function, or this function will never |
2807 return. | 2893 return. |
2808 | 2894 |
2809 Args: | 2895 Args: |
2810 js: script to be executed. | 2896 js: script to be executed. |
(...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5024 successful = result.wasSuccessful() | 5110 successful = result.wasSuccessful() |
5025 if not successful: | 5111 if not successful: |
5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5112 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5113 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5114 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5029 sys.exit(not successful) | 5115 sys.exit(not successful) |
5030 | 5116 |
5031 | 5117 |
5032 if __name__ == '__main__': | 5118 if __name__ == '__main__': |
5033 Main() | 5119 Main() |
OLD | NEW |