testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/chrome_webdriver.py
author Geoffrey Sneddon <me@gsnedders.com>
Fri, 28 Sep 2018 09:54:17 +0000
changeset 494491 a46c08092f37ff84190acaa8c08f30b3ab09a709
parent 491729 b529794168a2bd96e3aba7c600a3d14eb8a48b9f
permissions -rw-r--r--
Bug 1494049 [wpt PR 13201] - Add headless mode for chrome_webdriver, a=testonly Automatic update from web-platform-testsAdd headless mode for chrome_webdriver (#13201) 0200c63a74a540dfb870881d5f476280c367d1c1 failed to add this to chrome_webdriver, so add this now. -- wpt-commits: 1e7408fcd394b66234c38c24ba044ec6f00e4b70 wpt-pr: 13201

from .base import inherit
from . import chrome

from ..executors import executor_kwargs as base_executor_kwargs
from ..executors.executorwebdriver import (WebDriverTestharnessExecutor,  # noqa: F401
                                           WebDriverRefTestExecutor)  # noqa: F401


inherit(chrome, globals(), "chrome_webdriver")

# __wptrunner__ magically appears from inherit, F821 is undefined name
__wptrunner__["executor_kwargs"] = "executor_kwargs"  # noqa: F821
__wptrunner__["executor"]["testharness"] = "WebDriverTestharnessExecutor"  # noqa: F821
__wptrunner__["executor"]["reftest"] = "WebDriverRefTestExecutor"  # noqa: F821


def executor_kwargs(test_type, server_config, cache_manager, run_info_data,
                    **kwargs):
    executor_kwargs = base_executor_kwargs(test_type, server_config,
                                           cache_manager, run_info_data,
                                           **kwargs)
    executor_kwargs["close_after_done"] = True

    capabilities = {
        "browserName": "chrome",
        "platform": "ANY",
        "version": "",
        "goog:chromeOptions": {
            "prefs": {
                "profile": {
                    "default_content_setting_values": {
                        "popups": 1
                    }
                }
            },
            "w3c": True
        }
    }

    for (kwarg, capability) in [("binary", "binary"), ("binary_args", "args")]:
        if kwargs[kwarg] is not None:
            capabilities["goog:chromeOptions"][capability] = kwargs[kwarg]

    if kwargs["headless"]:
        if "args" not in capabilities["goog:chromeOptions"]:
            capabilities["goog:chromeOptions"]["args"] = []
        if "--headless" not in capabilities["goog:chromeOptions"]["args"]:
            capabilities["goog:chromeOptions"]["args"].append("--headless")

    if test_type == "testharness":
        capabilities["goog:chromeOptions"]["useAutomationExtension"] = False
        capabilities["goog:chromeOptions"]["excludeSwitches"] = ["enable-automation"]

    executor_kwargs["capabilities"] = capabilities

    return executor_kwargs