Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 9372120: Implementation of AutomationEventQueue and associated framework to support generic non-blocking aut… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Nirnimesh's comments. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 TODO(craigdh): Add documentation for raising an event once it has been
Nirnimesh 2012/02/28 09:13:09 Move TODO's outside of the docstring, as comments.
craigdh 2012/02/28 22:42:56 Done.
2806 implemented.
2807 TODO(craigdh): Add a corresponding method for extension views.
2808
2809 Args:
2810 event_name: The raised event name to watch for. By default all raised
2811 events are observed.
2812 tab_index: index of the tab.
2813 windex: index of the window.
2814 frame_xpath: XPath of the frame to execute the script. Default is no
2815 frame. Example: '//frames[1]'.
2816
2817 Returns:
2818 The id of the created observer, which can be used with GetQueuedEvent(id)
2819 and RemoveEventObserver(id).
2820
2821 Raises:
2822 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2823 """
2824 cmd_dict = {
2825 'command': 'AddDomRaisedEventObserver',
2826 'event_name': event_name,
2827 'tab_index' : tab_index,
2828 'windex' : windex,
2829 'frame_xpath' : frame_xpath,
2830 }
2831 return self._GetResultFromJSONRequest(cmd_dict,
2832 windex=windex)['observer_id']
2833
2834 def GetQueuedEvent(self, observer_id=-1, blocking=True, timeout=50000):
Nirnimesh 2012/02/28 09:13:09 why 50 secs? Just use the default automation timeo
craigdh 2012/02/28 22:42:56 Done.
2835 """Waits for an observed event to occur.
2836
2837 The returned event is removed from the Event Queue. If there is already a
2838 matching event in the queue it is returned immediately, otherwise the call
2839 blocks until a matching event occurs. If blocking is disabled and no
2840 matching event is in the queue this function will immediately return None.
2841
2842 Args:
2843 observer_id: The id of the observer to wait for, matches any event by
2844 default.
2845 blocking: If True waits until there is a matching event in the queue,
2846 if False and there is no event waiting in the queue returns
2847 None immediately.
2848 timeout: Time to wait for a matching event, defaults to 50 seconds.
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:
Nirnimesh 2012/02/28 09:13:09 Indent 2 spaces to the right
craigdh 2012/02/28 22:42:56 Done.
2854 { 'observer_id': 1,
Nirnimesh 2012/02/28 09:13:09 same here
craigdh 2012/02/28 22:42:56 Done.
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': 'GetQueuedEvent',
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 Args:
2873 observer_id: The id of the observer to remove.
2874
2875 Raises:
2876 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2877 """
2878 cmd_dict = {
2879 'command': 'RemoveEventObserver',
2880 'observer_id' : observer_id,
2881 }
2882 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
2883
2884 def ClearQueuedEvents(self):
2885 """Removes all events currently in the AutomationEventQueue.
2886
2887 Raises:
2888 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2889 """
2890 cmd_dict = {
2891 'command': 'ClearQueuedEvents',
2892 }
2893 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
2894
2895 def ClearEventObservers(self):
2896 """Removes all Event Observers associated with the AutomationEventQueue.
2897
2898 Raises:
2899 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2900 """
2901 cmd_dict = {
2902 'command': 'ClearEventObservers',
2903 }
2904 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
2905
2801 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): 2906 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''):
2802 """Executes a script in the specified frame of a tab. 2907 """Executes a script in the specified frame of a tab.
2803 2908
2804 By default, execute the script in the top frame of the first tab in the 2909 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 2910 first window. The invoked javascript function must send a result back via
2806 the domAutomationController.send function, or this function will never 2911 the domAutomationController.send function, or this function will never
2807 return. 2912 return.
2808 2913
2809 Args: 2914 Args:
2810 js: script to be executed. 2915 js: script to be executed.
(...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after
5024 successful = result.wasSuccessful() 5129 successful = result.wasSuccessful()
5025 if not successful: 5130 if not successful:
5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 5131 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 5132 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 5133 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5029 sys.exit(not successful) 5134 sys.exit(not successful)
5030 5135
5031 5136
5032 if __name__ == '__main__': 5137 if __name__ == '__main__':
5033 Main() 5138 Main()
OLDNEW
« chrome/test/functional/apptest.py ('K') | « chrome/test/functional/apptest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698