Chromium Code Reviews| 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. |
|
Nirnimesh
2012/02/24 23:18:09
Explain the motivation in the CL description.
Nirnimesh
2012/02/28 09:13:09
Please make the CL description somewhat meaningful
| |
| 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. |
| 11 | 11 |
| 12 Ref: http://dev.chromium.org/developers/testing/pyauto | 12 Ref: http://dev.chromium.org/developers/testing/pyauto |
| (...skipping 2778 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 AddRaisedEventObserver(self, event_name='', tab_index=0, windex=0, | |
|
Nirnimesh
2012/02/24 23:18:09
It's not clear to the end-user what 'Raised event'
craigdh
2012/02/27 22:43:38
Rename done.
I have the usage description written
| |
| 2802 frame_xpath=''): | |
|
frankf
2012/02/24 22:05:07
alignment issue
craigdh
2012/02/24 23:19:33
Done.
| |
| 2803 """Creates a raised event observer and associates it with the event queue. | |
| 2804 | |
|
Nirnimesh
2012/02/24 23:18:09
Add a TODO to add a corresponding method for exten
| |
| 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 | |
|
frankf
2012/02/24 22:05:07
why is the arg in quotes?
craigdh
2012/02/24 23:19:33
Because it was copy-pasted from the cmd_dict and I
| |
| 2810 events are observed. | |
| 2811 windex: index of the window. | |
|
frankf
2012/02/24 22:05:07
follow the order of function signature.
craigdh
2012/02/24 23:19:33
Done.
| |
| 2812 tab_index: index of the tab. | |
| 2813 frame_xpath: XPath of the frame to execute the script. Default is no | |
| 2814 frame. Example: '//frames[1]'. | |
| 2815 | |
| 2816 Returns: | |
| 2817 The id of the created observer, which can be used with GetEvent(id) and | |
| 2818 RemoveEventObserver(id). | |
| 2819 | |
| 2820 Raises: | |
| 2821 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
| 2822 """ | |
| 2823 cmd_dict = { | |
| 2824 'command': 'AddRaisedEventObserver', | |
| 2825 'event_name': event_name, | |
| 2826 'windex' : windex, | |
| 2827 'tab_index' : tab_index, | |
|
frankf
2012/02/24 22:05:07
same with ordering here.
craigdh
2012/02/24 23:19:33
Done.
| |
| 2828 'frame_xpath' : frame_xpath, | |
| 2829 } | |
| 2830 return self._GetResultFromJSONRequest( | |
| 2831 cmd_dict, timeout=self.large_test_timeout_ms())['observer_id'] | |
| 2832 | |
| 2833 def GetEvent(self, observer_id=-1, blocking=True): | |
|
Nirnimesh
2012/02/24 23:18:09
add 'app' somewhere in the name.
craigdh
2012/02/27 22:43:38
I don't want to limit the naming to just apps, so
| |
| 2834 """Waits for an event to occur. | |
|
Nirnimesh
2012/02/24 23:18:09
Waits for one of the observed events to occur
craigdh
2012/02/27 22:43:38
Done.
| |
| 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 | |
|
frankf
2012/02/24 22:05:07
again, why quotes?
craigdh
2012/02/24 23:19:33
Done.
| |
| 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 | |
| 2846 None immediately. | |
| 2847 | |
| 2848 Returns: | |
| 2849 Event response dictionary, or None if blocking is disabled and there is no | |
| 2850 matching event in the queue. | |
| 2851 SAMPLE: | |
| 2852 { 'observer_id': 1, | |
| 2853 'name': 'login completed', | |
| 2854 'type': 'raised_event'} | |
| 2855 | |
| 2856 Raises: | |
| 2857 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
| 2858 """ | |
| 2859 cmd_dict = { | |
| 2860 'command': 'GetEvent', | |
| 2861 'observer_id' : observer_id, | |
| 2862 'blocking' : blocking, | |
| 2863 } | |
| 2864 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
|
frankf
2012/02/24 22:05:07
if feel like it, define 50000 as a constant like l
Nirnimesh
2012/02/24 23:18:09
why 50s?
Leave it as the default, but provide a w
craigdh
2012/02/24 23:19:33
Oops, I meant to do self.large_test_timeout_ms().
| |
| 2865 | |
| 2866 def RemoveEventObserver(self, observer_id): | |
| 2867 """Removes an Event Observer from the event queue. | |
| 2868 | |
| 2869 Args: | |
| 2870 'observer_id': The id of the observer to remove. | |
| 2871 | |
| 2872 Raises: | |
| 2873 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
| 2874 """ | |
| 2875 cmd_dict = { | |
| 2876 'command': 'RemoveEventObserver', | |
| 2877 'observer_id' : observer_id, | |
| 2878 } | |
| 2879 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
| 2880 | |
| 2881 def ClearEvents(self): | |
| 2882 """Removes all events currently in the event queue. | |
|
Nirnimesh
2012/02/24 23:18:09
event -> app event
Repeat everywhere
craigdh
2012/02/27 22:43:38
There is no inherent requirement that they have an
| |
| 2883 | |
| 2884 Raises: | |
| 2885 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
| 2886 """ | |
| 2887 cmd_dict = { | |
| 2888 'command': 'ClearEvents', | |
| 2889 } | |
| 2890 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
| 2891 | |
| 2892 def ClearEventObservers(self): | |
| 2893 """Removes all Event Observers currently associated with the event queue. | |
| 2894 | |
| 2895 Raises: | |
| 2896 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
| 2897 """ | |
| 2898 cmd_dict = { | |
| 2899 'command': 'ClearEventObservers', | |
| 2900 } | |
| 2901 return self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
|
Nirnimesh
2012/02/24 23:18:09
why override this timeout?
craigdh
2012/02/27 22:43:38
No reason. Removed.
| |
| 2902 | |
| 2801 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): | 2903 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): |
| 2802 """Executes a script in the specified frame of a tab. | 2904 """Executes a script in the specified frame of a tab. |
| 2803 | 2905 |
| 2804 By default, execute the script in the top frame of the first tab in the | 2906 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 | 2907 first window. The invoked javascript function must send a result back via |
| 2806 the domAutomationController.send function, or this function will never | 2908 the domAutomationController.send function, or this function will never |
| 2807 return. | 2909 return. |
| 2808 | 2910 |
| 2809 Args: | 2911 Args: |
| 2810 js: script to be executed. | 2912 js: script to be executed. |
| (...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5024 successful = result.wasSuccessful() | 5126 successful = result.wasSuccessful() |
| 5025 if not successful: | 5127 if not successful: |
| 5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5128 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5129 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5130 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 5029 sys.exit(not successful) | 5131 sys.exit(not successful) |
| 5030 | 5132 |
| 5031 | 5133 |
| 5032 if __name__ == '__main__': | 5134 if __name__ == '__main__': |
| 5033 Main() | 5135 Main() |
| OLD | NEW |