Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WebDriver executor for wptrunner #12380

Merged
merged 3 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/ci/ci_wptrunner_infrastructure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ test_infrastructure() {
}

main() {
PRODUCTS=( "firefox" "chrome" )
PRODUCTS=( "firefox" "chrome" "chrome_webdriver" )
for PRODUCT in "${PRODUCTS[@]}"; do
if [ "$PRODUCT" != "firefox" ]; then
# Firefox is expected to work using pref settings for DNS
# Don't adjust the hostnames in that case to ensure this keeps working
hosts_fixup
fi
if [ "$PRODUCT" == "chrome" ]; then
if [[ "$PRODUCT" == "chrome"* ]]; then
install_chrome unstable
test_infrastructure "--binary=$(which google-chrome-unstable)"
else
Expand Down
10 changes: 8 additions & 2 deletions tools/webdriver/webdriver/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class WebDriverException(Exception):
http_status = None
status_code = None

def __init__(self, message=None, stacktrace=None):
def __init__(self, http_status=None, status_code=None, message=None, stacktrace=None):
super(WebDriverException, self)
self.http_status = http_status
self.status_code = status_code
self.message = message
self.stacktrace = stacktrace

Expand Down Expand Up @@ -171,13 +173,17 @@ def from_response(response):
"""
if response.status == 200:
raise UnknownErrorException(
response.status,
None,
"Response is not an error:\n"
"%s" % json.dumps(response.body))

if "value" in response.body:
value = response.body["value"]
else:
raise UnknownErrorException(
response.status,
None,
"Expected 'value' key in response body:\n"
"%s" % json.dumps(response.body))

Expand All @@ -187,7 +193,7 @@ def from_response(response):
stack = value["stacktrace"] or None

cls = get(code)
return cls(message, stacktrace=stack)
return cls(response.status, code, message, stacktrace=stack)


def get(error_code):
Expand Down
14 changes: 14 additions & 0 deletions tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ def install_webdriver(self, dest=None, channel=None):
def version(self, binary):
return None

class ChromeWebDriver(Chrome):
"""Chrome-specific interface for chrome without using selenium.

Includes webdriver installation.
"""
product = "chrome_webdriver"

class Opera(Browser):
"""Opera-specific interface.
Expand Down Expand Up @@ -582,6 +588,10 @@ def version(self, binary):
return None


class EdgeWebDriver(Edge):
product = "edge_webdriver"


class InternetExplorer(Browser):
"""Internet Explorer-specific interface."""

Expand Down Expand Up @@ -629,6 +639,10 @@ def version(self, binary):
return None


class SafariWebDriver(Safari):
product = "safari_webdriver"


class Servo(Browser):
"""Servo-specific interface."""

Expand Down
17 changes: 17 additions & 0 deletions tools/wpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def setup_kwargs(self, kwargs):
else:
raise WptrunError("Unable to locate or install chromedriver binary")

class ChromeWebDriver(Chrome):
name = "chrome_webdriver"
browser_cls = browser.ChromeWebDriver


class Opera(BrowserSetup):
name = "opera"
Expand Down Expand Up @@ -318,6 +322,11 @@ def setup_kwargs(self, kwargs):
kwargs["webdriver_binary"] = webdriver_binary


class EdgeWebDriver(Edge):
name = "edge_webdriver"
browser_cls = browser.EdgeWebDriver


class InternetExplorer(BrowserSetup):
name = "ie"
browser_cls = browser.InternetExplorer
Expand Down Expand Up @@ -356,6 +365,11 @@ def setup_kwargs(self, kwargs):
kwargs["webdriver_binary"] = webdriver_binary


class SafariWebDriver(Safari):
name = "safari_webdriver"
browser_cls = browser.SafariWebDriver


class Sauce(BrowserSetup):
name = "sauce"
browser_cls = browser.Sauce
Expand Down Expand Up @@ -402,9 +416,12 @@ def setup_kwargs(self, kwargs):
"firefox": Firefox,
"chrome": Chrome,
"chrome_android": ChromeAndroid,
"chrome_webdriver": ChromeWebDriver,
"edge": Edge,
"edge_webdriver": EdgeWebDriver,
"ie": InternetExplorer,
"safari": Safari,
"safari_webdriver": SafariWebDriver,
"servo": Servo,
"sauce": Sauce,
"opera": Opera,
Expand Down
3 changes: 3 additions & 0 deletions tools/wptrunner/wptrunner/browsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@

product_list = ["chrome",
"chrome_android",
"chrome_webdriver",
"edge",
"edge_webdriver",
"fennec",
"firefox",
"ie",
"safari",
"safari_webdriver",
"sauce",
"servo",
"servodriver",
Expand Down
20 changes: 20 additions & 0 deletions tools/wptrunner/wptrunner/browsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
import platform
import socket
from abc import ABCMeta, abstractmethod
from copy import deepcopy

from ..wptcommandline import require_arg # noqa: F401

here = os.path.split(__file__)[0]


def inherit(super_module, child_globals, product_name):
super_wptrunner = super_module.__wptrunner__
child_globals["__wptrunner__"] = child_wptrunner = deepcopy(super_wptrunner)

child_wptrunner["product"] = product_name

for k in ("check_args", "browser", "browser_kwargs", "executor_kwargs",
"env_extras", "env_options"):
attr = super_wptrunner[k]
child_globals[attr] = getattr(super_module, attr)

for v in super_module.__wptrunner__["executor"].values():
child_globals[v] = getattr(super_module, v)

if "run_info_extras" in super_wptrunner:
attr = super_wptrunner["run_info_extras"]
child_globals[attr] = getattr(super_module, attr)


def cmd_arg(name, value=None):
prefix = "-" if platform.system() == "Windows" else "--"
rv = prefix + name
Expand Down
50 changes: 50 additions & 0 deletions tools/wptrunner/wptrunner/browsers/chrome_webdriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

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

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

executor_kwargs["capabilities"] = capabilities

return executor_kwargs
12 changes: 12 additions & 0 deletions tools/wptrunner/wptrunner/browsers/edge_webdriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .base import inherit
from . import edge

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


inherit(edge, globals(), "edge_webdriver")

# __wptrunner__ magically appears from inherit, F821 is undefined name
__wptrunner__["executor"]["testharness"] = "WebDriverTestharnessExecutor" # noqa: F821
__wptrunner__["executor"]["reftest"] = "WebDriverRefTestExecutor" # noqa: F821
12 changes: 12 additions & 0 deletions tools/wptrunner/wptrunner/browsers/safari_webdriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .base import inherit
from . import safari

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


inherit(safari, globals(), "safari_webdriver")

# __wptrunner__ magically appears from inherit, F821 is undefined name
__wptrunner__["executor"]["testharness"] = "WebDriverTestharnessExecutor" # noqa: F821
__wptrunner__["executor"]["reftest"] = "WebDriverRefTestExecutor" # noqa: F821
18 changes: 9 additions & 9 deletions tools/wptrunner/wptrunner/executors/executorselenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def close_old_windows(self):

def get_test_window(self, window_id, parent):
test_window = None
if window_id:
try:
# Try this, it's in Level 1 but nothing supports it yet
win_s = self.webdriver.execute_script("return window['%s'];" % self.window_id)
win_obj = json.loads(win_s)
test_window = win_obj["window-fcc6-11e5-b4f8-330a88ab9d7f"]
except Exception:
pass
try:
# Try using the JSON serialization of the WindowProxy object,
# it's in Level 1 but nothing supports it yet
win_s = self.webdriver.execute_script("return window['%s'];" % window_id)
win_obj = json.loads(win_s)
test_window = win_obj["window-fcc6-11e5-b4f8-330a88ab9d7f"]
except Exception:
pass

if test_window is None:
after = self.webdriver.window_handles
Expand Down Expand Up @@ -296,7 +296,7 @@ def do_testharness(self, protocol, url, timeout):
parent_window = protocol.testharness.close_old_windows()
# Now start the test harness
protocol.base.execute_script(self.script % format_map)
test_window = protocol.testharness.get_test_window(webdriver, parent_window)
test_window = protocol.testharness.get_test_window(self.window_id, parent_window)

handler = CallbackHandler(self.logger, protocol, test_window)
while True:
Expand Down
Loading