Commit 6eb98719 authored by chrisgao@chromium.org's avatar chrisgao@chromium.org

Fix finding chrome binary for ChromeDriver.

NOTRY=true
BUG=none

Review URL: https://chromiumcodereview.appspot.com/11414267

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170861 0039d316-1c4b-4281-b951-d872f2087c98
parent 694dfbdf
...@@ -30,9 +30,19 @@ def _ExceptionForResponse(response): ...@@ -30,9 +30,19 @@ def _ExceptionForResponse(response):
class ChromeDriver(object): class ChromeDriver(object):
"""Starts and controls a single Chrome instance on this machine.""" """Starts and controls a single Chrome instance on this machine."""
def __init__(self, lib_path): def __init__(self, lib_path, chrome_binary=None):
self._lib = ctypes.CDLL(lib_path) self._lib = ctypes.CDLL(lib_path)
self._session_id = self._ExecuteCommand('newSession') if chrome_binary is None:
params = {}
else:
params = {
'desiredCapabilities': {
'chrome': {
'binary': chrome_binary
}
}
}
self._session_id = self._ExecuteCommand('newSession', params)
def _ExecuteCommand(self, name, params={}, session_id=''): def _ExecuteCommand(self, name, params={}, session_id=''):
cmd = { cmd = {
......
...@@ -14,6 +14,31 @@ sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib')) ...@@ -14,6 +14,31 @@ sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib'))
from common import chrome_paths from common import chrome_paths
from common import util from common import util
def _AppendEnvironmentPath(env_name, path):
if env_name in os.environ:
lib_path = os.environ[env_name]
if path not in lib_path:
os.environ[env_name] += os.pathsep + path
else:
os.environ[env_name] = path
def _FindChromeBinary(path):
if util.IsLinux():
exes = ['chrome']
elif util.IsMac():
exes = [
'Google Chrome.app/Contents/MacOS/Google Chrome',
'Chromium.app/Contents/MacOS/Chromium'
]
elif util.IsWindows():
exes = ['chrome.exe']
else:
exes = []
for exe in exes:
binary = os.path.join(path, exe)
if os.path.exists(binary):
return binary
return None
def Main(): def Main():
print '@@@BUILD_STEP chromedriver2_tests@@@' print '@@@BUILD_STEP chromedriver2_tests@@@'
...@@ -29,6 +54,17 @@ def Main(): ...@@ -29,6 +54,17 @@ def Main():
os.path.join(_THIS_DIR, 'test.py'), os.path.join(_THIS_DIR, 'test.py'),
os.path.join(build_dir, chromedriver), os.path.join(build_dir, chromedriver),
] ]
# Set the built chrome binary.
chrome_binary = _FindChromeBinary(build_dir)
if chrome_binary is not None:
cmd.append(chrome_binary)
if util.IsLinux():
# Set LD_LIBRARY_PATH to enable successful loading of shared object files,
# when chromedriver2.so is not a static build.
_AppendEnvironmentPath('LD_LIBRARY_PATH', os.path.join(build_dir, 'lib'))
elif util.IsMac():
# In Mac, chromedriver2.so is a 32-bit build, so run with the 32-bit python.
os.environ['VERSIONER_PYTHON_PREFER_32_BIT'] = 'yes'
code = util.RunCommand(cmd) code = util.RunCommand(cmd)
if code != 0: if code != 0:
print '@@@STEP_FAILURE@@@' print '@@@STEP_FAILURE@@@'
......
...@@ -16,15 +16,21 @@ class ChromeDriverTest(unittest.TestCase): ...@@ -16,15 +16,21 @@ class ChromeDriverTest(unittest.TestCase):
"""End to end tests for ChromeDriver.""" """End to end tests for ChromeDriver."""
def testStartStop(self): def testStartStop(self):
driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB) driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY)
driver.Quit() driver.Quit()
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 2: if len(sys.argv) != 2 and len(sys.argv) != 3:
print 'Usage: %s <path_to_chromedriver_so>' % __file__ print ('Usage: %s <path_to_chromedriver_so> [path_to_chrome_binary]' %
__file__)
sys.exit(1) sys.exit(1)
global _CHROMEDRIVER_LIB global _CHROMEDRIVER_LIB
_CHROMEDRIVER_LIB = os.path.abspath(sys.argv[1]) _CHROMEDRIVER_LIB = os.path.abspath(sys.argv[1])
global _CHROME_BINARY
if len(sys.argv) == 3:
_CHROME_BINARY = os.path.abspath(sys.argv[2])
else:
_CHROME_BINARY = None
all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
sys.modules[__name__]) sys.modules[__name__])
result = unittest.TextTestRunner().run(all_tests_suite) result = unittest.TextTestRunner().run(all_tests_suite)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment