Chromium Code Reviews| Index: tools/telemetry/telemetry/core/webdriver/webdriver_desktop_browser_finder.py |
| diff --git a/tools/telemetry/telemetry/core/webdriver/webdriver_desktop_browser_finder.py b/tools/telemetry/telemetry/core/webdriver/webdriver_desktop_browser_finder.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4512b891605b06a6ba0b7aac6e87aace74076fa2 |
| --- /dev/null |
| +++ b/tools/telemetry/telemetry/core/webdriver/webdriver_desktop_browser_finder.py |
| @@ -0,0 +1,95 @@ |
| +# Copyright (c) 2013 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. |
| +"""Finds desktop browsers that can be controlled by telemetry.""" |
| + |
| +import os |
| +import sys |
| + |
| +from telemetry.core import browser |
| +from telemetry.core import possible_browser |
| +from telemetry.core import util |
| +from telemetry.core.platform import linux_platform_backend |
| +from telemetry.core.platform import mac_platform_backend |
| +from telemetry.core.platform import win_platform_backend |
| +from telemetry.core.webdriver import webdriver_browser_backend |
| + |
| + |
| +# Add webdriver selenium client to PYTHONPATH. |
| +sys.path.insert(0, os.path.join(util.GetChromiumSrcDir(), |
| + 'third_party', 'webdriver', 'pylib')) |
| +from selenium import webdriver # pylint: disable=F0401 |
|
nduca
2013/07/30 06:49:45
What if this import fails for some reason? Can we
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Let's do it later. crbug.com/266177 was filed.
|
| + |
| +ALL_BROWSER_TYPES = ','.join([ |
| + 'internetexplorer', |
| + 'internetexplorer_x64']) |
|
nduca
2013/07/30 06:49:45
i think we have a naming convention for multi word
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Changed to "internet-explorer-x64". Used x64 becau
|
| + |
| + |
| +class PossibleWebDriverBrowser(possible_browser.PossibleBrowser): |
| + """A browser that can be controlled through webdriver API.""" |
| + |
| + def __init__(self, browser_type, options): |
| + super(PossibleWebDriverBrowser, self).__init__(browser_type, options) |
| + |
| + def CreatePlatformBackend(self): |
| + if sys.platform.startswith('linux'): |
|
nduca
2013/07/30 06:49:45
would a telemetry.core.platform.util.CreatePlatfor
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Done.
|
| + return linux_platform_backend.LinuxPlatformBackend() |
| + elif sys.platform == 'darwin': |
| + return mac_platform_backend.MacPlatformBackend() |
| + elif sys.platform == 'win32': |
| + return win_platform_backend.WinPlatformBackend() |
| + else: |
| + raise NotImplementedError() |
| + |
| + def CreateWebDriverBackend(self): |
| + raise NotImplementedError() |
| + |
| + def Create(self): |
| + backend = self.CreateWebDriverBackend() |
| + b = browser.Browser(backend, self.CreatePlatformBackend()) |
| + backend.SetBrowser(b) |
| + return b |
| + |
| + def SupportsOptions(self, options): |
| + return True |
|
nduca
2013/07/30 06:49:45
really? probably a TODO here no?
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Done.
|
| + |
| + @property |
| + def last_modification_time(self): |
| + return -1 |
| + |
| + def SelectDefaultBrowser(self, possible_browsers): # pylint: disable=W0613 |
| + return None |
| + |
| + |
| +class PossibleDesktopIE(PossibleWebDriverBrowser): |
| + def __init__(self, browser_type, options, architecture): |
| + super(PossibleDesktopIE, self).__init__(browser_type, options) |
| + self._architecture = architecture |
| + |
| + def CreateWebDriverBackend(self): |
| + # TODO Currently require that IEDriverServer.exe is in PATH. |
|
nduca
2013/07/30 06:49:45
# TODO(username): Is our convention.
Also, phrase
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Thanks for detailed explanation.
crbug.com/266170
|
| + driver = webdriver.Ie() |
| + return webdriver_browser_backend.WebDriverBrowserBackend( |
| + driver, False, self.options) |
| + |
| + |
| +def FindAllAvailableBrowsers(options): |
| + """Finds all the desktop browsers available on this machine.""" |
| + browsers = [] |
| + |
| + # Look for the IE browser in the standard location. |
| + if sys.platform.startswith('win'): |
| + ie_path = os.path.join('Internet Explorer', 'iexplore.exe') |
| + win_search_paths = { |
| + '32' : { 'path' : os.getenv('PROGRAMFILES(X86)'), |
| + 'type' : 'internetexplorer'}, |
| + '64' : { 'path' : os.getenv('PROGRAMFILES'), |
| + 'type' : 'internetexplorer_x64'}} |
| + for architecture, ie_info in win_search_paths.iteritems(): |
| + if not ie_info['path']: |
| + continue |
| + if os.path.exists(os.path.join(ie_info['path'], ie_path)): |
| + browsers.append( |
| + PossibleDesktopIE(ie_info['type'], options, architecture)) |
| + |
| + return browsers |