From 1f3c4f3f09cfe361e8dfae4fc81e60d129d0983b Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Sat, 1 Nov 2025 00:01:15 +0700 Subject: [PATCH 01/10] Refactor docstrings in remote connection tests for clarity and formatting --- .../webdriver/remote/remote_connection_tests.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/py/test/selenium/webdriver/remote/remote_connection_tests.py b/py/test/selenium/webdriver/remote/remote_connection_tests.py index 6e313ce2e58b8..afef229ab3996 100644 --- a/py/test/selenium/webdriver/remote/remote_connection_tests.py +++ b/py/test/selenium/webdriver/remote/remote_connection_tests.py @@ -39,9 +39,10 @@ def test_browser_specific_method(firefox_options, webserver): def test_remote_webdriver_with_http_timeout(chromium_options, webserver): - """This test starts a remote webdriver with an http client timeout - set less than the implicit wait timeout, and verifies the http timeout - is triggered first when waiting for an element. + """This test starts a remote webdriver with an http client timeout. + + It verifies the http timeout is triggered first when waiting for an element, + with the timeout set less than the implicit wait timeout. """ http_timeout = 4 wait_timeout = 6 @@ -56,9 +57,9 @@ def test_remote_webdriver_with_http_timeout(chromium_options, webserver): def test_remote_webdriver_with_websocket_timeout(chromium_options, webserver): - """This test starts a remote webdriver that uses websockets, and has a websocket - client timeout less than the default. It verifies the websocket times out according - to this value. + """This test starts a remote webdriver that uses websockets, and has a websocket client timeout. + + It verifies the websocket times out according to this value. """ websocket_timeout = 2.0 websocket_interval = 1.0 From c7a7de58c11c5866c6ba0a813e91453799503de4 Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Sat, 1 Nov 2025 00:18:55 +0700 Subject: [PATCH 02/10] Refactor docstrings for clarity and conciseness across multiple files --- py/selenium/webdriver/wpewebkit/options.py | 10 +++------- py/selenium/webdriver/wpewebkit/service.py | 3 +-- py/selenium/webdriver/wpewebkit/webdriver.py | 4 +--- .../selenium/webdriver/common/interactions_tests.py | 4 +--- .../webdriver/common/interactions_with_device_tests.py | 4 +--- py/test/selenium/webdriver/common/page_loader.py | 8 ++++---- .../selenium/webdriver/common/webdriverwait_tests.py | 6 ++++-- py/test/selenium/webdriver/common/webserver.py | 1 + 8 files changed, 16 insertions(+), 24 deletions(-) diff --git a/py/selenium/webdriver/wpewebkit/options.py b/py/selenium/webdriver/wpewebkit/options.py index ff365791d0bcd..a67bab7fbf87a 100644 --- a/py/selenium/webdriver/wpewebkit/options.py +++ b/py/selenium/webdriver/wpewebkit/options.py @@ -29,9 +29,7 @@ def __init__(self) -> None: @property def binary_location(self) -> str: - """Returns the location of the browser binary otherwise an empty - string. - """ + """Return the location of the browser binary or an empty string.""" return self._binary_location @binary_location.setter @@ -45,10 +43,8 @@ def binary_location(self, value: str) -> None: raise TypeError(self.BINARY_LOCATION_ERROR) self._binary_location = value - def to_capabilities(self): - """Creates a capabilities with all the options that have been set and - returns a dictionary with everything. - """ + def to_capabilities(self) -> dict: + """Create a capabilities dictionary with all set options.""" caps = self._caps browser_options = {} diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index 928eca35756f7..c94287a005ec8 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/service.py @@ -25,8 +25,7 @@ class Service(service.Service): - """A Service class that is responsible for the starting and stopping of - `WPEWebDriver`. + """A Service class that is responsible for the starting and stopping of `WPEWebDriver`. Args: executable_path: Install path of the WPEWebDriver executable, defaults diff --git a/py/selenium/webdriver/wpewebkit/webdriver.py b/py/selenium/webdriver/wpewebkit/webdriver.py index 6700727effbfb..ef5cf28dd7e5b 100644 --- a/py/selenium/webdriver/wpewebkit/webdriver.py +++ b/py/selenium/webdriver/wpewebkit/webdriver.py @@ -49,9 +49,7 @@ def __init__( self._is_remote = False def quit(self): - """Closes the browser and shuts down the WPEWebKitDriver executable - that is started when starting the WPEWebKitDriver. - """ + """Close the browser and shut down the WPEWebKit driver executable.""" try: super().quit() except http_client.BadStatusLine: diff --git a/py/test/selenium/webdriver/common/interactions_tests.py b/py/test/selenium/webdriver/common/interactions_tests.py index 53d58af030d47..857acc6cedb0f 100644 --- a/py/test/selenium/webdriver/common/interactions_tests.py +++ b/py/test/selenium/webdriver/common/interactions_tests.py @@ -209,9 +209,7 @@ def test_sending_keys_to_element(driver, pages): def test_can_send_keys_between_clicks(driver, pages): - """For W3C, ensures that the correct number of pauses are given to the other - input device. - """ + """Ensure W3C sends correct pause count to other input devices.""" pages.load("javascriptPage.html") keyup = driver.find_element(By.ID, "keyUp") keydown = driver.find_element(By.ID, "keyDown") diff --git a/py/test/selenium/webdriver/common/interactions_with_device_tests.py b/py/test/selenium/webdriver/common/interactions_with_device_tests.py index 97637294403ca..514134eccb293 100644 --- a/py/test/selenium/webdriver/common/interactions_with_device_tests.py +++ b/py/test/selenium/webdriver/common/interactions_with_device_tests.py @@ -194,9 +194,7 @@ def test_sending_keys_to_element_with_keyboard(driver, pages): def test_can_send_keys_between_clicks_with_keyboard(driver, pages): - """For W3C, ensures that the correct number of pauses are given to the other - input device. - """ + """Ensure W3C sends correct pause count to other input devices.""" pages.load("javascriptPage.html") keyup = driver.find_element(By.ID, "keyUp") keydown = driver.find_element(By.ID, "keyDown") diff --git a/py/test/selenium/webdriver/common/page_loader.py b/py/test/selenium/webdriver/common/page_loader.py index f14cd166fff73..7c5d11c973dab 100644 --- a/py/test/selenium/webdriver/common/page_loader.py +++ b/py/test/selenium/webdriver/common/page_loader.py @@ -15,10 +15,10 @@ # specific language governing permissions and limitations # under the License. -"""This module contains some decorators that can be used to support -the page models. For example for an action that needs a page to be fully -loaded, the @require_loaded decorator will make sure the page is loaded -before the call is invoked. +"""This module contains some decorators that can be used to support the page models. + +For example for an action that needs a page to be fully loaded, the @require_loaded +decorator will make sure the page is loaded before the call is invoked. This pattern is also useful for waiting for certain asynchronous events to happen before executing certain actions. """ diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index bb254871a0382..99cd3b3af6565 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -364,8 +364,10 @@ def test_expected_condition_attribute_to_be_include_in_element(driver, pages): def test_driver_with_http_timeout(driver, pages): - """This test starts a webdriver with an http client timeout set less than the implicit - wait, and verifies the http timeout is triggered first when waiting for an element. + """This test starts a webdriver with an http client timeout. + + It verifies the http timeout is triggered first when waiting for an element, + with the timeout set less than the implicit wait. """ pages.load("simpleTest.html") driver.command_executor.client_config.timeout = 6 diff --git a/py/test/selenium/webdriver/common/webserver.py b/py/test/selenium/webdriver/common/webserver.py index 8969e759f16f7..2437eee8fef09 100644 --- a/py/test/selenium/webdriver/common/webserver.py +++ b/py/test/selenium/webdriver/common/webserver.py @@ -16,6 +16,7 @@ # under the License. """A simple web server for testing purpose. + It serves the testing html pages that are needed by the webdriver unit tests. """ From 62c5aa1d3304f099b9527a82ac93dc341a391457 Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Sat, 1 Nov 2025 01:13:22 +0700 Subject: [PATCH 03/10] Refactor docstrings for clarity and conciseness in multiple files --- .../webdriver/support/expected_conditions.py | 72 ++++++------------- .../webdriver/support/relative_locator.py | 13 ++-- py/selenium/webdriver/support/select.py | 20 +++--- py/selenium/webdriver/webkitgtk/options.py | 18 ++--- py/selenium/webdriver/webkitgtk/service.py | 3 +- py/selenium/webdriver/webkitgtk/webdriver.py | 4 +- 6 files changed, 42 insertions(+), 88 deletions(-) diff --git a/py/selenium/webdriver/support/expected_conditions.py b/py/selenium/webdriver/support/expected_conditions.py index 2dd80ba8b7d8e..055e136f72525 100644 --- a/py/selenium/webdriver/support/expected_conditions.py +++ b/py/selenium/webdriver/support/expected_conditions.py @@ -74,8 +74,7 @@ def _predicate(driver: WebDriver): def presence_of_element_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], WebElement]: - """An expectation for checking that an element is present on the DOM of a - page. This does not necessarily mean that the element is visible. + """Check that an element is present on the DOM (not necessarily visible). Args: locator: Used to find the element. @@ -97,8 +96,7 @@ def _predicate(driver: WebDriverOrWebElement): def url_contains(url: str) -> Callable[[WebDriver], bool]: - """An expectation for checking that the current url contains a case- - sensitive substring. + """Check that the current url contains a case-sensitive substring. Args: url: The fragment of url expected. @@ -149,8 +147,7 @@ def _predicate(driver: WebDriver): def url_changes(url: str) -> Callable[[WebDriver], bool]: - """An expectation for checking the current url is different than a given - string. + """Check that the current url differs from a given string. Args: url: The expected url, which must not be an exact match. @@ -168,9 +165,7 @@ def _predicate(driver: WebDriver): def visibility_of_element_located( locator: tuple[str, str], ) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]: - """An expectation for checking that an element is present on the DOM of a - page and visible. Visibility means that the element is not only displayed - but also has a height and width that is greater than 0. + """Check that an element is present on the DOM and visible (has size). Args: locator: Used to find the element. @@ -195,11 +190,7 @@ def _predicate(driver: WebDriverOrWebElement): def visibility_of(element: WebElement) -> Callable[[Any], Union[Literal[False], WebElement]]: - """An expectation for checking that an element, known to be present on the - DOM of a page, is visible. - - Visibility means that the element is not only displayed but also has - a height and width that is greater than 0. + """Check that an element is visible (present on DOM and has size). Args: element: The WebElement to check. @@ -221,8 +212,7 @@ def _predicate(_): def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[Literal[False], WebElement]: - """An expectation for checking that an element, known to be present on the - DOM of a page, is of the expected visibility. + """Check if an element has the expected visibility state. Args: element: The WebElement to check. @@ -235,8 +225,7 @@ def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[L def presence_of_all_elements_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], list[WebElement]]: - """An expectation for checking that there is at least one element present - on a web page. + """Check that all elements matching the locator are present on the DOM. Args: locator: Used to find the element. @@ -258,8 +247,7 @@ def _predicate(driver: WebDriverOrWebElement): def visibility_of_any_elements_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], list[WebElement]]: - """An expectation for checking that there is at least one element visible - on a web page. + """Check that at least one element is visible on the web page. Args: locator: Used to find the element. @@ -283,9 +271,7 @@ def _predicate(driver: WebDriverOrWebElement): def visibility_of_all_elements_located( locator: tuple[str, str], ) -> Callable[[WebDriverOrWebElement], Union[list[WebElement], Literal[False]]]: - """An expectation for checking that all elements are present on the DOM of - a page and visible. Visibility means that the elements are not only - displayed but also has a height and width that is greater than 0. + """Check that all elements are present on the DOM and visible (have size). Args: locator: Used to find the elements. @@ -314,8 +300,7 @@ def _predicate(driver: WebDriverOrWebElement): def text_to_be_present_in_element(locator: tuple[str, str], text_: str) -> Callable[[WebDriverOrWebElement], bool]: - """An expectation for checking if the given text is present in the - specified element. + """Check that the given text is present in the specified element. Args: locator: Used to find the element. @@ -346,8 +331,7 @@ def _predicate(driver: WebDriverOrWebElement): def text_to_be_present_in_element_value( locator: tuple[str, str], text_: str ) -> Callable[[WebDriverOrWebElement], bool]: - """An expectation for checking if the given text is present in the - element's value. + """Check that the given text is present in the element's value. Args: locator: Used to find the element. @@ -380,8 +364,7 @@ def _predicate(driver: WebDriverOrWebElement): def text_to_be_present_in_element_attribute( locator: tuple[str, str], attribute_: str, text_: str ) -> Callable[[WebDriverOrWebElement], bool]: - """An expectation for checking if the given text is present in the - element's attribute. + """Check that the given text is present in the element's attribute. Args: locator: Used to find the element. @@ -415,11 +398,7 @@ def _predicate(driver: WebDriverOrWebElement): def frame_to_be_available_and_switch_to_it( locator: Union[tuple[str, str], str, WebElement], ) -> Callable[[WebDriver], bool]: - """An expectation for checking whether the given frame is available to - switch to. - - If the frame is available it switches the given driver to the - specified frame. + """Check that the given frame is available and switch to it. Args: locator: Used to find the frame. @@ -449,8 +428,7 @@ def _predicate(driver: WebDriver): def invisibility_of_element_located( locator: Union[WebElement, tuple[str, str]], ) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]: - """An Expectation for checking that an element is either invisible or not - present on the DOM. + """Check that an element is either invisible or not present on the DOM. Args: locator: Used to find the element. @@ -492,8 +470,7 @@ def _predicate(driver: WebDriverOrWebElement): def invisibility_of_element( element: Union[WebElement, tuple[str, str]], ) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]: - """An Expectation for checking that an element is either invisible or not - present on the DOM. + """Check that an element is either invisible or not present on the DOM. Args: element: Used to find the element. @@ -515,8 +492,7 @@ def invisibility_of_element( def element_to_be_clickable( mark: Union[WebElement, tuple[str, str]], ) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]: - """An Expectation for checking an element is visible and enabled such that - you can click it. + """Check that an element is visible and enabled so it can be clicked. Args: mark: Used to find the element. @@ -646,8 +622,7 @@ def _predicate(_): def element_located_selection_state_to_be( locator: tuple[str, str], is_selected: bool ) -> Callable[[WebDriverOrWebElement], bool]: - """An expectation to locate an element and check if the selection state - specified is in that state. + """Check that an element's selection state matches the expected state. Args: locator: Used to find the element. @@ -696,9 +671,8 @@ def _predicate(driver: WebDriver): return _predicate -def new_window_is_opened(current_handles: list[str]) -> Callable[[WebDriver], bool]: - """An expectation that a new window will be opened and have the number of - windows handles increase. +def new_window_is_opened(current_handles: set[str]) -> Callable[[WebDriver], bool]: + """Check that a new window has been opened (window handles count increased). Args: current_handles: The current window handles. @@ -719,9 +693,8 @@ def _predicate(driver: WebDriver): return _predicate -def alert_is_present() -> Callable[[WebDriver], Union[Alert, Literal[False]]]: - """An expectation for checking if an alert is currently present and - switching to it. +def alert_is_present() -> Callable[[WebDriver], Union[Alert, bool]]: + """Check that an alert is present and switch to it. Returns: The Alert once it is located. @@ -745,8 +718,7 @@ def _predicate(driver: WebDriver): def element_attribute_to_include(locator: tuple[str, str], attribute_: str) -> Callable[[WebDriverOrWebElement], bool]: - """An expectation for checking if the given attribute is included in the - specified element. + """Check if the given attribute is included in the specified element. Args: locator: Used to find the element. diff --git a/py/selenium/webdriver/support/relative_locator.py b/py/selenium/webdriver/support/relative_locator.py index 7f6e6717e9f6e..3863cb3010ae9 100644 --- a/py/selenium/webdriver/support/relative_locator.py +++ b/py/selenium/webdriver/support/relative_locator.py @@ -64,9 +64,9 @@ def locate_with(by: ByType, using: str) -> "RelativeBy": class RelativeBy: - """Gives the opportunity to find elements based on their relative location - on the page from a root element. It is recommended that you use the helper - function to create it. + """Find elements based on their relative location from a root element. + + It is recommended that you use the helper function to create instances. Example: -------- @@ -80,8 +80,7 @@ class RelativeBy: LocatorType = dict[ByType, str] def __init__(self, root: Optional[dict[ByType, str]] = None, filters: Optional[list] = None): - """Creates a new RelativeBy object. It is preferred if you use the - `locate_with` method as this signature could change. + """Create a RelativeBy object (prefer using `locate_with` instead). Args: root: A dict with `By` enum as the key and the search query as the value @@ -309,9 +308,7 @@ def near(self, element_or_locator: Union[WebElement, LocatorType, None] = None, return self def to_dict(self) -> dict: - """Create a dict that will be passed to the driver to start searching - for the element. - """ + """Create a dict to be passed to the driver for element searching.""" return { "relative": { "root": self.root, diff --git a/py/selenium/webdriver/support/select.py b/py/selenium/webdriver/support/select.py index dde724b954350..52f905ce91a46 100644 --- a/py/selenium/webdriver/support/select.py +++ b/py/selenium/webdriver/support/select.py @@ -23,8 +23,7 @@ class Select: def __init__(self, webelement: WebElement) -> None: - """Constructor. A check is made that the given element is, indeed, a - SELECT tag. If it is not, then an UnexpectedTagNameException is thrown. + """Constructor. A check is made that the given element is a SELECT tag. Args: webelement: SELECT element to wrap @@ -32,6 +31,9 @@ def __init__(self, webelement: WebElement) -> None: Example: from selenium.webdriver.support.ui import Select Select(driver.find_element(By.TAG_NAME, "select")).select_by_index(2) + + Raises: + UnexpectedTagNameException: If the element is not a SELECT tag """ if webelement.tag_name.lower() != "select": raise UnexpectedTagNameException(f"Select only works on