python webdriver manager
The main idea is to simplify management of binary drivers for different browsers.
For now support:
-
ChromeDriver
-
GeckoDriver
-
EdgeDriver
-
IEDriver
-
PhantomJS
Before: You should download binary chromedriver, unzip it somewhere in you PC and set path to this driver like this:
webdriver.Chrome('/home/user/drivers/chromedriver')
Itβs boring!!! Moreover every time the new version of driver released, you should go and repeat all steps again and again.
With webdriver manager, you just need to do two simple steps:
Install manager:
pip install webdriver_manager
Use with Chrome:
from webdriver_manager.chrome import ChromeDriverManager
webdriver.Chrome(ChromeDriverManager().install())
Use with FireFox:
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
If you face error related to github credentials, you need to place github token: (*)
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
(*) access_token required to work with Github API more info https://help.github.com/articles/creating-an-access-token-for-command-line-use/. You can set gh_token using config.ini file see Configuration section below.
Use with Edge:
driver = webdriver.Edge(EdgeDriverManager().install())
Use with IE
driver = webdriver.Ie(IEDriverManager().install())
Configuration
Create file ${USER_HOME}/.wdm/config.ini with such content:
[GeckoDriver]
driver_path =
gh_token =
version = latest
offline = False
-
gh_token - Github access token to solve issues with API rate limit
-
driver_path - path to driver that was already downloaded
-
version - by default driver lookup for the latest version of the driver, you can freeze it
-
offline - mode that will disable automatic driver lookup. In this case you need either specify exact driver version that is already in cache ${user_home}/.wdm or set path to the driver using driver_path variable.
Same variables can be set for [ChromeDriver] and [EdgeDriver]
Config example:
[ChromeDriver]
driver_path = /home/user/.wdm/chromedriver/2.27/chromedriver
gh_token = ada23fsdfdfsdfdf
version = 2.27
offline = True
It will automatically download latest release of chromedriver and set path. Moreover when the new version of the driver will be released, webdriver manager will download it and update path.
There is also possibility to set same variables via ENV VARIABLES.
Example:
GH_TOKEN = "asdasdasdasd"
VERSION = 2.56
This will make your test automation more elegant and robust!