Replies: 1 comment
-
For an example of same implementation of Execute as I'm proposing above see: https://github.com/SeleniumHQ/selenium/blob/trunk/py/selenium/webdriver/remote/webdriver.py |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, here are some thoughts for improving the function and clarity of the Execute method code logic. The Execute method handles the processing of the immediate inputs and outputs to/from the Selenium WebDriver and as such, is a centrally important code.
The section of code from Execute that I would like to discuss here is the complex logic in Execute's processing of the return response from Selenium WebDriver, as seen below.
One of the very nice aspects of the response that is directly received from the Selenium WebDriver is that it always comes returned as a Dictionary object containing different types (collections, arrays, strings, etc) depending on the command sent, including error information. That information can be parsed by the caller routines given the caller's expectations (the context). Execute shouldn't have to worry at all about preparing or (partially) parsing information for the caller. With that in mind, I am proposing that Execute should pass the response dictionary in its raw form and then let the caller decide how to parse, as in this below:
Note that the only task this simplified version of Execute is being asked to do with the response is to serve as the central error trapping mechanism, if the caller decides not to handle errors (raise=true). The two helper functions can be reused by the caller if needed, to handle unraised errors. A few examples of callers handling the errors:
The additional coding effort needed to update the callers for this change is close to trivial. All that has to be done is search the WebDriver class for this pattern "=Execute(CMD_" and where found, append a ("value") on the end of the Execute() call as in:
In a case like below, where the caller is indifferent about the response, no changes have to be made:
That is all that has to be done to simplify Execute. I would be interested in hearing what you think about this suggestion, and I would be willing to share my WebDriver class if that would be helpful (as a newbie to GitHub, I don't yet know how best to do that).
Thanks again for such an excellent resource.
Beta Was this translation helpful? Give feedback.
All reactions