diff --git a/py/selenium/webdriver/common/bidi/browser.py b/py/selenium/webdriver/common/bidi/browser.py index 73884ec08f0b7..a1ed8e912e85d 100644 --- a/py/selenium/webdriver/common/bidi/browser.py +++ b/py/selenium/webdriver/common/bidi/browser.py @@ -16,6 +16,7 @@ # under the License. +import warnings from typing import Any, Optional from selenium.webdriver.common.bidi.common import command_builder @@ -62,8 +63,31 @@ def get_state(self) -> str: ------- str: The state of the client window (one of the ClientWindowState constants). """ + warnings.warn("get_state method is deprecated, use `state` property instead", DeprecationWarning, stacklevel=2) return self.state + @property + def state(self) -> str: + """Gets the state of the client window. + + Returns: + ------- + str: The state of the client window (one of the ClientWindowState constants). + """ + return self._state + + @state.setter + def state(self, value) -> None: + """Sets the state of the client window. + + Returns: None + """ + if not isinstance(value, str): + raise ValueError("state must be a string") + if value not in ClientWindowState.VALID_STATES: + raise ValueError(f"Invalid state: {value}. Must be one of {ClientWindowState.VALID_STATES}") + self._state = value + def get_client_window(self) -> str: """Gets the client window identifier. @@ -71,8 +95,33 @@ def get_client_window(self) -> str: ------- str: The client window identifier. """ + warnings.warn( + "get_client_window method is deprecated, use `client_window` property instead", + DeprecationWarning, + stacklevel=2, + ) return self.client_window + @property + def client_window(self) -> str: + """Gets the client window identifier. + + Returns: + ------- + str: The client window identifier. + """ + return self._client_window + + @client_window.setter + def client_window(self, value) -> None: + """Sets the client window identifier. + + Returns: None + """ + if not isinstance(value, str): + raise ValueError("clientWindow must be a string") + self._client_window = value + def get_width(self) -> int: """Gets the width of the client window. @@ -80,8 +129,29 @@ def get_width(self) -> int: ------- int: The width of the client window. """ + warnings.warn("get_width method is deprecated, use `width` property instead", DeprecationWarning, stacklevel=2) return self.width + @property + def width(self) -> int: + """Gets the width of the client window. + + Returns: + ------- + int: The width of the client window. + """ + return self._width + + @width.setter + def width(self, value) -> None: + """Sets the width of the client window. + + Returns: None + """ + if not isinstance(value, int) or value < 0: + raise ValueError(f"width must be a non-negative integer, got {value}") + self._width = value + def get_height(self) -> int: """Gets the height of the client window. @@ -89,8 +159,31 @@ def get_height(self) -> int: ------- int: The height of the client window. """ + warnings.warn( + "get_height method is deprecated, use `height` property instead", DeprecationWarning, stacklevel=2 + ) return self.height + @property + def height(self) -> int: + """Gets the height of the client window. + + Returns: + ------- + int: The height of the client window. + """ + return self._height + + @height.setter + def height(self, value) -> None: + """Sets the height of the client window. + + Returns: None + """ + if not isinstance(value, int) or value < 0: + raise ValueError(f"height must be a non-negative integer, got {value}") + self._height = value + def get_x(self) -> int: """Gets the x coordinate of the client window. @@ -98,8 +191,29 @@ def get_x(self) -> int: ------- int: The x coordinate of the client window. """ + warnings.warn("get_x method is deprecated, use `x` property instead", DeprecationWarning, stacklevel=2) return self.x + @property + def x(self) -> int: + """Gets the x coordinate of the client window. + + Returns: + ------- + int: The x coordinate of the client window. + """ + return self._x + + @x.setter + def x(self, value) -> None: + """Sets the x coordinate of the client window. + + Returns: None + """ + if not isinstance(value, int): + raise ValueError(f"x must be an integer, got {type(value).__name__}") + self._x = value + def get_y(self) -> int: """Gets the y coordinate of the client window. @@ -107,8 +221,49 @@ def get_y(self) -> int: ------- int: The y coordinate of the client window. """ + warnings.warn("get_y method is deprecated, use `y` property instead", DeprecationWarning, stacklevel=2) return self.y + @property + def y(self) -> int: + """Gets the y coordinate of the client window. + + Returns: + ------- + int: The y coordinate of the client window. + """ + return self._y + + @y.setter + def y(self, value) -> None: + """Sets the y coordinate of the client window. + + Returns: None + """ + if not isinstance(value, int): + raise ValueError(f"y must be an integer, got {type(value).__name__}") + self._y = value + + @property + def active(self) -> bool: + """Gets the Window Status. + + Returns: + ------- + bool: The boolen value of Window Status + """ + return self._active + + @active.setter + def active(self, value) -> None: + """Sets the Window Status. + + Returns: None + """ + if not isinstance(value, bool): + raise ValueError("active must be a boolean") + self._active = value + def is_active(self) -> bool: """Checks if the client window is active. @@ -116,6 +271,7 @@ def is_active(self) -> bool: ------- bool: True if the client window is active, False otherwise. """ + warnings.warn("is_active method is deprecated, use `active` property instead", DeprecationWarning, stacklevel=2) return self.active @classmethod @@ -129,59 +285,20 @@ def from_dict(cls, data: dict) -> "ClientWindowInfo": Returns: ------- ClientWindowInfo: A new instance of ClientWindowInfo. - - Raises: - ------ - ValueError: If required fields are missing or have invalid types. """ - try: - client_window = data["clientWindow"] - if not isinstance(client_window, str): - raise ValueError("clientWindow must be a string") - - state = data["state"] - if not isinstance(state, str): - raise ValueError("state must be a string") - if state not in ClientWindowState.VALID_STATES: - raise ValueError(f"Invalid state: {state}. Must be one of {ClientWindowState.VALID_STATES}") - - width = data["width"] - if not isinstance(width, int) or width < 0: - raise ValueError(f"width must be a non-negative integer, got {width}") - - height = data["height"] - if not isinstance(height, int) or height < 0: - raise ValueError(f"height must be a non-negative integer, got {height}") - - x = data["x"] - if not isinstance(x, int): - raise ValueError(f"x must be an integer, got {type(x).__name__}") - - y = data["y"] - if not isinstance(y, int): - raise ValueError(f"y must be an integer, got {type(y).__name__}") - - active = data["active"] - if not isinstance(active, bool): - raise ValueError("active must be a boolean") - - return cls( - client_window=client_window, - state=state, - width=width, - height=height, - x=x, - y=y, - active=active, - ) - except (KeyError, TypeError) as e: - raise ValueError(f"Invalid data format for ClientWindowInfo: {e}") + return cls( + client_window=data["clientWindow"], + state=data["state"], + width=data["width"], + height=data["height"], + x=data["x"], + y=data["y"], + active=data["active"], + ) class Browser: - """ - BiDi implementation of the browser module. - """ + """BiDi implementation of the browser module.""" def __init__(self, conn): self.conn = conn diff --git a/py/test/selenium/webdriver/common/bidi_browser_tests.py b/py/test/selenium/webdriver/common/bidi_browser_tests.py index 74b406b54c22e..2469bec062b95 100644 --- a/py/test/selenium/webdriver/common/bidi_browser_tests.py +++ b/py/test/selenium/webdriver/common/bidi_browser_tests.py @@ -99,14 +99,14 @@ def test_get_client_windows(driver): window_info = client_windows[0] assert isinstance(window_info, ClientWindowInfo) - assert window_info.get_client_window() is not None - assert window_info.get_state() is not None - assert isinstance(window_info.get_state(), str) - assert window_info.get_width() > 0 - assert window_info.get_height() > 0 - assert isinstance(window_info.is_active(), bool) - assert window_info.get_x() >= 0 - assert window_info.get_y() >= 0 + assert window_info.client_window is not None + assert window_info.state is not None + assert isinstance(window_info.state, str) + assert window_info.width > 0 + assert window_info.height > 0 + assert isinstance(window_info.active, bool) + assert window_info.x >= 0 + assert window_info.y >= 0 def test_raises_exception_when_removing_default_user_context(driver):