Add WebDriver support in browser driver part of BenchmarkRunner
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Jul 2017 00:40:52 +0000 (00:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Jul 2017 00:40:52 +0000 (00:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174445

Patch by Matthew Stewart <matthew_r_stewart@apple.com> on 2017-07-24
Reviewed by Stephanie Lewis.

Adds a launch_driver function to each BrowserDriver subclass. This
function sets up the arguments for the webdriver and launches the
webdriver specific to that browser.

* Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py:
(BrowserDriver.launch_webdriver):
(BrowserDriver):
* Scripts/webkitpy/benchmark_runner/browser_driver/linux_browser_driver.py:
(LinuxBrowserDriver.launch_webdriver):
* Scripts/webkitpy/benchmark_runner/browser_driver/linux_chrome_driver.py:
(LinuxChromeDriver.launch_url):
(LinuxChromeDriver):
(LinuxChromeDriver.launch_driver):
* Scripts/webkitpy/benchmark_runner/browser_driver/linux_epiphany_driver.py:
(EpiphanyBrowserDriver.launch_url):
(EpiphanyBrowserDriver):
(EpiphanyBrowserDriver.launch_driver):
* Scripts/webkitpy/benchmark_runner/browser_driver/linux_firefox_driver.py:
(LinuxFirefoxDriver):
(LinuxFirefoxDriver.launch_url):
(LinuxFirefoxDriver.launch_driver):
* Scripts/webkitpy/benchmark_runner/browser_driver/linux_minibrowsergtk_driver.py:
(GTKMiniBrowserDriver.launch_url):
(GTKMiniBrowserDriver):
(GTKMiniBrowserDriver.launch_driver):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py:
(OSXBrowserDriver._launch_webdriver):
(OSXBrowserDriver):
(OSXBrowserDriver._screen_size):
(OSXBrowserDriver._insert_url):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py:
(OSXChromeDriver):
(OSXChromeDriver.launch_url):
(OSXChromeDriver.launch_driver):
(OSXChromeCanaryDriver):
(OSXChromeCanaryDriver.launch_url):
(OSXChromeCanaryDriver.launch_driver):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py:
(OSXFirefoxDriver):
(OSXFirefoxDriver.launch_url):
(OSXFirefoxDriver.launch_driver):
(OSXFirefoxNightlyDriver):
(OSXFirefoxNightlyDriver.launch_url):
(OSXFirefoxNightlyDriver.launch_driver):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py:
(OSXSafariDriver.launch_driver):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219850 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_browser_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_chrome_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_epiphany_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_firefox_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_minibrowsergtk_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py

index c40f1c3..cf2277e 100644 (file)
@@ -1,3 +1,57 @@
+2017-07-24  Matthew Stewart  <matthew_r_stewart@apple.com>
+
+        Add WebDriver support in browser driver part of BenchmarkRunner
+        https://bugs.webkit.org/show_bug.cgi?id=174445
+
+        Reviewed by Stephanie Lewis.
+
+        Adds a launch_driver function to each BrowserDriver subclass. This
+        function sets up the arguments for the webdriver and launches the
+        webdriver specific to that browser.
+
+        * Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py:
+        (BrowserDriver.launch_webdriver):
+        (BrowserDriver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_browser_driver.py:
+        (LinuxBrowserDriver.launch_webdriver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_chrome_driver.py:
+        (LinuxChromeDriver.launch_url):
+        (LinuxChromeDriver):
+        (LinuxChromeDriver.launch_driver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_epiphany_driver.py:
+        (EpiphanyBrowserDriver.launch_url):
+        (EpiphanyBrowserDriver):
+        (EpiphanyBrowserDriver.launch_driver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_firefox_driver.py:
+        (LinuxFirefoxDriver):
+        (LinuxFirefoxDriver.launch_url):
+        (LinuxFirefoxDriver.launch_driver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_minibrowsergtk_driver.py:
+        (GTKMiniBrowserDriver.launch_url):
+        (GTKMiniBrowserDriver):
+        (GTKMiniBrowserDriver.launch_driver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py:
+        (OSXBrowserDriver._launch_webdriver):
+        (OSXBrowserDriver):
+        (OSXBrowserDriver._screen_size):
+        (OSXBrowserDriver._insert_url):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py:
+        (OSXChromeDriver):
+        (OSXChromeDriver.launch_url):
+        (OSXChromeDriver.launch_driver):
+        (OSXChromeCanaryDriver):
+        (OSXChromeCanaryDriver.launch_url):
+        (OSXChromeCanaryDriver.launch_driver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py:
+        (OSXFirefoxDriver):
+        (OSXFirefoxDriver.launch_url):
+        (OSXFirefoxDriver.launch_driver):
+        (OSXFirefoxNightlyDriver):
+        (OSXFirefoxNightlyDriver.launch_url):
+        (OSXFirefoxNightlyDriver.launch_driver):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py:
+        (OSXSafariDriver.launch_driver):
+
 2017-07-24  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Mac WK2] Add an API test to cover r219765 (null dereference in [WKWebView dealloc])
index 75e8a46..b41a1c9 100644 (file)
@@ -18,6 +18,10 @@ class BrowserDriver(object):
         pass
 
     @abstractmethod
+    def launch_webdriver(self, url, driver):
+        pass
+
+    @abstractmethod
     def add_additional_results(self, test_url, results):
         return results
 
index 4c3e3be..182102c 100644 (file)
@@ -97,6 +97,10 @@ class LinuxBrowserDriver(BrowserDriver):
                                                  stdout=subprocess.PIPE,
                                                  stderr=subprocess.STDOUT)
 
+    def launch_webdriver(self, url, driver):
+        _log.info('Launching "%s" with url "%s"' % (driver.name, url))
+        driver.get(url)
+
     def _get_first_executable_path_from_list(self, searchlist):
         searchpath = [os.path.curdir] + os.environ['PATH'].split(os.pathsep)
         for program in searchlist:
index 71c1727..3c0207f 100644 (file)
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import os
+
 from linux_browser_driver import LinuxBrowserDriver
+from selenium import webdriver
+from selenium.webdriver.chrome.options import Options
 
 
 class LinuxChromeDriver(LinuxBrowserDriver):
@@ -35,3 +39,16 @@ class LinuxChromeDriver(LinuxBrowserDriver):
         self._browser_arguments = ['--temp-profile', '--start-maximized',
                                    '--homepage', url]
         super(LinuxChromeDriver, self).launch_url(url, options, browser_build_path)
+
+    def launch_driver(self, url, options, browser_build_path):
+        options = Options()
+        options.add_argument("--disable-web-security")
+        options.add_argument("--user-data-dir")
+        options.add_argument("--disable-extensions")
+        options.add_argument("--start-maximized")
+        if browser_build_path:
+            binary_path = os.path.join(browser_build_path, 'chromium-browser')
+            options.binary_location = binary_path
+        driver = webdriver.Chrome(chrome_options=options)
+        super(LinuxChromeDriver, self).launch_webdriver(url, driver)
+        return driver
index cb96526..d2c600e 100644 (file)
@@ -36,3 +36,6 @@ class EpiphanyBrowserDriver(LinuxBrowserDriver):
                                    '--profile={profile}'.format(profile=self._temp_profiledir),
                                    url]
         super(EpiphanyBrowserDriver, self).launch_url(url, options, browser_build_path)
+
+    def launch_driver(self, url, options, browser_build_path):
+        raise ValueError("Browser {browser} is not available with webdriver".format(browser=self.browser_name))
index 3c5eb49..bda2131 100644 (file)
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import os
+
 from linux_browser_driver import LinuxBrowserDriver
+from selenium import webdriver
+from selenium.webdriver.firefox.options import Options
 
 
 class LinuxFirefoxDriver(LinuxBrowserDriver):
     browser_name = 'firefox'
-    process_search_list = ['firefox']
+    process_search_list = ['firefox', 'firefox-bin']
 
     def launch_url(self, url, options, browser_build_path):
         self._browser_arguments = ['-new-instance', '-profile', self._temp_profiledir,
@@ -37,3 +41,12 @@ class LinuxFirefoxDriver(LinuxBrowserDriver):
                                    '-height', str(self._screen_size().height),
                                    url]
         super(LinuxFirefoxDriver, self).launch_url(url, options, browser_build_path)
+
+    def launch_driver(self, url, options, browser_build_path):
+        options = Options()
+        if browser_build_path:
+            binary_path = os.path.join(browser_build_path, 'firefox-bin')
+            options.binary_location = binary_path
+        driver = webdriver.Firefox(firefox_options=options)
+        super(LinuxFirefoxDriver, self).launch_webdriver(url, driver)
+        return driver
index edc97c5..3148f7f 100644 (file)
@@ -38,3 +38,6 @@ class GTKMiniBrowserDriver(LinuxBrowserDriver):
         self._browser_arguments.append('--geometry={w}x{h}'.format(w=self._screen_size().width, h=self._screen_size().height))
         self._browser_arguments.append(url)
         super(GTKMiniBrowserDriver, self).launch_url(url, options, browser_build_path)
+
+    def launch_driver(self, url, options, browser_build_path):
+        raise ValueError("Browser {browser} is not available with webdriver".format(browser=self.browser_name))
index 5d03c0c..ece83a6 100644 (file)
@@ -43,6 +43,11 @@ class OSXBrowserDriver(BrowserDriver):
         cls._launch_process_with_caffinate(args)
 
     @classmethod
+    def _launch_webdriver(cls, url, driver):
+        _log.info('Launching "%s" with url "%s"' % (driver.name, url))
+        driver.get(url)
+
+    @classmethod
     def _terminate_processes(cls, process_name):
         _log.info('Closing all processes with name %s' % process_name)
         subprocess.call(['/usr/bin/killall', process_name])
@@ -57,3 +62,9 @@ class OSXBrowserDriver(BrowserDriver):
     def _screen_size(cls):
         from AppKit import NSScreen
         return NSScreen.mainScreen().frame().size
+
+    @classmethod
+    def _insert_url(cls, args, pos, url):
+        temp_args = args[:]
+        temp_args.insert(pos, url)
+        return temp_args
index 5c72d81..12af135 100644 (file)
@@ -6,22 +6,54 @@ import subprocess
 import time
 
 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'
     browser_name = 'chrome'
+    app_name = 'Google Chrome.app'
 
     def launch_url(self, url, options, browser_build_path):
-        self._launch_process(build_dir=browser_build_path, app_name='Google Chrome.app', url=url, args=['--args', '--homepage', url, '--window-size={width},{height}'.format(width=int(self._screen_size().width), height=int(self._screen_size().height))])
+        args_with_url = self._insert_url(args, 2, url)
+        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):
+        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 = webdriver.Chrome(chrome_options=chrome_options)
+        self._launch_webdriver(url=url, driver=driver)
+        return driver
 
 
 class OSXChromeCanaryDriver(OSXBrowserDriver):
     process_name = 'Google Chrome Canary'
     browser_name = 'chrome-canary'
+    app_name = 'Google Chrome Canary.app'
 
     def launch_url(self, url, options, browser_build_path):
-        self._launch_process(build_dir=browser_build_path, app_name='Google Chrome Canary.app', url=url, args=['--args', '--homepage', url, '--window-size={width},{height}'.format(width=int(self._screen_size().width), height=int(self._screen_size().height))])
+        args_with_url = self._insert_url(args, 2, url)
+        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):
+        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 = webdriver.Chrome(chrome_options=chrome_options)
+        self._launch_webdriver(url=url, driver=driver)
+        return driver
index 3860ed2..8254cd4 100644 (file)
@@ -6,22 +6,50 @@ import subprocess
 import time
 
 from osx_browser_driver import OSXBrowserDriver
+from selenium import webdriver
+from selenium.webdriver.firefox.options import Options
 
 
 _log = logging.getLogger(__name__)
 
+args = ['--args', '-width', str(int(OSXBrowserDriver._screen_size().width)), '-height', str(int(OSXBrowserDriver._screen_size().height))]
+firefox_options = Options()
+
 
 class OSXFirefoxDriver(OSXBrowserDriver):
     process_name = 'firefox'
     browser_name = 'firefox'
+    app_name = 'Firefox.app'
 
     def launch_url(self, url, options, browser_build_path):
-        self._launch_process(build_dir=browser_build_path, app_name='Firefox.app', url=url, args=[url, '--args', '-width', str(int(self._screen_size().width)), '-height', str(int(self._screen_size().height))])
+        args_with_url = self._insert_url(args, 0, url)
+        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):
+        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)
+            firefox_options.binary_location = binary_path
+        driver = webdriver.Firefox(firefox_options=firefox_options)
+        self._launch_webdriver(url=url, driver=driver)
+        return driver
 
 
 class OSXFirefoxNightlyDriver(OSXBrowserDriver):
     process_name = 'firefox'
     browser_name = 'firefox-nightly'
+    app_name = 'FirefoxNightly.app'
 
     def launch_url(self, url, options, browser_build_path):
-        self._launch_process(build_dir=browser_build_path, app_name='FirefoxNightly.app', url=url, args=[url, '--args', '-width', str(int(self._screen_size().width)), '-height', str(int(self._screen_size().height))])
+        args_with_url = self._insert_url(args, 0, url)
+        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):
+        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)
+        firefox_options.binary_location = binary_path
+        driver = webdriver.Firefox(firefox_options=firefox_options)
+        self._launch_webdriver(url=url, driver=driver)
+        return driver
index 8308c98..3c89058 100644 (file)
@@ -8,6 +8,7 @@ import time
 
 from osx_browser_driver import OSXBrowserDriver
 from webkitpy.benchmark_runner.utils import force_remove
+from selenium import webdriver
 
 
 _log = logging.getLogger(__name__)
@@ -45,6 +46,11 @@ class OSXSafariDriver(OSXBrowserDriver):
         time.sleep(3)
         subprocess.Popen(['open', '-a', args[0], url])
 
+    def launch_driver(self, url, options, browser_build_path):
+        driver = webdriver.Safari(quiet=False)
+        self._launch_webdriver(url=url, driver=driver)
+        return driver
+
     def close_browsers(self):
         super(OSXSafariDriver, self).close_browsers()
         if self._safari_process and self._safari_process.returncode: