Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 pyauto_paths.GetThirdPartyDir(), |
| 54 | 56 os.path.dirname(__file__), |
|
Nirnimesh
2011/08/01 19:21:24
this should go before third_party
kkania
2011/08/02 15:10:44
Done.
| |
| 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 * |
| 88 except ImportError: | 70 except ImportError: |
| 89 print >>sys.stderr, 'Could not locate pyautolib shared libraries. ' \ | 71 print >>sys.stderr, 'Could not locate pyautolib shared libraries. ' \ |
| 90 'Did you build?\n Documentation: %s' % _PYAUTO_DOC_URL | 72 'Did you build?\n Documentation: %s' % _PYAUTO_DOC_URL |
| 91 # Mac requires python2.5 even when not the default 'python' (e.g. 10.6) | 73 # Mac requires python2.5 even when not the default 'python' (e.g. 10.6) |
| 92 if 'darwin' == sys.platform and sys.version_info[:2] != (2,5): | 74 if 'darwin' == sys.platform and sys.version_info[:2] != (2,5): |
| 93 print >>sys.stderr, '*\n* Perhaps use "python2.5", not "python" ?\n*' | 75 print >>sys.stderr, '*\n* Perhaps use "python2.5", not "python" ?\n*' |
| 94 raise | 76 raise |
| 95 | 77 |
| 96 # Should go after sys.path is set appropriately | 78 # Should go after sys.path is set appropriately |
| 97 import bookmark_model | 79 import bookmark_model |
| 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 |
| 89 from webdriver_factory import WebDriverFactory | |
|
Nirnimesh
2011/08/01 19:21:24
This would work if you have all the webdriver file
kkania
2011/08/02 15:10:44
Done.
| |
| 107 | 90 |
| 91 _WEBDRIVER_FACTORY = WebDriverFactory() | |
| 108 _HTTP_SERVER = None | 92 _HTTP_SERVER = None |
| 109 _REMOTE_PROXY = None | 93 _REMOTE_PROXY = None |
| 110 _OPTIONS = None | 94 _OPTIONS = None |
| 111 | 95 |
| 112 | 96 |
| 113 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): | 97 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
| 114 """Base class for UI Test Cases in Python. | 98 """Base class for UI Test Cases in Python. |
| 115 | 99 |
| 116 A browser is created before executing each test, and is destroyed after | 100 A browser is created before executing each test, and is destroyed after |
| 117 each test irrespective of whether the test passed or failed. | 101 each test irrespective of whether the test passed or failed. |
| (...skipping 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2823 Raises: | 2807 Raises: |
| 2824 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2808 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2825 """ | 2809 """ |
| 2826 cmd_dict = { | 2810 cmd_dict = { |
| 2827 'command': 'SetNTPMenuMode', | 2811 'command': 'SetNTPMenuMode', |
| 2828 'section': section, | 2812 'section': section, |
| 2829 'turn_on': turn_on | 2813 'turn_on': turn_on |
| 2830 } | 2814 } |
| 2831 return self._GetResultFromJSONRequest(cmd_dict) | 2815 return self._GetResultFromJSONRequest(cmd_dict) |
| 2832 | 2816 |
| 2817 def NewWebDriver(self): | |
| 2818 """Returns a new remote WebDriver instance. | |
| 2819 | |
| 2820 Returns: | |
| 2821 selenium.webdriver.remote.webdriver.WebDriver instance | |
| 2822 """ | |
| 2823 global _WEBDRIVER_FACTORY | |
| 2824 return _WEBDRIVER_FACTORY.NewWebDriver(self) | |
| 2825 | |
| 2826 def CreateNewAutomationProvider(self, channel_id): | |
| 2827 """Creates a new automation provider. | |
| 2828 | |
| 2829 The provider will open a named channel in server mode. | |
| 2830 Args: | |
| 2831 channel_id: the channel_id to open the server channel with | |
| 2832 """ | |
| 2833 cmd_dict = { | |
| 2834 'command': 'CreateNewAutomationProvider', | |
| 2835 'channel_id': channel_id | |
| 2836 } | |
| 2837 self._GetResultFromJSONRequest(cmd_dict) | |
| 2838 | |
| 2833 ## ChromeOS section | 2839 ## ChromeOS section |
| 2834 | 2840 |
| 2835 def GetLoginInfo(self): | 2841 def GetLoginInfo(self): |
| 2836 """Returns information about login and screen locker state. | 2842 """Returns information about login and screen locker state. |
| 2837 | 2843 |
| 2838 This includes things like whether a user is logged in, the username | 2844 This includes things like whether a user is logged in, the username |
| 2839 of the logged in user, and whether the screen is locked. | 2845 of the logged in user, and whether the screen is locked. |
| 2840 | 2846 |
| 2841 Returns: | 2847 Returns: |
| 2842 A dictionary. | 2848 A dictionary. |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3739 # the test cases, which is odd because our test cases depend on | 3745 # the test cases, which is odd because our test cases depend on |
| 3740 # initializtions like exitmanager, autorelease pool provided by the | 3746 # initializtions like exitmanager, autorelease pool provided by the |
| 3741 # suite. Forcibly delete the test cases before the suite. | 3747 # suite. Forcibly delete the test cases before the suite. |
| 3742 del self._tests | 3748 del self._tests |
| 3743 pyautolib.PyUITestSuiteBase.__del__(self) | 3749 pyautolib.PyUITestSuiteBase.__del__(self) |
| 3744 | 3750 |
| 3745 global _HTTP_SERVER | 3751 global _HTTP_SERVER |
| 3746 if _HTTP_SERVER: | 3752 if _HTTP_SERVER: |
| 3747 self._StopHTTPServer() | 3753 self._StopHTTPServer() |
| 3748 | 3754 |
| 3755 global _WEBDRIVER_FACTORY | |
| 3756 if _WEBDRIVER_FACTORY: | |
| 3757 _WEBDRIVER_FACTORY.Stop() | |
| 3758 | |
| 3749 def _StartHTTPServer(self): | 3759 def _StartHTTPServer(self): |
| 3750 """Start a local file server hosting data files over http://""" | 3760 """Start a local file server hosting data files over http://""" |
| 3751 global _HTTP_SERVER | 3761 global _HTTP_SERVER |
| 3752 assert not _HTTP_SERVER, 'HTTP Server already started' | 3762 assert not _HTTP_SERVER, 'HTTP Server already started' |
| 3753 http_data_dir = _OPTIONS.http_data_dir | 3763 http_data_dir = _OPTIONS.http_data_dir |
| 3754 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, | 3764 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, |
| 3755 pyautolib.FilePath(http_data_dir)) | 3765 pyautolib.FilePath(http_data_dir)) |
| 3756 assert http_server.Start(), 'Could not start http server' | 3766 assert http_server.Start(), 'Could not start http server' |
| 3757 _HTTP_SERVER = http_server | 3767 _HTTP_SERVER = http_server |
| 3758 logging.debug('Started http server at "%s".' % http_data_dir) | 3768 logging.debug('Started http server at "%s".' % http_data_dir) |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4118 successful = result.wasSuccessful() | 4128 successful = result.wasSuccessful() |
| 4119 if not successful: | 4129 if not successful: |
| 4120 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 4130 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 4121 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 4131 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 4122 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 4132 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 4123 sys.exit(not successful) | 4133 sys.exit(not successful) |
| 4124 | 4134 |
| 4125 | 4135 |
| 4126 if __name__ == '__main__': | 4136 if __name__ == '__main__': |
| 4127 Main() | 4137 Main() |
| OLD | NEW |