webdriver_manager icon indicating copy to clipboard operation
webdriver_manager copied to clipboard

driver binary Cache are not used. redownlaoidng geckodriver every time

Open eyaler opened this issue 3 years ago • 8 comments

Input:

import logging

from webdriver_manager.firefox import GeckoDriverManager

logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.DEBUG)

logging.info(f'>>> {GeckoDriverManager().install()=}')
logging.info('-' * 10)
logging.info(f'>>> {GeckoDriverManager().install()=}')
logging.info('Completed!')

Output:

2022-07-31 02:39:45,447 - WDM - INFO - ====== WebDriver manager ======
2022-07-31 02:39:46,622 - WDM - INFO - Get LATEST geckodriver version for 103.0 firefox
2022-07-31 02:39:46,628 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): api.github.com:443
2022-07-31 02:39:47,189 - urllib3.connectionpool - DEBUG - https://api.github.com:443 "GET /repos/mozilla/geckodriver/releases/latest HTTP/1.1" 200 3017
[WDM] - Downloading: 16.2kB [00:00, 8.29MB/s]
2022-07-31 02:39:48,460 - WDM - INFO - Driver [C:\Users\eyaler\.wdm\drivers\geckodriver\win64\0.31\geckodriver.exe] found in cache
2022-07-31 02:39:48,461 - root - INFO - >>> GeckoDriverManager().install()='C:\\Users\\eyaler\\.wdm\\drivers\\geckodriver\\win64\\0.31\\geckodriver.exe'
>>> logging.info('-' * 10)
2022-07-31 02:39:48,466 - root - INFO - ----------
>>> logging.info(f'>>> {GeckoDriverManager().install()=}')
2022-07-31 02:39:48,467 - WDM - INFO - ====== WebDriver manager ======
2022-07-31 02:39:49,733 - WDM - INFO - Get LATEST geckodriver version for 103.0 firefox
2022-07-31 02:39:49,735 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): api.github.com:443
2022-07-31 02:39:50,017 - urllib3.connectionpool - DEBUG - https://api.github.com:443 "GET /repos/mozilla/geckodriver/releases/latest HTTP/1.1" 200 3017
[WDM] - Downloading: 16.2kB [00:00, 16.6MB/s]
2022-07-31 02:39:51,264 - WDM - INFO - Driver [C:\Users\eyaler\.wdm\drivers\geckodriver\win64\0.31\geckodriver.exe] found in cache
2022-07-31 02:39:51,264 - root - INFO - >>> GeckoDriverManager().install()='C:\\Users\\eyaler\\.wdm\\drivers\\geckodriver\\win64\\0.31\\geckodriver.exe'

System:

Windows 10 WDM 3.8.3

eyaler avatar Jul 31 '22 09:07 eyaler

There is no driver download

SergeyPirogov avatar Jul 31 '22 10:07 SergeyPirogov

can you kindly explain what you mean? it says "Downloading" twice and i see the progress bar. this was fixed for chromium but happens for me now for firefox with 3.8.3

eyaler avatar Jul 31 '22 11:07 eyaler

I am having the same problem and I found out that it has something to do with the timestamp in C:\Users\User\.wdm\driver.json. If the timestamp does not contain today's date, the webdriver-manager will re-download the chrome driver for me.

MarcosBaungartner avatar Aug 01 '22 11:08 MarcosBaungartner

@MarcosBaungartner yes, because cache is valid for 1 day

SergeyPirogov avatar Aug 01 '22 12:08 SergeyPirogov

can you kindly explain what you mean? it says "Downloading" twice and i see the progress bar. this was fixed for chromium but happens for me now for firefox with 3.8.3

From logs above I see

2022-07-31 02:39:51,264 - WDM - INFO - Driver [C:\Users\eyaler\.wdm\drivers\geckodriver\win64\0.31\geckodriver.exe] found in cache

It means that driver is stored in cache

SergeyPirogov avatar Aug 01 '22 12:08 SergeyPirogov

@SergeyPirogov If I open the json and edit the TimeStamp to the current day, the webdriver-manager doesn't redownload the driver and uses the one he already downloaded. Is there a way to configure the manager so it will ignore the TimeStamp?

MarcosBaungartner avatar Aug 01 '22 14:08 MarcosBaungartner

DriverManager constructor have a parameter cache_valid=1, you can set it like 30 or 365

SergeyPirogov avatar Aug 01 '22 14:08 SergeyPirogov

I believe the log messages you are seeing are related to the driver manager making get requests to fetch the version string for the current driver.

It seems that when self._version hasn't been set in Driver, then this call is made: https://github.com/SergeyPirogov/webdriver_manager/blob/master/webdriver_manager/core/driver.py#L43-L45

Which, for GeckoDriver delegates down to this:

https://github.com/SergeyPirogov/webdriver_manager/blob/master/webdriver_manager/drivers/firefox.py#L27-L35

Then, if you look at how WDMHttpClient.get is implemented, it always calls show_download_progress which shows the progress bar no matter what type of get request is happening.

https://github.com/SergeyPirogov/webdriver_manager/blob/master/webdriver_manager/core/http.py#L27-L35

So I believe the original poster is seeing a download progress bar related to simply checking the version, rather than installing the whole driver.

With all of that said, there are 2 issues:

  1. The logging messages here are definitely a little confusing. My first impression was similar to OP; I thought that WDM was not properly using the cache
  2. Shouldn't it be possible to determine Driver._version from the cached driver, rather than reaching out to the internet? This makes running tests offline nearly impossible in my case, because GeckoDriverManager always needs to check for that version string.

johnlawsharrison avatar Sep 14 '22 19:09 johnlawsharrison

Hello,

When I'm trying to execute below code at the first time its download and save chromedriver as expected. But when I'm execute it for a second time it still download driver. Could you please help?

Input: from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=Service(ChromeDriverManager(path=r".\utils\Drivers").install()), options=options, desired_capabilities=desired_capabilities)

Output_1 ====== WebDriver manager ====== Current google-chrome version is 108.0.5359 Get LATEST chromedriver version for 108.0.5359 google-chrome Trying to download new driver from https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_win32.zip Driver has been saved in cache [.\utils\Drivers\drivers\chromedriver\win32\108.0.5359.71]

Output_2 ====== WebDriver manager ====== Current google-chrome version is 108.0.5359 Get LATEST chromedriver version for 108.0.5359 google-chrome Trying to download new driver from https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_win32.zip Driver has been saved in cache [.\utils\Drivers\drivers\chromedriver\win32\108.0.5359.71]

eneskooo avatar Mar 16 '23 18:03 eneskooo

@eneskooo hi!

Try current master - it's fixed. Soon I will make a release.

aleksandr-kotlyar avatar Mar 16 '23 21:03 aleksandr-kotlyar