From 75a0efa680aa91ccebaf74902e309c1125fc34fd Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Tue, 29 Oct 2024 15:11:39 -0400 Subject: [PATCH 1/5] [py] Add DetachedShadowRoot Exception --- py/selenium/common/__init__.py | 2 ++ py/selenium/common/exceptions.py | 3 +++ py/selenium/webdriver/remote/errorhandler.py | 3 +++ .../unit/selenium/webdriver/remote/error_handler_tests.py | 6 +++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/py/selenium/common/__init__.py b/py/selenium/common/__init__.py index 2ef6204d37070..fed0a47f55cfb 100644 --- a/py/selenium/common/__init__.py +++ b/py/selenium/common/__init__.py @@ -48,6 +48,7 @@ from .exceptions import UnexpectedTagNameException from .exceptions import UnknownMethodException from .exceptions import WebDriverException +from .exceptions import DetachedShadowRootException __all__ = [ "WebDriverException", @@ -83,4 +84,5 @@ "InvalidSessionIdException", "SessionNotCreatedException", "UnknownMethodException", + "DetachedShadowRootException" ] diff --git a/py/selenium/common/exceptions.py b/py/selenium/common/exceptions.py index 931eb307f809f..10408613636ff 100644 --- a/py/selenium/common/exceptions.py +++ b/py/selenium/common/exceptions.py @@ -285,3 +285,6 @@ def __init__( with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}/driver_location" super().__init__(with_support, screen, stacktrace) + +class DetachedShadowRootException(WebDriverException): + """Raised when referenced shadow root is no longer attached to the DOM""" \ No newline at end of file diff --git a/py/selenium/webdriver/remote/errorhandler.py b/py/selenium/webdriver/remote/errorhandler.py index e9b30fe51dd3f..e1398eba6927a 100644 --- a/py/selenium/webdriver/remote/errorhandler.py +++ b/py/selenium/webdriver/remote/errorhandler.py @@ -23,6 +23,7 @@ from selenium.common.exceptions import ElementNotInteractableException from selenium.common.exceptions import ElementNotSelectableException from selenium.common.exceptions import ElementNotVisibleException +from selenium.common.exceptions import DetachedShadowRootException from selenium.common.exceptions import ImeActivationFailedException from selenium.common.exceptions import ImeNotAvailableException from selenium.common.exceptions import InsecureCertificateException @@ -88,6 +89,7 @@ class ExceptionMapping: UNABLE_TO_CAPTURE_SCREEN = ScreenshotException ELEMENT_CLICK_INTERCEPTED = ElementClickInterceptedException UNKNOWN_METHOD = UnknownMethodException + DETACHED_SHADOW_ROOT = DetachedShadowRootException class ErrorCode: @@ -131,6 +133,7 @@ class ErrorCode: UNABLE_TO_CAPTURE_SCREEN = [63, "unable to capture screen"] ELEMENT_CLICK_INTERCEPTED = [64, "element click intercepted"] UNKNOWN_METHOD = ["unknown method exception"] + DETACHED_SHADOW_ROOT = [65,"detached shadow root"] METHOD_NOT_ALLOWED = [405, "unsupported operation"] diff --git a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py index 809d64193387a..4158509843276 100644 --- a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py +++ b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py @@ -240,7 +240,11 @@ def test_raises_exception_for_unknown_method(handler, code): def test_raises_exception_for_method_not_allowed(handler, code): with pytest.raises(exceptions.WebDriverException): handler.check_response({"status": code, "value": "foo"}) - + +@pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT) +def test_raises_exception_for_invalid_selector(handler, code): + with pytest.raises(exceptions.DetachedShadowRootException): + handler.check_response({"status": code, "value": "foo"}) @pytest.mark.parametrize("key", ["stackTrace", "stacktrace"]) def test_relays_exception_stacktrace(handler, key): From 48abb1819d3531120fe9856ef1fbe9bfd5151879 Mon Sep 17 00:00:00 2001 From: Simon Benzer <69980130+shbenzer@users.noreply.github.com> Date: Fri, 1 Nov 2024 09:43:42 -0400 Subject: [PATCH 2/5] added new line --- py/selenium/common/exceptions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/py/selenium/common/exceptions.py b/py/selenium/common/exceptions.py index 10408613636ff..c2818ae30a30a 100644 --- a/py/selenium/common/exceptions.py +++ b/py/selenium/common/exceptions.py @@ -287,4 +287,5 @@ def __init__( super().__init__(with_support, screen, stacktrace) class DetachedShadowRootException(WebDriverException): - """Raised when referenced shadow root is no longer attached to the DOM""" \ No newline at end of file + """Raised when referenced shadow root is no longer attached to the DOM""" + From 9c79ce34c7ce05ef85635396afe6d82bcbebc2bd Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Fri, 1 Nov 2024 09:49:39 -0400 Subject: [PATCH 3/5] ran scripts/format.sh --- py/selenium/common/__init__.py | 4 ++-- py/selenium/common/exceptions.py | 2 +- py/selenium/webdriver/remote/errorhandler.py | 4 ++-- py/test/unit/selenium/webdriver/remote/error_handler_tests.py | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/py/selenium/common/__init__.py b/py/selenium/common/__init__.py index fed0a47f55cfb..88269940125d9 100644 --- a/py/selenium/common/__init__.py +++ b/py/selenium/common/__init__.py @@ -15,6 +15,7 @@ # specific language governing permissions and limitations # under the License. +from .exceptions import DetachedShadowRootException from .exceptions import ElementClickInterceptedException from .exceptions import ElementNotInteractableException from .exceptions import ElementNotSelectableException @@ -48,7 +49,6 @@ from .exceptions import UnexpectedTagNameException from .exceptions import UnknownMethodException from .exceptions import WebDriverException -from .exceptions import DetachedShadowRootException __all__ = [ "WebDriverException", @@ -84,5 +84,5 @@ "InvalidSessionIdException", "SessionNotCreatedException", "UnknownMethodException", - "DetachedShadowRootException" + "DetachedShadowRootException", ] diff --git a/py/selenium/common/exceptions.py b/py/selenium/common/exceptions.py index c2818ae30a30a..702cdf7ecc0fc 100644 --- a/py/selenium/common/exceptions.py +++ b/py/selenium/common/exceptions.py @@ -286,6 +286,6 @@ def __init__( super().__init__(with_support, screen, stacktrace) + class DetachedShadowRootException(WebDriverException): """Raised when referenced shadow root is no longer attached to the DOM""" - diff --git a/py/selenium/webdriver/remote/errorhandler.py b/py/selenium/webdriver/remote/errorhandler.py index e1398eba6927a..d2df3b1b8e241 100644 --- a/py/selenium/webdriver/remote/errorhandler.py +++ b/py/selenium/webdriver/remote/errorhandler.py @@ -19,11 +19,11 @@ from typing import Dict from typing import Type +from selenium.common.exceptions import DetachedShadowRootException from selenium.common.exceptions import ElementClickInterceptedException from selenium.common.exceptions import ElementNotInteractableException from selenium.common.exceptions import ElementNotSelectableException from selenium.common.exceptions import ElementNotVisibleException -from selenium.common.exceptions import DetachedShadowRootException from selenium.common.exceptions import ImeActivationFailedException from selenium.common.exceptions import ImeNotAvailableException from selenium.common.exceptions import InsecureCertificateException @@ -133,7 +133,7 @@ class ErrorCode: UNABLE_TO_CAPTURE_SCREEN = [63, "unable to capture screen"] ELEMENT_CLICK_INTERCEPTED = [64, "element click intercepted"] UNKNOWN_METHOD = ["unknown method exception"] - DETACHED_SHADOW_ROOT = [65,"detached shadow root"] + DETACHED_SHADOW_ROOT = [65, "detached shadow root"] METHOD_NOT_ALLOWED = [405, "unsupported operation"] diff --git a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py index 4158509843276..2b95f2aecb8f1 100644 --- a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py +++ b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py @@ -240,12 +240,14 @@ def test_raises_exception_for_unknown_method(handler, code): def test_raises_exception_for_method_not_allowed(handler, code): with pytest.raises(exceptions.WebDriverException): handler.check_response({"status": code, "value": "foo"}) - + + @pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT) def test_raises_exception_for_invalid_selector(handler, code): with pytest.raises(exceptions.DetachedShadowRootException): handler.check_response({"status": code, "value": "foo"}) + @pytest.mark.parametrize("key", ["stackTrace", "stacktrace"]) def test_relays_exception_stacktrace(handler, key): import json From 80af3ab8baa3eed2322e72d1a08d49f4d5d36480 Mon Sep 17 00:00:00 2001 From: Simon Benzer <69980130+shbenzer@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:27:29 -0500 Subject: [PATCH 4/5] renamed test --- py/test/unit/selenium/webdriver/remote/error_handler_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py index 2b95f2aecb8f1..9f3098550efc8 100644 --- a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py +++ b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py @@ -243,7 +243,7 @@ def test_raises_exception_for_method_not_allowed(handler, code): @pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT) -def test_raises_exception_for_invalid_selector(handler, code): +def test_raises_exception_for_detached_shadow_root(handler, code): with pytest.raises(exceptions.DetachedShadowRootException): handler.check_response({"status": code, "value": "foo"}) From 3856e867e7d2b18902f2d8a8c3caf2227328c671 Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Mon, 4 Nov 2024 08:56:58 -0500 Subject: [PATCH 5/5] ran docformatter linting --- py/selenium/common/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/common/exceptions.py b/py/selenium/common/exceptions.py index 702cdf7ecc0fc..d1d7efdd1f0bd 100644 --- a/py/selenium/common/exceptions.py +++ b/py/selenium/common/exceptions.py @@ -288,4 +288,4 @@ def __init__( class DetachedShadowRootException(WebDriverException): - """Raised when referenced shadow root is no longer attached to the DOM""" + """Raised when referenced shadow root is no longer attached to the DOM."""