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

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

Issue 10736055: Smoke test for tracing infrastructure in PyAuto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Smoke test for tracing infrastructure in PyAuto Created 8 years, 5 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 3187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3198 Raises: 3198 Raises:
3199 pyauto_errors.JSONInterfaceError if the automation call returns an error. 3199 pyauto_errors.JSONInterfaceError if the automation call returns an error.
3200 """ 3200 """
3201 cmd_dict = { 3201 cmd_dict = {
3202 'command': 'WaitUntilNavigationCompletes', 3202 'command': 'WaitUntilNavigationCompletes',
3203 'tab_index': tab_index, 3203 'tab_index': tab_index,
3204 'windex': windex, 3204 'windex': windex,
3205 } 3205 }
3206 return self._GetResultFromJSONRequest(cmd_dict) 3206 return self._GetResultFromJSONRequest(cmd_dict)
3207 3207
3208 def ExecuteJavascriptWithFile(self, js, fileName, tab_index=0,
nduca 2012/07/18 05:51:35 Feels like this shoudl be a standalone changelist
3209 windex=0, frame_xpath=''):
3210 """Executes two scripts, one from a file, and one provided as an argument.
nduca 2012/07/18 05:51:35 Personally, this whole entry point feels kinda str
3211
3212 This function executes first the script loaded from "fileName", then the
3213 script in the string "js" all within an anonymous function.
3214
3215 The execution occurrs by calling ExecuteJavascript.
3216
3217 Args:
3218 fileName: filename of the script to load and execute
3219 For other arguments, see ExecuteJavascript
3220
3221 Returns:
3222 See ExecuteJavascript
3223
3224 Raises:
3225 IOError if the file named by fileName cannot be found.
3226 See ExecuteJavascript
3227 """
3228 fileJs, fd = (None, None)
3229 try:
3230 fd = open(fileName, "r")
3231 fileJs = fd.read()
3232 finally:
3233 if( fd != None ):
nduca 2012/07/18 05:51:35 if fd: fd.close() shoudl work
3234 fd.close()
3235 return self.ExecuteJavascript("""
3236 // Keep pollution down by eval'ing in an anonymous function.
3237 (function(){
3238 %s
3239 %s
3240 })();""" % (
3241 fileJs,
3242 js
3243 ), tab_index, windex, frame_xpath)
3244
3208 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''): 3245 def ExecuteJavascript(self, js, tab_index=0, windex=0, frame_xpath=''):
3209 """Executes a script in the specified frame of a tab. 3246 """Executes a script in the specified frame of a tab.
3210 3247
3211 By default, execute the script in the top frame of the first tab in the 3248 By default, execute the script in the top frame of the first tab in the
3212 first window. The invoked javascript function must send a result back via 3249 first window. The invoked javascript function must send a result back via
3213 the domAutomationController.send function, or this function will never 3250 the domAutomationController.send function, or this function will never
3214 return. 3251 return.
3215 3252
3216 Args: 3253 Args:
3217 js: script to be executed. 3254 js: script to be executed.
(...skipping 2784 matching lines...) Expand 10 before | Expand all | Expand 10 after
6002 successful = result.wasSuccessful() 6039 successful = result.wasSuccessful()
6003 if not successful: 6040 if not successful:
6004 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 6041 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
6005 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 6042 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
6006 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 6043 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
6007 sys.exit(not successful) 6044 sys.exit(not successful)
6008 6045
6009 6046
6010 if __name__ == '__main__': 6047 if __name__ == '__main__':
6011 Main() 6048 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698