Skip to content
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
18 changes: 9 additions & 9 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def stop_driver(self):
driver_to_stop.quit()


@pytest.fixture(scope="function")
@pytest.fixture
def driver(request):
global selenium_driver
driver_class = getattr(request, "param", "Chrome").lower()
Expand Down Expand Up @@ -368,7 +368,7 @@ def ensure_valid_window():
except Exception:
pass

request.addfinalizer(ensure_valid_window)
request.addfinalizer(ensure_valid_window) # noqa: PT021

yield selenium_driver.driver

Expand All @@ -391,7 +391,7 @@ def fin():
selenium_driver.stop_driver()
selenium_driver = None

request.addfinalizer(fin)
request.addfinalizer(fin) # noqa: PT021


def pytest_exception_interact(node, call, report):
Expand Down Expand Up @@ -460,12 +460,12 @@ def edge_service():
return EdgeService


@pytest.fixture(scope="function")
@pytest.fixture
def driver_executable(request):
return request.config.option.executable


@pytest.fixture(scope="function")
@pytest.fixture
def clean_driver(request):
_supported_drivers = SupportedDrivers()
try:
Expand All @@ -492,17 +492,17 @@ def clean_driver(request):
driver_reference = None


@pytest.fixture(scope="function")
@pytest.fixture
def clean_service(request):
driver_class = request.config.option.drivers[0].lower()
selenium_driver = Driver(driver_class, request)
yield selenium_driver.service
return selenium_driver.service


@pytest.fixture(scope="function")
@pytest.fixture
def clean_options(request):
driver_class = request.config.option.drivers[0].lower()
yield Driver.clean_options(driver_class, request)
return Driver.clean_options(driver_class, request)


@pytest.fixture
Expand Down
13 changes: 6 additions & 7 deletions py/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from pathlib import Path
from textwrap import dedent
from textwrap import indent as tw_indent
from typing import Union, cast
from typing import cast

import inflection # type: ignore

Expand All @@ -49,18 +49,18 @@
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules."""

INIT_HEADER = """{}
""".format(SHARED_HEADER)
INIT_HEADER = f"""{SHARED_HEADER}
"""

MODULE_HEADER = """{}
MODULE_HEADER = f"""{SHARED_HEADER}
#
# CDP domain: {{}}{{}}
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
""".format(SHARED_HEADER)
"""

current_version = ""

Expand Down Expand Up @@ -819,8 +819,7 @@ def generate_code(self):
code += import_code
code += "\n\n"
code += "\n"
item_iter_t = Union[CdpEvent, CdpCommand, CdpType]
item_iter: Iterator[item_iter_t] = itertools.chain(
item_iter: Iterator[CdpEvent | CdpCommand | CdpType] = itertools.chain(
iter(self.types),
iter(self.commands),
iter(self.events),
Expand Down
7 changes: 6 additions & 1 deletion py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ respect-gitignore = true
target-version = "py310"

[tool.ruff.lint]
extend-select = ["D", "E4", "E7", "E9", "F", "I", "E501", "RUF022", "TID252"]
extend-select = ["D", "E", "F", "I", "PT", "UP", "RUF", "TID252"]
fixable = ["ALL"]
extend-ignore = [
"D100", # Missing docstring in public module
Expand All @@ -155,6 +155,11 @@ extend-ignore = [
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
"D212", # Multi-line docstring summary should start at the first line
"PT011", # Use of `pytest.raises({exception})` is too broad
"PT012", # `pytest.raises()` block should contain a single simple statement
"RUF005", # Uses of the + operator to concatenate collections
"RUF012", # Mutable default values in class attributes
"RUF059", # Unpacked variable is never used
]

[tool.ruff.format]
Expand Down
27 changes: 0 additions & 27 deletions py/selenium/types.py

This file was deleted.

54 changes: 27 additions & 27 deletions py/selenium/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@
# specific language governing permissions and limitations
# under the License.

from selenium.webdriver.chrome.options import Options as ChromeOptions # noqa
from selenium.webdriver.chrome.service import Service as ChromeService # noqa
from selenium.webdriver.chrome.webdriver import WebDriver as Chrome # noqa
from selenium.webdriver.common.action_chains import ActionChains # noqa
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # noqa
from selenium.webdriver.common.keys import Keys # noqa
from selenium.webdriver.common.proxy import Proxy # noqa
from selenium.webdriver.edge.options import Options as EdgeOptions # noqa
from selenium.webdriver.edge.service import Service as EdgeService # noqa
from selenium.webdriver.edge.webdriver import WebDriver as ChromiumEdge # noqa
from selenium.webdriver.edge.webdriver import WebDriver as Edge # noqa
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile # noqa
from selenium.webdriver.firefox.options import Options as FirefoxOptions # noqa
from selenium.webdriver.firefox.service import Service as FirefoxService # noqa
from selenium.webdriver.firefox.webdriver import WebDriver as Firefox # noqa
from selenium.webdriver.ie.options import Options as IeOptions # noqa
from selenium.webdriver.ie.service import Service as IeService # noqa
from selenium.webdriver.ie.webdriver import WebDriver as Ie # noqa
from selenium.webdriver.remote.webdriver import WebDriver as Remote # noqa
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.webdriver import WebDriver as Chrome
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.edge.webdriver import WebDriver as ChromiumEdge
from selenium.webdriver.edge.webdriver import WebDriver as Edge
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.firefox.webdriver import WebDriver as Firefox
from selenium.webdriver.ie.options import Options as IeOptions
from selenium.webdriver.ie.service import Service as IeService
from selenium.webdriver.ie.webdriver import WebDriver as Ie
from selenium.webdriver.remote.webdriver import WebDriver as Remote
from selenium.webdriver.safari.options import Options as SafariOptions
from selenium.webdriver.safari.service import Service as SafariService # noqa
from selenium.webdriver.safari.webdriver import WebDriver as Safari # noqa
from selenium.webdriver.webkitgtk.options import Options as WebKitGTKOptions # noqa
from selenium.webdriver.webkitgtk.service import Service as WebKitGTKService # noqa
from selenium.webdriver.webkitgtk.webdriver import WebDriver as WebKitGTK # noqa
from selenium.webdriver.wpewebkit.options import Options as WPEWebKitOptions # noqa
from selenium.webdriver.wpewebkit.service import Service as WPEWebKitService # noqa
from selenium.webdriver.wpewebkit.webdriver import WebDriver as WPEWebKit # noqa
from selenium.webdriver.safari.service import Service as SafariService
from selenium.webdriver.safari.webdriver import WebDriver as Safari
from selenium.webdriver.webkitgtk.options import Options as WebKitGTKOptions
from selenium.webdriver.webkitgtk.service import Service as WebKitGTKService
from selenium.webdriver.webkitgtk.webdriver import WebDriver as WebKitGTK
from selenium.webdriver.wpewebkit.options import Options as WPEWebKitOptions
from selenium.webdriver.wpewebkit.service import Service as WPEWebKitService
from selenium.webdriver.wpewebkit.webdriver import WebDriver as WPEWebKit

__version__ = "4.40.0.202512070022"

Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/chrome/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# specific language governing permissions and limitations
# under the License.


from collections.abc import Mapping, Sequence
from typing import IO, Any

from selenium.types import SubprocessStdAlias
from selenium.webdriver.chromium import service


Expand All @@ -43,7 +42,7 @@ def __init__(
executable_path: str | None = None,
port: int = 0,
service_args: Sequence[str] | None = None,
log_output: SubprocessStdAlias | None = None,
log_output: int | str | IO[Any] | None = None,
env: Mapping[str, str] | None = None,
**kwargs,
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/chromium/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from collections.abc import Mapping, Sequence
from io import IOBase
from typing import IO, Any

from selenium.types import SubprocessStdAlias
from selenium.webdriver.common import service


Expand All @@ -44,7 +44,7 @@ def __init__(
executable_path: str | None = None,
port: int = 0,
service_args: Sequence[str] | None = None,
log_output: SubprocessStdAlias | None = None,
log_output: int | str | IO[Any] | None = None,
env: Mapping[str, str] | None = None,
driver_path_env_key: str | None = None,
**kwargs,
Expand Down
11 changes: 7 additions & 4 deletions py/selenium/webdriver/common/action_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING

from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.key_input import KeyInput
Expand All @@ -30,8 +30,6 @@
if TYPE_CHECKING:
from selenium.webdriver.remote.webdriver import WebDriver

AnyDevice = Union[PointerInput, KeyInput, WheelInput]


class ActionChains:
"""Automate low-level interactions like mouse movements, button actions, key presses, and context menus.
Expand Down Expand Up @@ -68,7 +66,12 @@ class ActionChains:
another.
"""

def __init__(self, driver: WebDriver, duration: int = 250, devices: list[AnyDevice] | None = None) -> None:
def __init__(
self,
driver: WebDriver,
duration: int = 250,
devices: list[PointerInput | KeyInput | WheelInput] | None = None,
) -> None:
"""Creates a new ActionChains.

Args:
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/common/bidi/webextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def install(self, path=None, archive_path=None, base64_value=None) -> dict:
except WebDriverException as e:
if "Method not available" in str(e):
raise WebDriverException(
f"{str(e)}. If you are using Chrome or Edge, add '--enable-unsafe-extension-debugging' "
f"{e!s}. If you are using Chrome or Edge, add '--enable-unsafe-extension-debugging' "
"and '--remote-debugging-pipe' arguments or set options.enable_webextensions = True"
) from e
raise
Expand Down
47 changes: 25 additions & 22 deletions py/selenium/webdriver/common/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,36 @@ class Proxy:
socks_version = _ProxyTypeDescriptor("socksVersion", ProxyType.MANUAL)
"""SOCKS proxy version."""

def __init__(self, raw=None):
def __init__(self, raw: dict | None = None):
"""Creates a new Proxy.

Args:
raw: Raw proxy data. If None, default class values are used.
"""
if raw:
if "proxyType" in raw and raw["proxyType"]:
self.proxy_type = ProxyType.load(raw["proxyType"])
if "httpProxy" in raw and raw["httpProxy"]:
self.http_proxy = raw["httpProxy"]
if "noProxy" in raw and raw["noProxy"]:
self.no_proxy = raw["noProxy"]
if "proxyAutoconfigUrl" in raw and raw["proxyAutoconfigUrl"]:
self.proxy_autoconfig_url = raw["proxyAutoconfigUrl"]
if "sslProxy" in raw and raw["sslProxy"]:
self.sslProxy = raw["sslProxy"]
if "autodetect" in raw and raw["autodetect"]:
self.auto_detect = raw["autodetect"]
if "socksProxy" in raw and raw["socksProxy"]:
self.socks_proxy = raw["socksProxy"]
if "socksUsername" in raw and raw["socksUsername"]:
self.socks_username = raw["socksUsername"]
if "socksPassword" in raw and raw["socksPassword"]:
self.socks_password = raw["socksPassword"]
if "socksVersion" in raw and raw["socksVersion"]:
self.socks_version = raw["socksVersion"]
if raw is None:
return
if not isinstance(raw, dict):
raise TypeError(f"`raw` must be a dict, got {type(raw)}")
if raw.get("proxyType"):
self.proxy_type = ProxyType.load(raw["proxyType"])
if raw.get("httpProxy"):
self.http_proxy = raw["httpProxy"]
if raw.get("noProxy"):
self.no_proxy = raw["noProxy"]
if raw.get("proxyAutoconfigUrl"):
self.proxy_autoconfig_url = raw["proxyAutoconfigUrl"]
if raw.get("sslProxy"):
self.sslProxy = raw["sslProxy"]
if raw.get("autodetect"):
self.auto_detect = raw["autodetect"]
if raw.get("socksProxy"):
self.socks_proxy = raw["socksProxy"]
if raw.get("socksUsername"):
self.socks_username = raw["socksUsername"]
if raw.get("socksPassword"):
self.socks_password = raw["socksPassword"]
if raw.get("socksVersion"):
self.socks_version = raw["socksVersion"]

@property
def proxy_type(self):
Expand Down
11 changes: 5 additions & 6 deletions py/selenium/webdriver/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
from io import IOBase
from subprocess import PIPE
from time import sleep
from typing import IO, Any, Optional, Union, cast
from typing import IO, Any, cast
from urllib import request
from urllib.error import URLError

from selenium.common.exceptions import WebDriverException
from selenium.types import SubprocessStdAlias
from selenium.webdriver.common import utils

logger = logging.getLogger(__name__)
Expand All @@ -54,7 +53,7 @@ def __init__(
self,
executable_path: str | None = None,
port: int = 0,
log_output: SubprocessStdAlias | None = None,
log_output: int | str | IO[Any] | None = None,
env: Mapping[Any, Any] | None = None,
driver_path_env_key: str | None = None,
**kwargs,
Expand All @@ -67,7 +66,7 @@ def __init__(
elif log_output is None or log_output == subprocess.DEVNULL:
self.log_output = subprocess.DEVNULL
else:
self.log_output = cast(Union[int, IOBase], log_output)
self.log_output = cast(int | IOBase, log_output)

self.port = port or utils.free_port()
# Default value for every python subprocess: subprocess.Popen(..., creationflags=0)
Expand Down Expand Up @@ -221,8 +220,8 @@ def _start_process(self, path: str) -> None:
cmd,
env=self.env,
close_fds=close_file_descriptors,
stdout=cast(Optional[Union[int, IO[Any]]], self.log_output),
stderr=cast(Optional[Union[int, IO[Any]]], self.log_output),
stdout=cast(int | IO[Any] | None, self.log_output),
stderr=cast(int | IO[Any] | None, self.log_output),
stdin=PIPE,
creationflags=self.creation_flags,
startupinfo=start_info,
Expand Down
Loading