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