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 ObserveRaisedEvents(self, event_name="", tab_index=0, windex=0, | |
dennis_jeffrey
2012/02/23 19:26:36
prefer single quotes over double quotes
dennis_jeffrey
2012/02/23 19:26:36
Would a name like "GetEventObserver" be better her
craigdh
2012/02/24 01:30:02
Perhaps "AddRaisedEventObserver" as there are goin
| |
2802 frame_xpath=''): | |
2803 """Creates a raised event observer and associates it with the event queue. | |
2804 | |
2805 TODO(craigdh): Describe the correct method of raising an event once it has | |
2806 been implemented. | |
2807 | |
2808 Args: | |
2809 'event_name': The raised event name to watch for. By default all raised | |
2810 events are observed. | |
2811 'windex' : windex, | |
2812 'tab_index' : tab_index, | |
2813 'frame_xpath' : frame_xpath, | |
dennis_jeffrey
2012/02/23 19:26:36
for the above 3 argument descriptions, we should h
craigdh
2012/02/24 01:30:02
Copy-Paste error. Done.
| |
2814 | |
2815 Returns: | |
2816 The id of the created observer, which can be used with GetEvent(id) and | |
2817 RemoveEventObserver(id). | |
2818 | |
2819 Raises: | |
2820 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2821 """ | |
2822 cmd_dict = { | |
2823 'command': 'ObserveRaisedEvents', | |
2824 'event_name': event_name, | |
2825 'windex' : windex, | |
2826 'tab_index' : tab_index, | |
2827 'frame_xpath' : frame_xpath, | |
2828 } | |
2829 return self._GetResultFromJSONRequest(cmd_dict, | |
2830 timeout=50000).get('observer_id') | |
dennis_jeffrey
2012/02/23 19:26:36
should we use "self.large_test_timeout_ms()" inste
dennis_jeffrey
2012/02/23 19:26:36
will the call to get() here ever return None? (I t
craigdh
2012/02/24 01:30:02
Good point. It should never return None.
craigdh
2012/02/24 01:30:02
I wasn't aware that existed. Done.
| |
2831 | |
2832 def GetEvent(self, observer_id=-1, blocking=True): | |
dennis_jeffrey
2012/02/23 19:26:36
If this function gets an event, is that event remo
craigdh
2012/02/24 01:30:02
Yes. Clarified this in the comments.
| |
2833 """Waits for a registered event to occur. | |
2834 | |
2835 Args: | |
2836 'observer_id': The id of the observer to wait for, matches any event by | |
2837 default. | |
2838 'blocking': If True waits until there is a matching event in the queue, | |
2839 if False and there is no event waiting in the queue returns | |
2840 None immediately. | |
2841 | |
2842 Returns: | |
2843 Event response. | |
dennis_jeffrey
2012/02/23 19:26:36
is this a string or a number?
craigdh
2012/02/24 01:30:02
Neither, it is a dictionary. Added an example.
| |
2844 | |
2845 Raises: | |
2846 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2847 """ | |
2848 cmd_dict = { | |
2849 'command': 'GetEvent', | |
2850 'observer_id' : observer_id, | |
2851 'blocking' : blocking, | |
2852 } | |
2853 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
2854 | |
2855 def RemoveEventObserver(self, observer_id): | |
2856 """Removes an Event Observer from the event queue. | |
2857 | |
2858 Args: | |
2859 'observer_id': The id of the observer to remove. | |
2860 | |
2861 Raises: | |
2862 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2863 """ | |
2864 cmd_dict = { | |
2865 'command': 'RemoveEventObserver', | |
2866 'observer_id' : observer_id, | |
2867 } | |
2868 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
2869 | |
2870 def ClearEvents(self): | |
2871 """Removes all events currently in the event queue. | |
2872 | |
2873 Raises: | |
2874 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2875 """ | |
2876 cmd_dict = { | |
2877 'command': 'ClearEvents', | |
2878 } | |
2879 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
2880 | |
2881 def ClearEventObservers(self): | |
dennis_jeffrey
2012/02/23 19:26:36
Would it make sense to have pyauto automatically c
craigdh
2012/02/24 01:30:02
So long as PyAuto always restarts the browser befo
| |
2882 """Removes all Event Observers currently associated with the event queue. | |
2883 | |
2884 Raises: | |
2885 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
2886 """ | |
2887 cmd_dict = { | |
2888 'command': 'ClearEventObservers', | |
2889 } | |
2890 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
2891 | |
2801 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): | 2892 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): |
2802 """Executes a script in the specified frame of a tab. | 2893 """Executes a script in the specified frame of a tab. |
2803 | 2894 |
2804 By default, execute the script in the top frame of the first tab in the | 2895 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 | 2896 first window. The invoked javascript function must send a result back via |
2806 the domAutomationController.send function, or this function will never | 2897 the domAutomationController.send function, or this function will never |
2807 return. | 2898 return. |
2808 | 2899 |
2809 Args: | 2900 Args: |
2810 js: script to be executed. | 2901 js: script to be executed. |
(...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5024 successful = result.wasSuccessful() | 5115 successful = result.wasSuccessful() |
5025 if not successful: | 5116 if not successful: |
5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5117 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5118 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5119 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5029 sys.exit(not successful) | 5120 sys.exit(not successful) |
5030 | 5121 |
5031 | 5122 |
5032 if __name__ == '__main__': | 5123 if __name__ == '__main__': |
5033 Main() | 5124 Main() |
OLD | NEW |