OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 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.""" |
| 5 |
| 6 import os |
| 7 import sys |
| 8 |
| 9 from telemetry.core import browser |
| 10 from telemetry.core import util |
| 11 from telemetry.core import possible_browser |
| 12 from telemetry.core import platform |
| 13 from telemetry.core.backends.webdriver import webdriver_browser_backend |
| 14 |
| 15 |
| 16 # Add webdriver selenium client to PYTHONPATH. |
| 17 sys.path.insert(0, os.path.join(util.GetChromiumSrcDir(), |
| 18 'third_party', 'webdriver', 'pylib')) |
| 19 # TODO(chrisgao): Handle failure of import gracefully. crbug.com/266177 |
| 20 from selenium import webdriver # pylint: disable=F0401 |
| 21 |
| 22 ALL_BROWSER_TYPES = ','.join([ |
| 23 'internet-explorer', |
| 24 'internet-explorer-x64']) |
| 25 |
| 26 |
| 27 class PossibleWebDriverBrowser(possible_browser.PossibleBrowser): |
| 28 """A browser that can be controlled through webdriver API.""" |
| 29 |
| 30 def __init__(self, browser_type, options): |
| 31 super(PossibleWebDriverBrowser, self).__init__(browser_type, options) |
| 32 |
| 33 def CreateWebDriverBackend(self): |
| 34 raise NotImplementedError() |
| 35 |
| 36 def Create(self): |
| 37 backend = self.CreateWebDriverBackend() |
| 38 b = browser.Browser(backend, platform.CreatePlatformBackendForCurrentOS()) |
| 39 return b |
| 40 |
| 41 def SupportsOptions(self, options): |
| 42 # TODO(chrisgao): Check if some options are not supported. |
| 43 return True |
| 44 |
| 45 @property |
| 46 def last_modification_time(self): |
| 47 return -1 |
| 48 |
| 49 def SelectDefaultBrowser(self, possible_browsers): # pylint: disable=W0613 |
| 50 return None |
| 51 |
| 52 |
| 53 class PossibleDesktopIE(PossibleWebDriverBrowser): |
| 54 def __init__(self, browser_type, options, architecture): |
| 55 super(PossibleDesktopIE, self).__init__(browser_type, options) |
| 56 self._architecture = architecture |
| 57 |
| 58 def CreateWebDriverBackend(self): |
| 59 def DriverCreator(): |
| 60 # TODO(chrisgao): Check in IEDriverServer.exe and specify path to it when |
| 61 # creating the webdriver instance. crbug.com/266170 |
| 62 return webdriver.Ie() |
| 63 return webdriver_browser_backend.WebDriverBrowserBackend( |
| 64 DriverCreator, False, self.options) |
| 65 |
| 66 |
| 67 def FindAllAvailableBrowsers(options): |
| 68 """Finds all the desktop browsers available on this machine.""" |
| 69 browsers = [] |
| 70 |
| 71 # Look for the IE browser in the standard location. |
| 72 if sys.platform.startswith('win'): |
| 73 ie_path = os.path.join('Internet Explorer', 'iexplore.exe') |
| 74 win_search_paths = { |
| 75 '32' : { 'path' : os.getenv('PROGRAMFILES(X86)'), |
| 76 'type' : 'internet-explorer'}, |
| 77 '64' : { 'path' : os.getenv('PROGRAMFILES'), |
| 78 'type' : 'internet-explorer-x64'}} |
| 79 for architecture, ie_info in win_search_paths.iteritems(): |
| 80 if not ie_info['path']: |
| 81 continue |
| 82 if os.path.exists(os.path.join(ie_info['path'], ie_path)): |
| 83 browsers.append( |
| 84 PossibleDesktopIE(ie_info['type'], options, architecture)) |
| 85 |
| 86 return browsers |
OLD | NEW |