Fix BenchmarkRunner to only import selenium when needed
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / browser_driver / osx_firefox_driver.py
1 #!/usr/bin/env python
2
3 import logging
4 import os
5
6 from osx_browser_driver import OSXBrowserDriver
7
8
9 _log = logging.getLogger(__name__)
10
11 args = ['--args', '-width', str(int(OSXBrowserDriver._screen_size().width)), '-height', str(int(OSXBrowserDriver._screen_size().height))]
12
13
14 class OSXFirefoxDriver(OSXBrowserDriver):
15     process_name = 'firefox'
16     browser_name = 'firefox'
17     app_name = 'Firefox.app'
18
19     def launch_url(self, url, options, browser_build_path):
20         args_with_url = self._insert_url(args, 0, url)
21         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
22
23     def launch_driver(self, url, options, browser_build_path):
24         from webkitpy.thirdparty.autoinstalled.selenium.webdriver.firefox.options import Options
25         firefox_options = Options()
26         if browser_build_path:
27             app_path = os.path.join(browser_build_path, self.app_name)
28             binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
29             firefox_options.binary_location = binary_path
30         driver_executable = self.webdriver_binary_path
31         from webkitpy.thirdparty.autoinstalled.selenium import webdriver
32         driver = webdriver.Firefox(firefox_options=firefox_options, executable_path=driver_executable)
33         self._launch_webdriver(url=url, driver=driver)
34         return driver
35
36
37 class OSXFirefoxNightlyDriver(OSXBrowserDriver):
38     process_name = 'firefox'
39     browser_name = 'firefox-nightly'
40     app_name = 'FirefoxNightly.app'
41
42     def launch_url(self, url, options, browser_build_path):
43         args_with_url = self._insert_url(args, 0, url)
44         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
45
46     def launch_driver(self, url, options, browser_build_path):
47         from webkitpy.thirdparty.autoinstalled.selenium.webdriver.firefox.options import Options
48         firefox_options = Options()
49         if not browser_build_path:
50             browser_build_path = '/Applications/'
51         app_path = os.path.join(browser_build_path, self.app_name)
52         binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
53         firefox_options.binary_location = binary_path
54         driver_executable = self.webdriver_binary_path
55         from webkitpy.thirdparty.autoinstalled.selenium import webdriver
56         driver = webdriver.Firefox(firefox_options=firefox_options, executable_path=driver_executable)
57         self._launch_webdriver(url=url, driver=driver)
58         return driver