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

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

Issue 7629019: Revert 96556 - Let pyauto create an attached webdriver instance to manipulate web pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/test/pyautolib/chrome_driver_factory.py ('k') | chrome/test/pyautolib/pyauto_paths.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
51 49
52 def _LocateBinDirs(): 50 def _LocateBinDirs():
53 """Setup a few dirs where we expect to find dependency libraries.""" 51 """Setup a few dirs where we expect to find dependency libraries."""
54 deps_dirs = [ 52 script_dir = os.path.dirname(__file__)
55 os.path.dirname(__file__), 53 chrome_src = os.path.join(script_dir, os.pardir, os.pardir, os.pardir)
56 pyauto_paths.GetThirdPartyDir(), 54
57 os.path.join(pyauto_paths.GetThirdPartyDir(), 'webdriver', 'python'), 55 bin_dirs = {
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,
58 ] 76 ]
59 sys.path += map(os.path.normpath, pyauto_paths.GetBuildDirs() + deps_dirs) 77 sys.path += map(os.path.normpath, bin_dirs.get(sys.platform, []) + deps_dirs)
60 78
61 _LocateBinDirs() 79 _LocateBinDirs()
62 80
63 _PYAUTO_DOC_URL = 'http://dev.chromium.org/developers/testing/pyauto' 81 _PYAUTO_DOC_URL = 'http://dev.chromium.org/developers/testing/pyauto'
64 82
65 try: 83 try:
66 import pyautolib 84 import pyautolib
67 # Needed so that all additional classes (like: FilePath, GURL) exposed by 85 # Needed so that all additional classes (like: FilePath, GURL) exposed by
68 # swig interface get available in this module. 86 # swig interface get available in this module.
69 from pyautolib import * 87 from pyautolib import *
(...skipping 10 matching lines...) Expand all
80 import download_info 98 import download_info
81 import history_info 99 import history_info
82 import omnibox_info 100 import omnibox_info
83 import plugins_info 101 import plugins_info
84 import prefs_info 102 import prefs_info
85 from pyauto_errors import JSONInterfaceError 103 from pyauto_errors import JSONInterfaceError
86 from pyauto_errors import NTPThumbnailNotShownError 104 from pyauto_errors import NTPThumbnailNotShownError
87 import pyauto_utils 105 import pyauto_utils
88 import simplejson as json # found in third_party 106 import simplejson as json # found in third_party
89 107
90 _CHROME_DRIVER_FACTORY = None
91 _HTTP_SERVER = None 108 _HTTP_SERVER = None
92 _REMOTE_PROXY = None 109 _REMOTE_PROXY = None
93 _OPTIONS = None 110 _OPTIONS = None
94 111
95 112
96 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): 113 class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
97 """Base class for UI Test Cases in Python. 114 """Base class for UI Test Cases in Python.
98 115
99 A browser is created before executing each test, and is destroyed after 116 A browser is created before executing each test, and is destroyed after
100 each test irrespective of whether the test passed or failed. 117 each test irrespective of whether the test passed or failed.
(...skipping 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after
2806 Raises: 2823 Raises:
2807 pyauto_errors.JSONInterfaceError if the automation call returns an error. 2824 pyauto_errors.JSONInterfaceError if the automation call returns an error.
2808 """ 2825 """
2809 cmd_dict = { 2826 cmd_dict = {
2810 'command': 'SetNTPMenuMode', 2827 'command': 'SetNTPMenuMode',
2811 'section': section, 2828 'section': section,
2812 'turn_on': turn_on 2829 'turn_on': turn_on
2813 } 2830 }
2814 return self._GetResultFromJSONRequest(cmd_dict) 2831 return self._GetResultFromJSONRequest(cmd_dict)
2815 2832
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
2841 ## ChromeOS section 2833 ## ChromeOS section
2842 2834
2843 def GetLoginInfo(self): 2835 def GetLoginInfo(self):
2844 """Returns information about login and screen locker state. 2836 """Returns information about login and screen locker state.
2845 2837
2846 This includes things like whether a user is logged in, the username 2838 This includes things like whether a user is logged in, the username
2847 of the logged in user, and whether the screen is locked. 2839 of the logged in user, and whether the screen is locked.
2848 2840
2849 Returns: 2841 Returns:
2850 A dictionary. 2842 A dictionary.
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 # the test cases, which is odd because our test cases depend on 3815 # the test cases, which is odd because our test cases depend on
3824 # initializtions like exitmanager, autorelease pool provided by the 3816 # initializtions like exitmanager, autorelease pool provided by the
3825 # suite. Forcibly delete the test cases before the suite. 3817 # suite. Forcibly delete the test cases before the suite.
3826 del self._tests 3818 del self._tests
3827 pyautolib.PyUITestSuiteBase.__del__(self) 3819 pyautolib.PyUITestSuiteBase.__del__(self)
3828 3820
3829 global _HTTP_SERVER 3821 global _HTTP_SERVER
3830 if _HTTP_SERVER: 3822 if _HTTP_SERVER:
3831 self._StopHTTPServer() 3823 self._StopHTTPServer()
3832 3824
3833 global _CHROME_DRIVER_FACTORY
3834 if _CHROME_DRIVER_FACTORY is not None:
3835 _CHROME_DRIVER_FACTORY.Stop()
3836
3837 def _StartHTTPServer(self): 3825 def _StartHTTPServer(self):
3838 """Start a local file server hosting data files over http://""" 3826 """Start a local file server hosting data files over http://"""
3839 global _HTTP_SERVER 3827 global _HTTP_SERVER
3840 assert not _HTTP_SERVER, 'HTTP Server already started' 3828 assert not _HTTP_SERVER, 'HTTP Server already started'
3841 http_data_dir = _OPTIONS.http_data_dir 3829 http_data_dir = _OPTIONS.http_data_dir
3842 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, 3830 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP,
3843 pyautolib.FilePath(http_data_dir)) 3831 pyautolib.FilePath(http_data_dir))
3844 assert http_server.Start(), 'Could not start http server' 3832 assert http_server.Start(), 'Could not start http server'
3845 _HTTP_SERVER = http_server 3833 _HTTP_SERVER = http_server
3846 logging.debug('Started http server at "%s".' % http_data_dir) 3834 logging.debug('Started http server at "%s".' % http_data_dir)
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
4206 successful = result.wasSuccessful() 4194 successful = result.wasSuccessful()
4207 if not successful: 4195 if not successful:
4208 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 4196 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
4209 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 4197 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
4210 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 4198 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
4211 sys.exit(not successful) 4199 sys.exit(not successful)
4212 4200
4213 4201
4214 if __name__ == '__main__': 4202 if __name__ == '__main__':
4215 Main() 4203 Main()
OLDNEW
« no previous file with comments | « chrome/test/pyautolib/chrome_driver_factory.py ('k') | chrome/test/pyautolib/pyauto_paths.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698