1# Copyright (c) 2012 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 5import os 6import platform 7import sys 8 9import util 10 11 12def GetTestDataPath(relative_path): 13 """Returns the path to the given path under chromedriver's test data dir.""" 14 return os.path.join(TEST_DATA_PATH, relative_path) 15 16 17def GetChromeTestDataPath(relative_path): 18 """Returns the path to the given path under chrome's test data dir.""" 19 return os.path.join(CHROME_TEST_DATA_PATH, relative_path) 20 21 22def _SetupPaths(): 23 start_dir = os.path.abspath(os.path.dirname(__file__)) 24 J = os.path.join 25 26 global SRC_PATH 27 SRC_PATH = J(start_dir, os.pardir, os.pardir, os.pardir, os.pardir) 28 29 global TEST_DATA_PATH, PEM_CERT_AND_KEY 30 TEST_DATA_PATH = start_dir 31 PEM_CERT_AND_KEY = J(start_dir, 'cert.pem') 32 33 global CHROME_TEST_DATA_PATH 34 CHROME_TEST_DATA_PATH = J(SRC_PATH, 'chrome', 'test', 'data') 35 36 global SRC_THIRD_PARTY, PYTHON_BINDINGS, WEBDRIVER_TEST_DATA 37 SRC_THIRD_PARTY = J(SRC_PATH, 'third_party') 38 webdriver = J(SRC_THIRD_PARTY, 'webdriver') 39 PYTHON_BINDINGS = J(webdriver, 'pylib') 40 WEBDRIVER_TEST_DATA = J(webdriver, 'test_data') 41 42 global CHROMEDRIVER_EXE, CHROME_EXE 43 def _FindDriver(): 44 cd_exe_name = 'chromedriver' 45 if util.IsWin(): 46 cd_exe_name += '.exe' 47 for dir in _DefaultExeLocations(): 48 path = os.path.abspath(os.path.join(dir, cd_exe_name)) 49 if os.path.exists(path): 50 return path 51 return None 52 CHROMEDRIVER_EXE = _FindDriver() 53 54 def _FindChrome(): 55 possible_paths = [] 56 if util.IsWin(): 57 possible_paths += ['chrome.exe'] 58 elif util.IsMac(): 59 possible_paths += ['Chromium.app/Contents/MacOS/Chromium', 60 'Google Chrome.app/Contents/MacOS/Google Chrome'] 61 elif util.IsLinux(): 62 possible_paths += ['chrome'] 63 for dir in _DefaultExeLocations(): 64 for chrome_path in possible_paths: 65 path = os.path.abspath(os.path.join(dir, chrome_path)) 66 if os.path.exists(path): 67 return path 68 return None 69 CHROME_EXE = _FindChrome() 70 71 72def _DefaultExeLocations(): 73 """Returns the paths that are used to find the ChromeDriver executable. 74 75 Returns: 76 a list of directories that would be searched for the executable 77 """ 78 bin_dirs = { 79 'linux2': [ os.path.join(SRC_PATH, 'out', 'Debug'), 80 os.path.join(SRC_PATH, 'sconsbuild', 'Debug'), 81 os.path.join(SRC_PATH, 'out', 'Release'), 82 os.path.join(SRC_PATH, 'sconsbuild', 'Release')], 83 'linux3': [ os.path.join(SRC_PATH, 'out', 'Debug'), 84 os.path.join(SRC_PATH, 'sconsbuild', 'Debug'), 85 os.path.join(SRC_PATH, 'out', 'Release'), 86 os.path.join(SRC_PATH, 'sconsbuild', 'Release')], 87 'darwin': [ os.path.join(SRC_PATH, 'xcodebuild', 'Debug'), 88 os.path.join(SRC_PATH, 'xcodebuild', 'Release')], 89 'win32': [ os.path.join(SRC_PATH, 'chrome', 'Debug'), 90 os.path.join(SRC_PATH, 'build', 'Debug'), 91 os.path.join(SRC_PATH, 'chrome', 'Release'), 92 os.path.join(SRC_PATH, 'build', 'Release')], 93 } 94 return bin_dirs.get(sys.platform, []) 95 96 97_SetupPaths() 98