1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 """Finds desktop browsers that can be controlled by telemetry."""
10 from telemetry.core import browser
11 from telemetry.core import possible_browser
12 from telemetry.core import platform
13 from telemetry.core import util
14 from telemetry.core.backends.webdriver import webdriver_ie_backend
15 from telemetry.page import cloud_storage
17 # Try to import the selenium python lib which may be not available.
18 util.AddDirToPythonPath(
19 util.GetChromiumSrcDir(), 'third_party', 'webdriver', 'pylib')
21 from selenium import webdriver # pylint: disable=F0401
25 ALL_BROWSER_TYPES = []
29 'internet-explorer-x64']
31 logging.warning('Webdriver backend is unsupported without selenium pylib. '
32 'For installation of selenium pylib, please refer to '
33 'https://code.google.com/p/selenium/wiki/PythonBindings.')
36 class PossibleWebDriverBrowser(possible_browser.PossibleBrowser):
37 """A browser that can be controlled through webdriver API."""
39 def __init__(self, browser_type, finder_options):
40 target_os = sys.platform.lower()
41 super(PossibleWebDriverBrowser, self).__init__(browser_type, target_os,
43 assert browser_type in ALL_BROWSER_TYPES, \
44 'Please add %s to ALL_BROWSER_TYPES' % browser_type
46 def CreateWebDriverBackend(self, platform_backend):
47 raise NotImplementedError()
50 platform_backend = platform.CreatePlatformBackendForCurrentOS()
51 backend = self.CreateWebDriverBackend(platform_backend)
52 b = browser.Browser(backend, platform_backend)
55 def SupportsOptions(self, finder_options):
56 if len(finder_options.extensions_to_load) != 0:
60 def UpdateExecutableIfNeeded(self):
64 def last_modification_time(self):
68 class PossibleDesktopIE(PossibleWebDriverBrowser):
69 def __init__(self, browser_type, finder_options, architecture):
70 super(PossibleDesktopIE, self).__init__(browser_type, finder_options)
71 self._architecture = architecture
73 def CreateWebDriverBackend(self, platform_backend):
76 ie_driver_exe = os.path.join(util.GetTelemetryDir(), 'bin',
77 'IEDriverServer_%s.exe' % self._architecture)
78 cloud_storage.GetIfChanged(ie_driver_exe, cloud_storage.PUBLIC_BUCKET)
79 return webdriver.Ie(executable_path=ie_driver_exe)
80 return webdriver_ie_backend.WebDriverIEBackend(
81 platform_backend, DriverCreator, self.finder_options.browser_options)
83 def SelectDefaultBrowser(_):
86 def FindAllAvailableBrowsers(finder_options):
87 """Finds all the desktop browsers available on this machine."""
92 # Look for the IE browser in the standard location.
93 if sys.platform.startswith('win'):
94 ie_path = os.path.join('Internet Explorer', 'iexplore.exe')
96 '32' : { 'path' : os.getenv('PROGRAMFILES(X86)'),
97 'type' : 'internet-explorer'},
98 '64' : { 'path' : os.getenv('PROGRAMFILES'),
99 'type' : 'internet-explorer-x64'}}
100 for architecture, ie_info in win_search_paths.iteritems():
101 if not ie_info['path']:
103 if os.path.exists(os.path.join(ie_info['path'], ie_path)):
105 PossibleDesktopIE(ie_info['type'], finder_options, architecture))