Package: smart-webdriver-manager
Smart Webdriver ManagerA smart webdriver manager. Inspired bywebdriver_managerandchromedriver-binary-auto.Unlike other managers, this module provides a version-synchronized context for the driver, the browser, and the data directory.These are then cached for future use in the user-specified directory (or default).Currently Linux and Windows are fully tested. (See TODO)Examplespipinstallsmart-webdriver-managerimportosfromseleniumimportwebdriverfromselenium.webdriverimportChromeOptionsfromselenium.webdriver.chrome.serviceimportServicefromsmart_webdriver_managerimportChromeDriverManagerversion=os.getenv('MY_ENVIRONMENTAL_VARIABLE')cdm=ChromeDriverManager(version=version)driver_path=cdm.get_driver()browser_path=cdm.get_browser()user_data_path=cdm.get_browser_user_data()options=ChromeOptions()options.binary_location=browser_pathoptions.add_argument(f'--user-data-dir={user_data_path}')service=Service(executable_path=driver_path)driver=webdriver.Chrome(service=service,options=options)try:driver.get("http://google.com")finally:driver.quit()While it is more verbose than other managers, we can run parallel tests across supported versions.forversionin[0,75,80,95,96]:# 0 -> latest# ... same code as above, replacing versionThe compoenents themselves are modular. You can use the the driver or the browser independently.
However, both the driver and browser are installed together. If you only need a driver then other modules may be better suited.Whats really nice is the work required to update tests is now minimal. Just decrement back if the tests don't work.
No need to install/uninstall browsers when verifying versions.DevelopmentThere are two ways to run local testspipinstall-Upippoetrytoxgitclonehttps://github.com/bissli/smart-webdriver-manager.gitcdsmart-webdriver-managertoxpipinstall-Upippoetrygitclonehttps://github.com/bissli/smart-webdriver-manager.gitcdsmart-webdriver-managerpoetryinstallpoetryshellpipinstallpytestmockseleniumassertspytestTechnical LayoutSome module definitions:Version: main browser version, ie Chrome 95Release: subversion: ie Chrome 95.01.1121Revision: browser-only, snapshots within a releaseTo clarify how the module works, below is the cache directory illustrated:For browsers with revisions, we return the latest revision to the browser.For driver with releases, we return the latest releases to the driver corresponding to the browser.A user data directory is aligned with the release (see TODO)For example if the user requests chromedriver v96, revision 92512 will be returned for the browser and 96.1.85.111 for the driver."""Cache structureswm/browsers/chromium/ [linux]96.1.85.54/929511/chrome-linux/chrome...929511-chrome-linux.zip929512/chrome-linux/chrome...929512-chrome-linux.zipuser-data/...firefox/...drivers/chromedriver/ [windows]96.1.85.54/driver.zipchromedriver.exe96.1.85.111/driver.zipchromedriver.exegeckodriver/ [linux]0.29.8/driver.zipgeckodriver0.29.9/driver.zipgeckodriverbrowsers.jsondrivers.json"""The default directory for the cache is as follows:Windows: ~/appdata/roaming/swmLinux:   ~/.local/share/swmMac:  ~/Library/Application Support/swmTODOComplete support for Mac. Parse .app directory and create workaround for Gatekeeper.Complete the cache clear/remove methods. Write methods to delete the data directory or parts of the cache.Add Firefox as another supported platform. Current support is limited to Chromium/Chromedriver.Ability to recover if part of the cache is missing (ie a browser not there but browsers.json says so) (check path exists)Change the user data directory to fall under the major version, not release (see illustration above).Decide whether symlinks have value, remove code if not. (REMOVED)Migrate off omahaproxy.appspot.com (discontinued). Seehttps://groups.google.com/a/chromium.org/g/chromium-dev/c/uH-nFrOLWtE?pli=1ContributingActive contributions are welcome (collaboration). Please open a PR for features or bug fixes.