splinter
splinter copied to clipboard
Implement plugin system
This solution uses Pluggy https://pluggy.readthedocs.io/en/latest/ to add a plugin system into Splinter.
This PR features hooks for:
- registering external drivers. This implements #164 and provides a solution for #25 and #730. Internet Explorer is an old browser at this point, but a custom driver could be dropped in without hacking splinter's internals.
- Performing actions after a page is navigated to
- Performing actions before closing the browser.
Plugins classes or modules can be registered via a call to splinter.plugins.register()
This PR is missing:
- Hooks implementation for non-webdriver drivers
- Documentation
But will be added if the overall approach works.
This is a bare bones example of what an external driver plugin could look like:
import splinter
from splinter.driver.webdriver import BaseWebDriver
class WebDriver(BaseWebDriver):
driver_name = "Ie"
def __init__(self, wait_time=2):
self.driver = Ie()
super(WebDriver, self).__init__(wait_time)
class InternetExplorerPlugin:
@splinter.hookimpl
def splinter_prepare_drivers(drivers):
drivers['internet_explorer'] = WebDriver
splinter.plugins.register(InternetExplorerPlugin())