Skip to content

[πŸš€ Feature]: [py] Reduce pytest output of Selenium-internals on exceptionΒ #15664

@ShaheedHaque

Description

@ShaheedHaque

Description

I would like pytest to show less Selenium internal code and variables in it's output when there is an exception. For example, let's say one has a test like this:

class TestFlow(SeleniumTest):
    def test_10_ae_pay_run________(self):
        self.driver.find_element(By.ID, "no such element")  <<<< exception raised here

Then the output from pytest -slvv has something like these stack frames:

  1. The user code (as above)
  2. selenium/webdriver/remote/webdriver.py in find_element()
  3. selenium/webdriver/remote/webdriver.py in execute()
  4. selenium/webdriver/remote/errorhandler.py in check_response()

Of these, the first and last are shown in verbose form including (IIUC) all the source code of the function, the variables and their values and so on. (The middle ones are shown in a compact form, with only one line of source code). The net result is that there are about 140 lines of output for check_response(), including a stack trace.

I propose to make check_response() into a minimal wrapper around a _check_response_real() and so remove most of this. The core of a possible patch looks something like this:

 class ErrorHandler:
     """Handles errors returned by the WebDriver server."""
 
     def check_response(self, response: Dict[str, Any]) -> None:
+        exception_class, args = self._check_response_real(response)
+        if exception_class:
+            raise exception_class(*args)
+
+    def _check_response_real(self, response: Dict[str, Any]) -> Tuple[Optional[Type[Exception]], Optional[Tuple[Any]]]:
         """Checks that a JSON response from the WebDriver does not have an
         error.
 
         :Args:
          - response - The JSON response from the WebDriver server as a dictionary

The 140 lines of Selenium internal is reduced to about 40 lines if there a stack trace, or just 20 lines if not. IMHO, this makes reading the output and thence debugging much nicer. I will propose a patch in due course.

Have you considered any alternatives or workarounds?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-pyPython BindingsI-enhancementSomething could be betterJ-awaiting answerQuestion asked of user; a reply moves it to triage again

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions