diff --git a/py/selenium/webdriver/common/bidi/storage.py b/py/selenium/webdriver/common/bidi/storage.py index 620477aeae6da..4404baca7a66a 100644 --- a/py/selenium/webdriver/common/bidi/storage.py +++ b/py/selenium/webdriver/common/bidi/storage.py @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -from typing import Optional, Union +from typing import Any, Optional, Union from selenium.webdriver.common.bidi.common import command_builder @@ -85,12 +85,19 @@ def from_dict(cls, data: dict) -> "Cookie": ------- Cookie: A new instance of Cookie. """ - value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) + # Validation for empty strings + name = data.get("name") + if not name: + raise ValueError("name is required and cannot be empty") + domain = data.get("domain") + if not domain: + raise ValueError("domain is required and cannot be empty") + value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) return cls( - name=data.get("name"), + name=str(name), value=value, - domain=data.get("domain"), + domain=str(domain), path=data.get("path"), size=data.get("size"), http_only=data.get("httpOnly"), @@ -125,14 +132,14 @@ def __init__( self.same_site = same_site self.expiry = expiry - def to_dict(self) -> dict: + def to_dict(self) -> dict[str, Any]: """Converts the CookieFilter to a dictionary. Returns: ------- Dict: A dictionary representation of the CookieFilter. """ - result = {} + result: dict[str, Any] = {} if self.name is not None: result["name"] = self.name if self.value is not None: @@ -242,14 +249,14 @@ def __init__( self.same_site = same_site self.expiry = expiry - def to_dict(self) -> dict: + def to_dict(self) -> dict[str, Any]: """Converts the PartialCookie to a dictionary. Returns: ------- Dict: A dictionary representation of the PartialCookie. """ - result = { + result: dict[str, Any] = { "name": self.name, "value": self.value.to_dict(), "domain": self.domain, diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index 67e5765645133..fc76c6fd832fc 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -422,7 +422,7 @@ def __init__(self) -> None: self._caps = self.default_capabilities self._proxy = None self.set_capability("pageLoadStrategy", PageLoadStrategy.normal) - self.mobile_options = None + self.mobile_options: Optional[dict[str, str]] = None self._ignore_local_proxy = False @property diff --git a/py/selenium/webdriver/common/virtual_authenticator.py b/py/selenium/webdriver/common/virtual_authenticator.py index a434de83741df..19b0ec615e7c5 100644 --- a/py/selenium/webdriver/common/virtual_authenticator.py +++ b/py/selenium/webdriver/common/virtual_authenticator.py @@ -24,17 +24,17 @@ class Protocol(str, Enum): """Protocol to communicate with the authenticator.""" - CTAP2: str = "ctap2" - U2F: str = "ctap1/u2f" + CTAP2 = "ctap2" + U2F = "ctap1/u2f" class Transport(str, Enum): """Transport method to communicate with the authenticator.""" - BLE: str = "ble" - USB: str = "usb" - NFC: str = "nfc" - INTERNAL: str = "internal" + BLE = "ble" + USB = "usb" + NFC = "nfc" + INTERNAL = "internal" class VirtualAuthenticatorOptions: