Skip to content
Draft
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
184 changes: 0 additions & 184 deletions py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1219,190 +1219,6 @@ test_suite(
],
)

py_test_suite(
name = "test-webkitgtk-common",
size = "large",
srcs = glob(
[
"test/selenium/webdriver/common/**/*.py",
"test/selenium/webdriver/support/**/*.py",
],
exclude = BIDI_TESTS + ACTIONS_TESTS + FEATURE_TESTS,
),
args = [
"--instafail",
"--driver=webkitgtk",
"--browser-binary=MiniBrowser",
"--browser-args=--automation",
],
tags = [
"exclusive-if-local",
"no-sandbox",
"skip-rbe",
],
test_suffix = "webkitgtk",
deps = [
":common",
":init-tree",
":support",
":webkitgtk",
":webserver",
] + TEST_DEPS,
)

py_test_suite(
name = "test-webkitgtk-actions",
size = "large",
srcs = ACTIONS_TESTS,
args = [
"--instafail",
"--driver=webkitgtk",
"--browser-binary=MiniBrowser",
"--browser-args=--automation",
],
tags = [
"exclusive-if-local",
"no-sandbox",
"skip-rbe",
],
test_suffix = "webkitgtk-actions",
deps = [
":common_actions",
":init-tree",
":support",
":webkitgtk",
":webserver",
] + TEST_DEPS,
)

[
py_test_suite(
name = "test-webkitgtk-%s" % feature,
size = "large",
srcs = FEATURE_SUITE_DEFS[feature][0],
args = [
"--instafail",
"--driver=webkitgtk",
"--browser-binary=MiniBrowser",
"--browser-args=--automation",
],
tags = [
"exclusive-if-local",
"no-sandbox",
"skip-rbe",
],
test_suffix = "webkitgtk-%s" % feature,
deps = [
":init-tree",
":support",
":webkitgtk",
":webserver",
FEATURE_SUITE_DEFS[feature][1],
] + TEST_DEPS,
)
for feature in FEATURE_SUITE_DEFS
]

test_suite(
name = "test-webkitgtk",
tests = [
":test-webkitgtk-actions",
":test-webkitgtk-common",
] + [":test-webkitgtk-%s" % f for f in FEATURE_SUITE_DEFS],
)

py_test_suite(
name = "test-wpewebkit-common",
size = "large",
srcs = glob(
[
"test/selenium/webdriver/common/**/*.py",
"test/selenium/webdriver/support/**/*.py",
],
exclude = BIDI_TESTS + ACTIONS_TESTS + FEATURE_TESTS,
),
args = [
"--instafail",
"--driver=wpewebkit",
"--browser-binary=MiniBrowser",
"--browser-args=--automation --headless",
],
tags = [
"exclusive-if-local",
"no-sandbox",
"skip-rbe",
],
test_suffix = "wpewebkit",
deps = [
":common",
":init-tree",
":support",
":webserver",
":wpewebkit",
] + TEST_DEPS,
)

py_test_suite(
name = "test-wpewebkit-actions",
size = "large",
srcs = ACTIONS_TESTS,
args = [
"--instafail",
"--driver=wpewebkit",
"--browser-binary=MiniBrowser",
"--browser-args=--automation --headless",
],
tags = [
"exclusive-if-local",
"no-sandbox",
"skip-rbe",
],
test_suffix = "wpewebkit-actions",
deps = [
":common_actions",
":init-tree",
":support",
":webserver",
":wpewebkit",
] + TEST_DEPS,
)

[
py_test_suite(
name = "test-wpewebkit-%s" % feature,
size = "large",
srcs = FEATURE_SUITE_DEFS[feature][0],
args = [
"--instafail",
"--driver=wpewebkit",
"--browser-binary=MiniBrowser",
"--browser-args=--automation --headless",
],
tags = [
"exclusive-if-local",
"no-sandbox",
"skip-rbe",
],
test_suffix = "wpewebkit-%s" % feature,
deps = [
":init-tree",
":support",
":webserver",
":wpewebkit",
FEATURE_SUITE_DEFS[feature][1],
] + TEST_DEPS,
)
for feature in FEATURE_SUITE_DEFS
]

test_suite(
name = "test-wpewebkit",
tests = [
":test-wpewebkit-actions",
":test-wpewebkit-common",
] + [":test-wpewebkit-%s" % f for f in FEATURE_SUITE_DEFS],
)

py_binary(
name = "generate-api-listing",
srcs = ["generate_api_module_listing.py"],
Expand Down
110 changes: 98 additions & 12 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@

from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.options import ArgOptions
from selenium.webdriver.common.service import Service
from selenium.webdriver.common.utils import free_port
from selenium.webdriver.common.webdriver import LocalWebDriver
from selenium.webdriver.remote.server import Server
from test.selenium.webdriver.common.network import get_lan_ip
from test.selenium.webdriver.common.webserver import SimpleWebServer
Expand Down Expand Up @@ -278,8 +281,6 @@ class SupportedDrivers(ContainerProtocol):
safari: str = "Safari"
edge: str = "Edge"
ie: str = "Ie"
webkitgtk: str = "WebKitGTK"
wpewebkit: str = "WPEWebKit"


@dataclass
Expand All @@ -289,8 +290,6 @@ class SupportedOptions(ContainerProtocol):
edge: str = "EdgeOptions"
safari: str = "SafariOptions"
ie: str = "IeOptions"
webkitgtk: str = "WebKitGTKOptions"
wpewebkit: str = "WPEWebKitOptions"


@dataclass
Expand Down Expand Up @@ -419,8 +418,6 @@ def options(self, cls_name):
self._options.enable_downloads = True

if self.browser_path or self.browser_args:
if self.driver_class == self.supported_drivers.webkitgtk:
self._options.overlay_scrollbars_enabled = False
if self.browser_path is not None:
self._options.binary_location = self.browser_path.strip("'")
if self.browser_args is not None:
Expand Down Expand Up @@ -448,8 +445,6 @@ def is_platform_valid(self):
return False
if self.driver_class.lower() == "ie" and self.exe_platform != "Windows":
return False
if "webkit" in self.driver_class.lower() and self.exe_platform == "Windows":
return False
return True

@property
Expand All @@ -470,7 +465,7 @@ def _start_local_driver(self, kwargs):
if self.driver_path is not None:
kwargs["service"] = self.service
try:
return getattr(webdriver, self.driver_class)(**kwargs)
return self._build_local_driver(kwargs)
except (WebDriverException, urllib3.exceptions.HTTPError, OSError) as e:
if attempt == self.DRIVER_START_RETRIES:
raise
Expand All @@ -489,14 +484,17 @@ def stop_driver(self):
if driver_to_stop is not None:
driver_to_stop.quit()

def _build_local_driver(self, kwargs):
return getattr(webdriver, self.driver_class)(**kwargs)


@pytest.fixture
def driver(request, server):
global selenium_driver
driver_class = getattr(request, "param", "Chrome").lower()

if selenium_driver is None:
selenium_driver = Driver(driver_class, request)
selenium_driver = make_driver(driver_class, request)
if server:
selenium_driver._server = server

Expand Down Expand Up @@ -700,14 +698,14 @@ def clean_driver(request):
@pytest.fixture
def clean_service(request):
driver_class = request.config.option.drivers[0].lower()
selenium_driver = Driver(driver_class, request)
selenium_driver = make_driver(driver_class, request)
return selenium_driver.service


@pytest.fixture
def clean_options(request):
driver_class = request.config.option.drivers[0].lower()
return Driver.clean_options(driver_class, request)
return make_driver(driver_class, request).options


@pytest.fixture
Expand Down Expand Up @@ -778,3 +776,91 @@ def do_GET(self):
for server in servers:
server.shutdown()
server.server_close()


# WebKitGTK and WPE WebKit are W3C-compliant drivers maintained by the WebKit
# project and are not run in our CI. Kept isolated here so the base Driver
# carries no WebKit branches and they avoid the deprecated binding modules.
WEBKIT_DRIVERS = {
"webkitgtk": {"options_key": "webkitgtk:browserOptions", "overlay_scrollbars": True},
"wpewebkit": {"options_key": "wpe:browserOptions", "overlay_scrollbars": False},
}


@dataclass
class SupportedWebKitDrivers(ContainerProtocol):
webkitgtk: str = "WebKitGTK"
wpewebkit: str = "WPEWebKit"


class _WebKitService(Service):
def command_line_args(self) -> list[str]:
return ["-p", f"{self.port}"]


class _WebKitLocalDriver(LocalWebDriver):
def __init__(self, options=None, service=None):
self.service = service
try:
self.service.start()
super().__init__(command_executor=self.service.service_url, options=options)
except Exception:
# Only tear down if a process was actually started; otherwise
# Service.stop() raises AttributeError and masks the real failure.
if getattr(self.service, "process", None) is not None:
self.quit()
raise
Comment thread
titusfortner marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.


def _webkit_options(name, *, binary=None, args=()):
config = WEBKIT_DRIVERS[name]
args = list(args)

options = ArgOptions()
options.set_capability("browserName", "MiniBrowser")

browser_options = {}
if binary:
browser_options["binary"] = binary
if args:
browser_options["args"] = args
if config["overlay_scrollbars"]:
browser_options["useOverlayScrollbars"] = not (binary or args)
options.set_capability(config["options_key"], browser_options)
return options


class WebKitDriver(Driver):
@property
def supported_drivers(self):
return SupportedWebKitDrivers()

@property
def is_platform_valid(self):
return self.exe_platform != "Windows"

@Driver.options.setter
def options(self, cls_name):
self._options = _webkit_options(
cls_name.lower(),
binary=self.browser_path.strip("'") if self.browser_path else None,
args=self.browser_args.split() if self.browser_args else (),
)
if self.is_remote:
self._options.enable_downloads = True

@property
def service(self):
executable = self.driver_path
if executable:
self._service = _WebKitService(executable_path=executable)
return self._service
return None

def _build_local_driver(self, kwargs):
return _WebKitLocalDriver(**kwargs)


def make_driver(driver_class, request):
cls = WebKitDriver if driver_class.lower() in WEBKIT_DRIVERS else Driver
return cls(driver_class, request)
7 changes: 7 additions & 0 deletions py/selenium/webdriver/webkitgtk/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

import warnings
from typing import Any

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
Expand All @@ -25,6 +26,12 @@ class Options(ArgOptions):
KEY = "webkitgtk:browserOptions"

def __init__(self) -> None:
warnings.warn(
"WebKitGTKOptions is deprecated and will be removed in a future release; "
"subclass ArgOptions in your own project if you still need it.",
DeprecationWarning,
stacklevel=2,
)
super().__init__()
self._binary_location = ""
self._overlay_scrollbars_enabled = True
Expand Down
Loading
Loading