c8139b8e5681cc80e5138d15e721ce7c2ef9f9a4
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / browser_driver / osx_chrome_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 class OSXChromeDriver(OSXBrowserDriver):
12     process_name = 'Google Chrome'
13     browser_name = 'chrome'
14     app_name = 'Google Chrome.app'
15
16     def launch_url(self, url, options, browser_build_path):
17         args_with_url = self._insert_url(create_args(), 2, url)
18         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
19
20     def launch_driver(self, url, options, browser_build_path):
21         import webkitpy.thirdparty.autoinstalled.selenium
22         from selenium import webdriver
23         chrome_options = create_chrome_options()
24         if browser_build_path:
25             app_path = os.path.join(browser_build_path, self.app_name)
26             binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
27             chrome_options.binary_location = binary_path
28         driver_executable = self.webdriver_binary_path
29         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
30         self._launch_webdriver(url=url, driver=driver)
31         return driver
32
33
34 class OSXChromeCanaryDriver(OSXBrowserDriver):
35     process_name = 'Google Chrome Canary'
36     browser_name = 'chrome-canary'
37     app_name = 'Google Chrome Canary.app'
38
39     def launch_url(self, url, options, browser_build_path):
40         args_with_url = self._insert_url(create_args(), 2, url)
41         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
42
43     def launch_driver(self, url, options, browser_build_path):
44         import webkitpy.thirdparty.autoinstalled.selenium
45         from selenium import webdriver
46         chrome_options = create_chrome_options()
47         if not browser_build_path:
48             browser_build_path = '/Applications/'
49         app_path = os.path.join(browser_build_path, self.app_name)
50         binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
51         chrome_options.binary_location = binary_path
52         driver_executable = self.webdriver_binary_path
53         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
54         self._launch_webdriver(url=url, driver=driver)
55         return driver
56
57
58 def create_args():
59     args = ['--args', '--homepage', create_window_size_arg()]
60     return args
61
62 def create_chrome_options():
63     from selenium.webdriver.chrome.options import Options
64     chrome_options = Options()
65     chrome_options.add_argument("--disable-web-security")
66     chrome_options.add_argument("--user-data-dir")
67     chrome_options.add_argument("--disable-extensions")
68     chrome_options.add_argument(create_window_size_arg())
69     return chrome_options
70
71
72 def create_window_size_arg():
73     window_size_arg = '--window-size={width},{height}'.format(width=int(OSXBrowserDriver._screen_size().width), height=int(OSXBrowserDriver._screen_size().height))
74     return window_size_arg