-
- Notifications
You must be signed in to change notification settings - Fork 8.6k
[py] Add LocalWebDriver base class #16730
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
base: trunk
Are you sure you want to change the base?
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label | ||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
| ||||||||||||
| How difficult would it be not to inherit from RemoteWebDriver any more? Ruby, JS & .NET all moved away from that hierarchy. Not sure it is worth it here, but just curious. |
That was actually my original thought... I wanted a It's not a huge amount of work, but there is a decent amount of reshuffling/copying/renaming that has to be done. I'll get to it eventually :) |
User description
💥 What does this PR do?
This PR introduces a new class named
LocalWebDriverthat is a common base class that all localWebDriverclasses inherit from. This allows us to implement common code across all local WebDriver instances without repeating code in every class.🔧 Implementation Notes
You will get a
TypeErrorif you try to instantiateLocalWebDriverdirectly. I was going to implement it as an Abstract Base Class (usingabc.ABC), but it doesn't provide any abstract methods and also inherits fromRemoteWebDriver... so I felt it was better to just leave it as a concrete class, but make it impossible to instantiate.💡 Additional Considerations
This shouldn't affect the public API... it is just an internal class hierarchy change for easier maintenance and to remove duplicated code.
PR Type
Enhancement
Description
Introduces
LocalWebDriverbase class for all local WebDriver implementationsConsolidates common code (quit, download methods) into single base class
Removes duplicate code across Chrome, Firefox, IE, Safari, WebKitGTK, WPEWebKit drivers
Prevents direct instantiation of
LocalWebDrivervia__new__overrideDiagram Walkthrough
File Walkthrough
webdriver.py
Create LocalWebDriver base class with common functionalitypy/selenium/webdriver/common/webdriver.py
LocalWebDriverbase class inheriting fromRemoteWebDriver__new__to prevent direct instantiation ofLocalWebDriver_is_remote = Falsein__init__for all local driversquit()method with service cleanup logicdownload_file(),get_downloadable_files(),delete_downloadable_files()as NotImplementedError stubswebdriver.py
Refactor ChromiumDriver to use LocalWebDriver base classpy/selenium/webdriver/chromium/webdriver.py
ChromiumDriverto inherit fromLocalWebDriverinstead ofRemoteWebDriver_is_remote = Falseassignment (now inLocalWebDriver.__init__)quit()method (now inLocalWebDriver)download_file(),get_downloadable_files(),delete_downloadable_files()methods (now inLocalWebDriver)LocalWebDriverfromselenium.webdriver.common.webdriverwebdriver.py
Refactor Firefox WebDriver to use LocalWebDriver base classpy/selenium/webdriver/firefox/webdriver.py
WebDriverto inherit fromLocalWebDriverinstead ofRemoteWebDriver_is_remote = Falseassignment (now inLocalWebDriver.__init__)quit()method (now inLocalWebDriver)download_file(),get_downloadable_files(),delete_downloadable_files()methods (now inLocalWebDriver)LocalWebDriverfromselenium.webdriver.common.webdriverwebdriver.py
Refactor IE WebDriver to use LocalWebDriver base classpy/selenium/webdriver/ie/webdriver.py
WebDriverto inherit fromLocalWebDriverinstead ofRemoteWebDriver_is_remote = Falseassignment (now inLocalWebDriver.__init__)quit()method (now inLocalWebDriver)download_file(),get_downloadable_files(),delete_downloadable_files()methods (now inLocalWebDriver)LocalWebDriverfromselenium.webdriver.common.webdriverwebdriver.py
Refactor Safari WebDriver to use LocalWebDriver base classpy/selenium/webdriver/safari/webdriver.py
WebDriverto inherit fromLocalWebDriverinstead ofRemoteWebDriver_is_remote = Falseassignment (now inLocalWebDriver.__init__)download_file(),get_downloadable_files(),delete_downloadable_files()methods (now inLocalWebDriver)LocalWebDriverfromselenium.webdriver.common.webdriverquit()method withhttp_client.BadStatusLineexception handling
webdriver.py
Refactor WebKitGTK WebDriver to use LocalWebDriver base classpy/selenium/webdriver/webkitgtk/webdriver.py
WebDriverto inherit fromLocalWebDriverinstead ofRemoteWebDriver_is_remote = Falseassignment (now inLocalWebDriver.__init__)quit()method (now inLocalWebDriver)download_file(),get_downloadable_files(),delete_downloadable_files()methods (now inLocalWebDriver)http.clientimportLocalWebDriverfromselenium.webdriver.common.webdriverwebdriver.py
Refactor WPEWebKit WebDriver to use LocalWebDriver base classpy/selenium/webdriver/wpewebkit/webdriver.py
WebDriverto inherit fromLocalWebDriverinstead ofRemoteWebDriver_is_remote = Falseassignment (now inLocalWebDriver.__init__)quit()method (now inLocalWebDriver)download_file(),get_downloadable_files(),delete_downloadable_files()methods (now inLocalWebDriver)http.clientimportLocalWebDriverfromselenium.webdriver.common.webdriver