diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-12 18:12:24 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-12 18:12:24 +0000 |
commit | ada3e82b82a0ebfb91db4a6e8c371e8162fde89f (patch) | |
tree | ebd9188a41f2d8954799f26c7feccb3108afebdc /chrome/test/pyautolib | |
parent | 79f16a133050196d2a78ef9478f8f59b4680981d (diff) | |
download | chromium_src-ada3e82b82a0ebfb91db4a6e8c371e8162fde89f.zip chromium_src-ada3e82b82a0ebfb91db4a6e8c371e8162fde89f.tar.gz chromium_src-ada3e82b82a0ebfb91db4a6e8c371e8162fde89f.tar.bz2 |
Revert 96556 - Let pyauto create an attached webdriver instance to manipulate web pages.
BUG=49379
TEST=none
Review URL: http://codereview.chromium.org/7523060
TBR=hnguyen
Review URL: http://codereview.chromium.org/7629019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r-- | chrome/test/pyautolib/chrome_driver_factory.py | 62 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 62 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto_paths.py | 57 |
3 files changed, 25 insertions, 156 deletions
diff --git a/chrome/test/pyautolib/chrome_driver_factory.py b/chrome/test/pyautolib/chrome_driver_factory.py deleted file mode 100644 index 3ea970d..0000000 --- a/chrome/test/pyautolib/chrome_driver_factory.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Factory that creates ChromeDriver instances for pyauto.""" - -import os -import random -import tempfile - -import pyauto_paths -from selenium import webdriver -from selenium.webdriver.chrome import service - - -class ChromeDriverFactory(object): - """"Factory that creates ChromeDriver instances for pyauto. - - Starts a single chromedriver server when necessary. Users should call 'Stop' - when no longer using the factory. - """ - - def __init__(self): - self._chromedriver_server = None - - def NewChromeDriver(self, pyauto): - """Creates a new remote WebDriver instance. - - This instance will connect to a new automation provider of an already - running Chrome. - Args: - pyauto: pyauto.PyUITest instance - - Returns: - selenium.webdriver.remote.webdriver.WebDriver instance - """ - self._StartServerIfNecessary() - channel_id = 'testing' + hex(random.getrandbits(20 * 4))[2:-1] - if not pyauto.IsWin(): - channel_id = os.path.join(tempfile.gettempdir(), channel_id) - pyauto.CreateNewAutomationProvider(channel_id) - return webdriver.Remote(self._chromedriver_server.service_url, - {'chrome.channel': channel_id}) - - def _StartServerIfNecessary(self): - """Starts the ChromeDriver server, if not already started.""" - if self._chromedriver_server is None: - exe = pyauto_paths.GetChromeDriverExe() - assert exe, 'Cannot find chromedriver exe. Did you build it?' - self._chromedriver_server = service.Service(exe) - self._chromedriver_server.start() - - def Stop(self): - """Stops the ChromeDriver server, if running.""" - if self._chromedriver_server is not None: - self._chromedriver_server.stop() - self._chromedriver_server = None - - def __del__(self): - self.Stop() - diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 89ef512..329c9bf 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -46,17 +46,35 @@ import types import unittest import urllib -import pyauto_paths - def _LocateBinDirs(): """Setup a few dirs where we expect to find dependency libraries.""" - deps_dirs = [ - os.path.dirname(__file__), - pyauto_paths.GetThirdPartyDir(), - os.path.join(pyauto_paths.GetThirdPartyDir(), 'webdriver', 'python'), + script_dir = os.path.dirname(__file__) + chrome_src = os.path.join(script_dir, os.pardir, os.pardir, os.pardir) + + bin_dirs = { + 'linux2': [ os.path.join(chrome_src, 'out', 'Debug'), + os.path.join(chrome_src, 'sconsbuild', 'Debug'), + os.path.join(chrome_src, 'out', 'Release'), + os.path.join(chrome_src, 'sconsbuild', 'Release')], + 'linux3': [ os.path.join(chrome_src, 'out', 'Debug'), + os.path.join(chrome_src, 'sconsbuild', 'Debug'), + os.path.join(chrome_src, 'out', 'Release'), + os.path.join(chrome_src, 'sconsbuild', 'Release')], + 'darwin': [ os.path.join(chrome_src, 'xcodebuild', 'Debug'), + os.path.join(chrome_src, 'xcodebuild', 'Release')], + 'win32': [ os.path.join(chrome_src, 'chrome', 'Debug'), + os.path.join(chrome_src, 'build', 'Debug'), + os.path.join(chrome_src, 'chrome', 'Release'), + os.path.join(chrome_src, 'build', 'Release')], + 'cygwin': [ os.path.join(chrome_src, 'chrome', 'Debug'), + os.path.join(chrome_src, 'chrome', 'Release')], + } + deps_dirs = [ os.path.join(script_dir, os.pardir, + os.pardir, os.pardir, 'third_party'), + script_dir, ] - sys.path += map(os.path.normpath, pyauto_paths.GetBuildDirs() + deps_dirs) + sys.path += map(os.path.normpath, bin_dirs.get(sys.platform, []) + deps_dirs) _LocateBinDirs() @@ -87,7 +105,6 @@ from pyauto_errors import NTPThumbnailNotShownError import pyauto_utils import simplejson as json # found in third_party -_CHROME_DRIVER_FACTORY = None _HTTP_SERVER = None _REMOTE_PROXY = None _OPTIONS = None @@ -2813,31 +2830,6 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } return self._GetResultFromJSONRequest(cmd_dict) - def NewWebDriver(self): - """Returns a new remote WebDriver instance. - - Returns: - selenium.webdriver.remote.webdriver.WebDriver instance - """ - from chrome_driver_factory import ChromeDriverFactory - global _CHROME_DRIVER_FACTORY - if _CHROME_DRIVER_FACTORY is None: - _CHROME_DRIVER_FACTORY = ChromeDriverFactory() - return _CHROME_DRIVER_FACTORY.NewChromeDriver(self) - - def CreateNewAutomationProvider(self, channel_id): - """Creates a new automation provider. - - The provider will open a named channel in server mode. - Args: - channel_id: the channel_id to open the server channel with - """ - cmd_dict = { - 'command': 'CreateNewAutomationProvider', - 'channel_id': channel_id - } - self._GetResultFromJSONRequest(cmd_dict) - ## ChromeOS section def GetLoginInfo(self): @@ -3830,10 +3822,6 @@ class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): if _HTTP_SERVER: self._StopHTTPServer() - global _CHROME_DRIVER_FACTORY - if _CHROME_DRIVER_FACTORY is not None: - _CHROME_DRIVER_FACTORY.Stop() - def _StartHTTPServer(self): """Start a local file server hosting data files over http://""" global _HTTP_SERVER diff --git a/chrome/test/pyautolib/pyauto_paths.py b/chrome/test/pyautolib/pyauto_paths.py deleted file mode 100644 index 5b9bb1e..0000000 --- a/chrome/test/pyautolib/pyauto_paths.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Common paths for pyauto tests.""" - -import os -import sys - - -def GetSourceDir(): - """Returns src/ directory.""" - script_dir = os.path.abspath(os.path.dirname(__file__)) - return os.path.join(script_dir, os.pardir, os.pardir, os.pardir) - - -def GetThirdPartyDir(): - """Returns src/third_party directory.""" - return os.path.join(GetSourceDir(), 'third_party') - - -def GetBuildDirs(): - """Returns list of possible build directories.""" - build_dirs = { - 'linux2': [ os.path.join('out', 'Debug'), - os.path.join('sconsbuild', 'Debug'), - os.path.join('out', 'Release'), - os.path.join('sconsbuild', 'Release')], - 'linux3': [ os.path.join('out', 'Debug'), - os.path.join('sconsbuild', 'Debug'), - os.path.join('out', 'Release'), - os.path.join('sconsbuild', 'Release')], - 'darwin': [ os.path.join('xcodebuild', 'Debug'), - os.path.join('xcodebuild', 'Release')], - 'win32': [ os.path.join('chrome', 'Debug'), - os.path.join('build', 'Debug'), - os.path.join('chrome', 'Release'), - os.path.join('build', 'Release')], - 'cygwin': [ os.path.join('chrome', 'Debug'), - os.path.join('chrome', 'Release')], - } - src_dir = GetSourceDir() - return map(lambda dir: os.path.join(src_dir, dir), - build_dirs.get(sys.platform, [])) - - -def GetChromeDriverExe(): - """Returns path to ChromeDriver executable, or None if cannot be found.""" - exe_name = 'chromedriver' - if sys.platform == 'win32': - exe_name += '.exe' - for dir in GetBuildDirs(): - exe = os.path.join(dir, exe_name) - if os.path.exists(exe): - return exe - return None |