Fix BenchmarkRunner to only import selenium when needed
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / browser_driver / osx_chrome_driver.py
index 013b1006686e00fc55ed6c31cdca24163315c086..c67066bbaffa1291e9ceb8724b18583a842be02e 100644 (file)
@@ -4,19 +4,11 @@ import logging
 import os
 
 from osx_browser_driver import OSXBrowserDriver
-from selenium import webdriver
-from selenium.webdriver.chrome.options import Options
 
 
 _log = logging.getLogger(__name__)
 window_size_arg = '--window-size={width},{height}'.format(width=int(OSXBrowserDriver._screen_size().width), height=int(OSXBrowserDriver._screen_size().height))
 args = ['--args', '--homepage', window_size_arg]
-chrome_options = Options()
-chrome_options.add_argument("--disable-web-security")
-chrome_options.add_argument("--user-data-dir")
-chrome_options.add_argument("--disable-extensions")
-chrome_options.add_argument(window_size_arg)
-
 
 class OSXChromeDriver(OSXBrowserDriver):
     process_name = 'Google Chrome'
@@ -28,11 +20,13 @@ class OSXChromeDriver(OSXBrowserDriver):
         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
 
     def launch_driver(self, url, options, browser_build_path):
+        chrome_options = create_chrome_options()
         if browser_build_path:
             app_path = os.path.join(browser_build_path, self.app_name)
             binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
             chrome_options.binary_location = binary_path
         driver_executable = self.webdriver_binary_path
+        from webkitpy.thirdparty.autoinstalled.selenium import webdriver
         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
         self._launch_webdriver(url=url, driver=driver)
         return driver
@@ -48,12 +42,24 @@ class OSXChromeCanaryDriver(OSXBrowserDriver):
         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
 
     def launch_driver(self, url, options, browser_build_path):
+        chrome_options = create_chrome_options()
         if not browser_build_path:
             browser_build_path = '/Applications/'
         app_path = os.path.join(browser_build_path, self.app_name)
         binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
         chrome_options.binary_location = binary_path
         driver_executable = self.webdriver_binary_path
+        from webkitpy.thirdparty.autoinstalled.selenium import webdriver
         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
         self._launch_webdriver(url=url, driver=driver)
         return driver
+
+
+def create_chrome_options():
+    from webkitpy.thirdparty.autoinstalled.selenium.webdriver.chrome.options import Options
+    chrome_options = Options()
+    chrome_options.add_argument("--disable-web-security")
+    chrome_options.add_argument("--user-data-dir")
+    chrome_options.add_argument("--disable-extensions")
+    chrome_options.add_argument(window_size_arg)
+    return chrome_options