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

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

Issue 7634031: Let pyauto create an attached webdriver instance to manipulate web pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forgot to re-add the previously added files Created 9 years, 4 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/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """PyAuto: Python Interface to Chromium's Automation Proxy. 7 """PyAuto: Python Interface to Chromium's Automation Proxy.
8 8
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. 9 PyAuto uses swig to expose Automation Proxy interfaces to Python.
10 For complete documentation on the functionality available, 10 For complete documentation on the functionality available,
(...skipping 28 matching lines...) Expand all
39 import stat 39 import stat
40 import string 40 import string
41 import subprocess 41 import subprocess
42 import sys 42 import sys
43 import tempfile 43 import tempfile
44 import time 44 import time
45 import types 45 import types
46 import unittest 46 import unittest
47 import urllib 47 import urllib
48 48
49 import pyauto_paths
50
49 51
50 def _LocateBinDirs(): 52 def _LocateBinDirs():
51 """Setup a few dirs where we expect to find dependency libraries.""" 53 """Setup a few dirs where we expect to find dependency libraries."""
52 script_dir = os.path.dirname(__file__) 54 deps_dirs = [
53 chrome_src = os.path.join(script_dir, os.pardir, os.pardir, os.pardir) 55 os.path.dirname(__file__),
54 56 pyauto_paths.GetThirdPartyDir(),
55 bin_dirs = { 57 os.path.join(pyauto_paths.GetThirdPartyDir(), 'webdriver', 'python'),
56 'linux2': [ os.path.join(chrome_src, 'out', 'Debug'),
57 os.path.join(chrome_src, 'sconsbuild', 'Debug'),
58 os.path.join(chrome_src, 'out', 'Release'),
59 os.path.join(chrome_src, 'sconsbuild', 'Release')],
60 'linux3': [ os.path.join(chrome_src, 'out', 'Debug'),
61 os.path.join(chrome_src, 'sconsbuild', 'Debug'),
62 os.path.join(chrome_src, 'out', 'Release'),
63 os.path.join(chrome_src, 'sconsbuild', 'Release')],
64 'darwin': [ os.path.join(chrome_src, 'xcodebuild', 'Debug'),
65 os.path.join(chrome_src, 'xcodebuild', 'Release')],
66 'win32': [ os.path.join(chrome_src, 'chrome', 'Debug'),
67 os.path.join(chrome_src, 'build', 'Debug'),
68 os.path.join(chrome_src, 'chrome', 'Release'),
69 os.path.join(chrome_src, 'build', 'Release')],
70 'cygwin': [ os.path.join(chrome_src, 'chrome', 'Debug'),
71 os.path.join(chrome_src, 'chrome', 'Release')],
72 }
73 deps_dirs = [ os.path.join(script_dir, os.pardir,
74 os.pardir, os.pardir, 'third_party'),
75 script_dir,
76 ] 58 ]
77 sys.path += map(os.path.normpath, bin_dirs.get(sys.platform, []) + deps_dirs) 59 sys.path += map(os.path.normpath, pyauto_paths.GetBuildDirs() + deps_dirs)
78 60
79 _LocateBinDirs() 61 _LocateBinDirs()
80 62
81 _PYAUTO_DOC_URL = 'http://dev.chromium.org/developers/testing/pyauto' 63 _PYAUTO_DOC_URL = 'http://dev.chromium.org/developers/testing/pyauto'
82 64
83 try: 65 try:
84 import pyautolib 66 import pyautolib
85 # Needed so that all additional classes (like: FilePath, GURL) exposed by 67 # Needed so that all additional classes (like: FilePath, GURL) exposed by
86 # swig interface get available in this module. 68 # swig interface get available in this module.
87 from pyautolib import * 69 from pyautolib import *
(...skipping 10 matching lines...) Expand all
98 import download_info 80 import download_info
99 import history_info 81 import history_info
100 import omnibox_info 82 import omnibox_info
101 import plugins_info 83 import plugins_info
102 import prefs_info 84 import prefs_info
103 from pyauto_errors import JSONInterfaceError 85 from pyauto_errors import JSONInterfaceError
104 from pyauto_errors import NTPThumbnailNotShownError 86 from pyauto_errors import NTPThumbnailNotShownError
105 import pyauto_utils 87 import pyauto_utils
106 import simplejson as json # found in third_party 88 import simplejson as json # found in third_party
107 89
90 _CHROME_DRIVER_FACTORY = None
108 _HTTP_SERVER = None 91 _HTTP_SERVER = None
109 _REMOTE_PROXY = None 92 _REMOTE_PROXY = None
110 _OPTIONS = None 93 _OPTIONS = None
111 94
112 95
113 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): 96 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
114 """Base class for UI Test Cases in Python. 97 """Base class for UI Test Cases in Python.
115 98
116 A browser is created before executing each test, and is destroyed after 99 A browser is created before executing each test, and is destroyed after
117 each test irrespective of whether the test passed or failed. 100 each test irrespective of whether the test passed or failed.
(...skipping 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after
2823 Raises: 2806 Raises:
2824 pyauto_errors.JSONInterfaceError if the automation call returns an error. 2807 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2825 """ 2808 """
2826 cmd_dict = { 2809 cmd_dict = {
2827 'command': 'SetNTPMenuMode', 2810 'command': 'SetNTPMenuMode',
2828 'section': section, 2811 'section': section,
2829 'turn_on': turn_on 2812 'turn_on': turn_on
2830 } 2813 }
2831 return self._GetResultFromJSONRequest(cmd_dict) 2814 return self._GetResultFromJSONRequest(cmd_dict)
2832 2815
2816 def NewWebDriver(self):
2817 """Returns a new remote WebDriver instance.
2818
2819 Returns:
2820 selenium.webdriver.remote.webdriver.WebDriver instance
2821 """
2822 from chrome_driver_factory import ChromeDriverFactory
2823 global _CHROME_DRIVER_FACTORY
2824 if _CHROME_DRIVER_FACTORY is None:
2825 _CHROME_DRIVER_FACTORY = ChromeDriverFactory()
2826 return _CHROME_DRIVER_FACTORY.NewChromeDriver(self)
2827
2828 def CreateNewAutomationProvider(self, channel_id):
2829 """Creates a new automation provider.
2830
2831 The provider will open a named channel in server mode.
2832 Args:
2833 channel_id: the channel_id to open the server channel with
2834 """
2835 cmd_dict = {
2836 'command': 'CreateNewAutomationProvider',
2837 'channel_id': channel_id
2838 }
2839 self._GetResultFromJSONRequest(cmd_dict)
2840
2833 ## ChromeOS section 2841 ## ChromeOS section
2834 2842
2835 def GetLoginInfo(self): 2843 def GetLoginInfo(self):
2836 """Returns information about login and screen locker state. 2844 """Returns information about login and screen locker state.
2837 2845
2838 This includes things like whether a user is logged in, the username 2846 This includes things like whether a user is logged in, the username
2839 of the logged in user, and whether the screen is locked. 2847 of the logged in user, and whether the screen is locked.
2840 2848
2841 Returns: 2849 Returns:
2842 A dictionary. 2850 A dictionary.
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
3815 # the test cases, which is odd because our test cases depend on 3823 # the test cases, which is odd because our test cases depend on
3816 # initializtions like exitmanager, autorelease pool provided by the 3824 # initializtions like exitmanager, autorelease pool provided by the
3817 # suite. Forcibly delete the test cases before the suite. 3825 # suite. Forcibly delete the test cases before the suite.
3818 del self._tests 3826 del self._tests
3819 pyautolib.PyUITestSuiteBase.__del__(self) 3827 pyautolib.PyUITestSuiteBase.__del__(self)
3820 3828
3821 global _HTTP_SERVER 3829 global _HTTP_SERVER
3822 if _HTTP_SERVER: 3830 if _HTTP_SERVER:
3823 self._StopHTTPServer() 3831 self._StopHTTPServer()
3824 3832
3833 global _CHROME_DRIVER_FACTORY
3834 if _CHROME_DRIVER_FACTORY is not None:
3835 _CHROME_DRIVER_FACTORY.Stop()
3836
3825 def _StartHTTPServer(self): 3837 def _StartHTTPServer(self):
3826 """Start a local file server hosting data files over http://""" 3838 """Start a local file server hosting data files over http://"""
3827 global _HTTP_SERVER 3839 global _HTTP_SERVER
3828 assert not _HTTP_SERVER, 'HTTP Server already started' 3840 assert not _HTTP_SERVER, 'HTTP Server already started'
3829 http_data_dir = _OPTIONS.http_data_dir 3841 http_data_dir = _OPTIONS.http_data_dir
3830 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, 3842 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP,
3831 pyautolib.FilePath(http_data_dir)) 3843 pyautolib.FilePath(http_data_dir))
3832 assert http_server.Start(), 'Could not start http server' 3844 assert http_server.Start(), 'Could not start http server'
3833 _HTTP_SERVER = http_server 3845 _HTTP_SERVER = http_server
3834 logging.debug('Started http server at "%s".' % http_data_dir) 3846 logging.debug('Started http server at "%s".' % http_data_dir)
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
4194 successful = result.wasSuccessful() 4206 successful = result.wasSuccessful()
4195 if not successful: 4207 if not successful:
4196 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 4208 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
4197 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 4209 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
4198 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 4210 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
4199 sys.exit(not successful) 4211 sys.exit(not successful)
4200 4212
4201 4213
4202 if __name__ == '__main__': 4214 if __name__ == '__main__':
4203 Main() 4215 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698