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

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 second round of 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=''):
Nirnimesh 2012/02/29 03:22:08 align under self
craigdh 2012/02/29 22:53:43 Done. That's the danger of renaming with a regular
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
Nirnimesh 2012/02/29 03:22:08 need space after #
craigdh 2012/02/29 22:53:43 Done.
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']
2832
2833 def GetNextEvent(self, observer_id=-1, blocking=True, timeout=None):
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/02/29 03:22:08 this is too large. default to the regular timeout.
craigdh 2012/02/29 22:53:43 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 if timeout is None:
2867 timeout = self.large_test_timeout_ms()
2868 return self._GetResultFromJSONRequest(cmd_dict, windex=None,
2869 timeout=timeout)
2870
2871 def RemoveEventObserver(self, observer_id):
2872 """Removes an Event Observer from the AutomationEventQueue.
2873
2874 Expects a valid observer_id.
2875
2876 Args:
2877 observer_id: The id of the observer to remove.
2878
2879 Raises:
2880 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2881 """
2882 cmd_dict = {
2883 'command': 'RemoveEventObserver',
2884 'observer_id' : observer_id,
2885 }
2886 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
2887
2888 def ClearEventQueue(self):
2889 """Removes all events currently in the AutomationEventQueue.
2890
2891 Raises:
2892 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2893 """
2894 cmd_dict = {
2895 'command': 'ClearEventQueue',
2896 }
2897 return self._GetResultFromJSONRequest(cmd_dict, windex=None)
2898
2801 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): 2899 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''):
2802 """Executes a script in the specified frame of a tab. 2900 """Executes a script in the specified frame of a tab.
2803 2901
2804 By default, execute the script in the top frame of the first tab in the 2902 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 2903 first window. The invoked javascript function must send a result back via
2806 the domAutomationController.send function, or this function will never 2904 the domAutomationController.send function, or this function will never
2807 return. 2905 return.
2808 2906
2809 Args: 2907 Args:
2810 js: script to be executed. 2908 js: script to be executed.
(...skipping 2213 matching lines...) Expand 10 before | Expand all | Expand 10 after
5024 successful = result.wasSuccessful() 5122 successful = result.wasSuccessful()
5025 if not successful: 5123 if not successful:
5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 5124 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 5125 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 5126 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5029 sys.exit(not successful) 5127 sys.exit(not successful)
5030 5128
5031 5129
5032 if __name__ == '__main__': 5130 if __name__ == '__main__':
5033 Main() 5131 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