New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[py] optimised BaseOptions
in common/options.py
#12213
[py] optimised BaseOptions
in common/options.py
#12213
Conversation
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## trunk #12213 +/- ##
==========================================
- Coverage 58.09% 57.28% -0.82%
==========================================
Files 86 86
Lines 5348 5349 +1
Branches 207 205 -2
==========================================
- Hits 3107 3064 -43
- Misses 2034 2080 +46
+ Partials 207 205 -2
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still trying to understand the improvement. If we want to keep docstring info for the IDEs, does this new approach still reduce code?
def timeouts(self, timeouts: dict) -> None: | ||
"""How long the driver should wait for actions to complete before | ||
returning an error https://w3c.github.io/webdriver/#timeouts. | ||
class _Timeouts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we treat PageLoadStrategy, Timeouts, Proxy and UnhandledPromptBehavior differently?
Shouldn't we be documenting all w3c capabilities this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we treat PageLoadStrategy, Timeouts, Proxy and UnhandledPromptBehavior differently?
Shouldn't we be documenting all w3c capabilities this way?
We can stuff PageLoadStrategy
, UnHandledPromptBehavior
, Timeouts
and Poxy
in one single descriptor. But we need to have multiple conditional statements inside __set__
method since the behaviour of __set__
method is slightly different for each of the above 4 descriptors. So from code readability perspective I have just separated them out into different classes. If you observe _BaseOptions
class, the behaviour of __set__
method is common across attributes browser_version
, platform_name
, accept_insecure_certs
, strict_file_interactability
, set_window_rect
. So for all the above attributes we can re-use the same __get__
and __set__
method in _BaseOptions
class. We don't have to write multiple getters
and setters
. Since the behaviour is same across all 5 attributes we can re-use __get__
and __set__
in _BaseOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that means we are only getting the extra docstring details on the items that have non-default getter and/or setter behavior? Is there a way to use these descriptors instead of properties, have docstring details that can be consumed by the constructor, and have it result in less code and/or be more straightforward than what we have now with properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that means we are only getting the extra docstring details on the items that have non-default getter and/or setter behavior? Is there a way to use these descriptors instead of properties, have docstring details that can be consumed by the constructor, and have it result in less code and/or be more straightforward than what we have now with properties?
464557f
to
892fae0
Compare
Ok, looking at this side by side with existing... One of the goals of this PR was to make the classes shorter. Once we add the requirement back in for keeping the comments displayed in the user's IDE, though, it results in a larger class. I know @isaulv generally prefers the descriptors, but I don't think they are normally combined with code comments (Ruby's @KazuCocoa what is your opinion? Is there a common approach that Selenium/Appium can/should take here? |
@titusfortner @KazuCocoa , I have gone though
We can make the rest of the option classes to inherit from the main
|
Oh, great. It should help to reduce the boiler place in Python client code. Let me cc @mykola-mokhnach as well |
Please remove other PR commits from this PR and I will review |
@AutomatedTester I have removed all previous commits of this PR and kept only the relevant change specific to this PR. |
4cb2556
to
4ddaf51
Compare
2f92bc2
to
61570d5
Compare
@AutomatedTester , I have also added type validations for all browser options in |
As per discussion with @titusfortner I have removed the type checks that I had added in previous commit (1a22b11) from all base browser options. Also, the browser version is now being passed as an |
@AutomatedTester , I have removed previous commit. All tests are passing in my local. Request you to review this PR. Thank You. |
now assigning browser version as string in selenium_manager_tests |
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Optimised
BaseOptions
object by creating_BaseOptions
,_PageLoadStrategy
,_UnHandledPromptBehavior
and_Timeouts
descriptors by eliminating multipleproperties
Motivation and Context
In
BaseOptions
class, different browser attributes are being set through multipleproperties
likebrowser_version
platform_name
page_load_strategy
unhandled_prompt_behavior
timeouts
accept_insecure_certs
strict_file_interactability
set_window_rect
proxy
Now that I have replaced multiple
properties
with below descriptor objects_BaseOptions
_PageLoadStrategy
_UnHandledPromptBehavior
_Timeouts
By doing so, the descriptors has eliminated 18
getter
andsetter
methods.Types of changes
Checklist