Skip to content

Commit

Permalink
see version 6.0.0 changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
stasvinokur committed Sep 2, 2023
1 parent 9afab4a commit 181b2bd
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 155 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## [6.0.0] - 02/09/2023
This version was written and tested on Python 3.11.1

#### Complete overhaul of chromedriver
- Added updated method to download chromedriver
- Added support for Windows 64 bit chromedriver

#### Added
- Added support for Windows ARM, Linux ARM Geckodriver
- Added proper comparison of versions
- Added universal extraction of only drivers (before it was extracting all elements in archive)
- Added support of multiple drivers in console updater - you need to separate drivers with comma, like this: chromedriver,geckodriver
- Added support for one filename if multiple drivers are given

#### Improved
- Improved console line updater help function and added more additional information to become more understandable to user
- Improved WGET bar to be more understandable, now file size is measuring in MB's
- Overall code improvements

#### Removed
- Removed parameter "old_return"

## [5.1.8] - 22/01/2023
This version was written and tested on Python 3.11.1
This version fully supports Python 3.11!
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# selenium_driver_updater

[![PyPI version](https://badge.fury.io/py/selenium-driver-updater.svg)](https://badge.fury.io/py/selenium-driver-updater)
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/Svinokur/selenium_driver_updater/master/LICENSE)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://pepy.tech/badge/selenium-driver-updater)](https://pepy.tech/project/selenium-driver-updater)
[![Downloads](https://pepy.tech/badge/selenium-driver-updater/month)](https://pepy.tech/project/selenium-driver-updater)
[![Downloads](https://pepy.tech/badge/selenium-driver-updater/week)](https://pepy.tech/project/selenium-driver-updater)
Expand All @@ -12,8 +12,6 @@
[![macOS](https://github.com/Svinokur/selenium_driver_updater/actions/workflows/macOS-tests.yml/badge.svg)](https://github.com/Svinokur/selenium_driver_updater/actions/workflows/macOS-tests.yml)
[![Ubuntu](https://github.com/Svinokur/selenium_driver_updater/actions/workflows/ubuntu-tests.yml/badge.svg)](https://github.com/Svinokur/selenium_driver_updater/actions/workflows/ubuntu-tests.yml)

[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/Svinokur/selenium_driver_updater)

It is a fast and convenience package that can automatically download or update Selenium webdriver binaries and their browsers for different OS.

## Installation
Expand All @@ -33,7 +31,7 @@ import os

base_dir = os.path.dirname(os.path.abspath(__file__))

filename = DriverUpdater.install(path=base_dir, driver_name=DriverUpdater.chromedriver, upgrade=True, check_driver_is_up_to_date=True, old_return=False)
filename = DriverUpdater.install(path=base_dir, driver_name=DriverUpdater.chromedriver, upgrade=True, check_driver_is_up_to_date=True)

driver = webdriver.Chrome(filename)
driver.get('https://google.com')
Expand All @@ -49,7 +47,7 @@ import os
base_dir = os.path.dirname(os.path.abspath(__file__))
list_drivers = [DriverUpdater.chromedriver, DriverUpdater.geckodriver]

filenames = DriverUpdater.install(path=base_dir, driver_name=list_drivers, upgrade=True, check_driver_is_up_to_date=True, old_return=False)
filenames = DriverUpdater.install(path=base_dir, driver_name=list_drivers, upgrade=True, check_driver_is_up_to_date=True)
print(filenames)

driver_chrome = webdriver.Chrome(filename[0])
Expand All @@ -67,6 +65,16 @@ selenium-driver-updater --help
```
To see all available arguments and commands

This example shows how you can use this console updater to download chromedriver to current dir
```bash
selenium-driver-updater -d chromedriver
```

Or you can use console updater to download chromedriver and geckodriver at the same time
```bash
selenium-driver-updater -d chromedriver,geckodriver
```

# Supported Selenium Binaries

### ``Chromedriver``
Expand All @@ -89,7 +97,9 @@ For installing or updating [geckodriver binary](https://github.com/mozilla/gecko
All supported OS's for this driver are:

- Windows
- Windows ARM
- Linux
- Linux ARM
- MacOS
- MacOS with M1

Expand Down
72 changes: 45 additions & 27 deletions selenium_driver_updater/_chromeDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import time
from pathlib import Path
from typing import Tuple

# Third party imports
import wget
from packaging import version

# Local imports
from selenium_driver_updater.browsers._chromeBrowser import ChromeBrowser

from selenium_driver_updater.util.logger import logger
from selenium_driver_updater.driver_base import DriverBase

from selenium_driver_updater.util.exceptions import DriverVersionInvalidException

class ChromeDriver(DriverBase):
"""Class for working with Selenium chromedriver binary"""

Expand All @@ -26,7 +26,9 @@ def __init__(self, **kwargs):

#assign of specific os
specific_system = str(kwargs.get('system_name', ''))
specific_system = specific_system.replace('win64', 'win32')
specific_system = specific_system.replace('linux32', 'linux64')
specific_system = specific_system.replace('mac64_m1', 'mac-arm64')
specific_system = specific_system.replace('mac64', 'mac-x64')
if specific_system:
self.system_name = f"chromedriver_{specific_system}.zip"

Expand Down Expand Up @@ -69,28 +71,54 @@ def main(self) -> str:
driver_path = self._download_driver(previous_version=True)

else:

try:
if version.parse(self.version) < version.parse('115'):
message = 'Versions below 115 are not supported - aborting operation'
logger.error(message)
raise DriverVersionInvalidException(message)
except:
raise DriverVersionInvalidException('Invalid version was provided, please check it')

driver_path = self._download_driver(version=self.version)

return driver_path

def _get_latest_version_driver(self, no_messages : bool = False) -> str:
"""Gets latest driver version
Returns:
str
latest_version (str) : Latest version of specific driver.
"""

latest_version : str = ''

url = self.setting[self.driver_name_setting]["LinkLastRelease"]
json_data = self.requests_getter.get_result_by_request(url=url, is_json=True)

latest_version = json_data.get('channels').get('Stable').get('version')

if not no_messages:

logger.info(f'Latest version of {self.driver_name}: {latest_version}')

return latest_version

def _compare_latest_version_main_chromedriver_and_latest_version_main_chrome_browser(self) -> Tuple[bool, str, str]:
"""Compares latest main version of chromedriver and latest main version of chrome browser"""
is_equal : bool = False
latest_version_chromedriver_main : str = ''
latest_version_browser_main : str = ''

latest_version_chromedriver = super()._get_latest_version_driver(no_messages=True)
latest_version_chromedriver = self._get_latest_version_driver(no_messages=True)

latest_version_browser = self.chromebrowser._get_latest_version_chrome_browser(no_messages=True)

latest_version_chromedriver_main = latest_version_chromedriver.split('.', maxsplit=1)[0]
latest_version_browser_main = latest_version_browser.split('.', maxsplit=1)[0]

if int(latest_version_chromedriver_main) <= int(latest_version_browser_main):
if version.parse(latest_version_chromedriver).major <= version.parse(latest_version_browser).major:
is_equal = True

return is_equal, latest_version_chromedriver_main, latest_version_browser_main
return is_equal, latest_version_chromedriver, latest_version_browser

def _check_if_chromedriver_is_up_to_date(self) -> str:
"""Сhecks for the latest version, downloads or updates chromedriver binary
Expand Down Expand Up @@ -141,11 +169,8 @@ def _get_latest_previous_version_chromedriver_via_requests(self) -> str:

latest_version_previous : str = ''

url = self.setting["ChromeDriver"]["LinkLastRelease"]
json_data = self.requests_getter.get_result_by_request(url=url)

latest_version = str(json_data)
latest_version_main = latest_version.split(".", maxsplit=1)[0]
latest_version = self._get_latest_version_driver()
latest_version_main = version.parse(latest_version).major

latest_version_main_previous = int(latest_version_main) - 1

Expand Down Expand Up @@ -195,7 +220,7 @@ def _download_driver(self, version : str = '', previous_version : bool = False)

else:

latest_version = super()._get_latest_version_driver()
latest_version = self._get_latest_version_driver()

url = self.setting["ChromeDriver"]["LinkLastReleaseFile"].format(latest_version)
logger.info(f'Started download chromedriver latest_version: {latest_version}')
Expand Down Expand Up @@ -224,10 +249,10 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
Path(out_path).unlink()

logger.info(f'Started download chromedriver by url: {url}')
archive_path = self._wget_download_driver(url, out_path)
archive_path = super()._wget_download_driver(url, out_path)
time.sleep(2)

logger.info(f'Chromedriver was downloaded to path: {archive_path}')
logger.info(f'\r\nChromedriver was downloaded to path: {archive_path}')

out_path : str = self.path

Expand Down Expand Up @@ -256,10 +281,3 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
super()._chmod_driver()

return driver_path

def _wget_download_driver(self, url, path):
if self.info_messages:
archive_path = wget.download(url=url, out=path)
else:
archive_path = wget.download(url=url, out=path, bar=None)
return archive_path
16 changes: 3 additions & 13 deletions selenium_driver_updater/_edgeDriver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pylint: disable=logging-fstring-interpolation
#Standart library imports
import shutil
import time
from pathlib import Path
from packaging import version

# Third party imports
import wget

# Local imports

Expand Down Expand Up @@ -109,7 +107,7 @@ def _get_latest_previous_version_edgedriver_via_requests(self) -> str:

latest_version = super()._get_latest_version_driver()

latest_version_main = int(latest_version.split('.', maxsplit=1)[0])
latest_version_main = version.parse(latest_version).major
latest_previous_version_main = str(latest_version_main-1)

if 'arm64' in self.setting["EdgeDriver"]["LinkLastReleaseFile"] or 'win' in self.setting["EdgeDriver"]["LinkLastReleaseFile"]:
Expand Down Expand Up @@ -141,7 +139,6 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
"""

url : str = ''
driver_notes_path : str = self.path + 'Driver_Notes'
latest_previous_version : str = ''
latest_version : str = ''

Expand Down Expand Up @@ -194,11 +191,7 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
Path(out_path).unlink()

logger.info(f'Started download edgedriver by url: {url}')

if self.info_messages:
archive_path = wget.download(url=url, out=out_path)
else:
archive_path = wget.download(url=url, out=out_path, bar=None)
archive_path = super()._wget_download_driver(url, out_path)
time.sleep(2)

logger.info(f'Edgedriver was downloaded to path: {archive_path}')
Expand All @@ -222,9 +215,6 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
if Path(archive_path).exists():
Path(archive_path).unlink()

if Path(driver_notes_path).exists():
shutil.rmtree(driver_notes_path)

driver_path = self.edgedriver_path

logger.info(f'Edgedriver was successfully unpacked by path: {driver_path}')
Expand Down
9 changes: 1 addition & 8 deletions selenium_driver_updater/_geckoDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import re
from pathlib import Path

# Third party imports
import wget

# Local imports

from selenium_driver_updater.util.logger import logger
Expand Down Expand Up @@ -209,11 +206,7 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
Path(out_path).unlink()

logger.info(f'Started download geckodriver by url: {url}')

if self.info_messages:
archive_path = wget.download(url=url, out=out_path)
else:
archive_path = wget.download(url=url, out=out_path, bar=None)
archive_path = super()._wget_download_driver(url, out_path)
time.sleep(2)

logger.info(f'Geckodriver was downloaded to path: {archive_path}')
Expand Down
34 changes: 12 additions & 22 deletions selenium_driver_updater/_operaDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from pathlib import Path
import re

# Third party imports
import wget

# Local imports
from selenium_driver_updater.util.logger import logger

Expand Down Expand Up @@ -233,38 +230,31 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
Path(out_path).unlink()

logger.info(f'Started download operadriver by url: {url}')

if self.info_messages:
archive_path = wget.download(url=url, out=out_path)
else:
archive_path = wget.download(url=url, out=out_path, bar=None)

logger.info(f'Operadriver was downloaded to path: {archive_path}')

archive_path = super()._wget_download_driver(url, out_path)
time.sleep(2)

logger.info(f'Operadriver was downloaded to path: {archive_path}')

out_path = self.path
self.extractor.extract_and_detect_archive_format(archive_path=archive_path, out_path=out_path)

platform : str = self.setting['OperaDriver']['LastReleasePlatform']

archive_folder_path = self.path + Path(archive_path).stem + os.path.sep
archive_operadriver_path = archive_folder_path + platform
parameters = dict(archive_path=archive_path, out_path=out_path)

if not self.filename:

copyfile(archive_operadriver_path, self.path + platform)
self.extractor.extract_and_detect_archive_format(**parameters)

else:

self.__rename_driver(archive_folder_path=archive_folder_path,
archive_operadriver_path=archive_operadriver_path)
filename = str(self.setting['OperaDriver']['LastReleasePlatform'])
parameters.update(dict(filename=filename, filename_replace=self.filename))

self.extractor.extract_all_zip_archive_with_specific_name(**parameters)

if Path(archive_path).exists():
Path(archive_path).unlink()
shutil.rmtree(archive_path)

if Path(archive_folder_path).exists():
shutil.rmtree(archive_folder_path)
if Path(archive_path).exists():
shutil.rmtree(archive_path)

driver_path = self.operadriver_path

Expand Down
Loading

0 comments on commit 181b2bd

Please sign in to comment.